2

I know about adapter.js, which tries to:

insulate apps from spec changes and prefix differences.

But adpater.js only covers the very basic WebRTC API's. I'll just use setRemoteDescription as an example.

In 2013 it was called like this:

pc.setRemoteDescription(offer);

According to https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection, the current API is?

  pc.setRemoteDescription(new RTCSessionDescription(offer), function() {
    pc.createAnswer(function(answer) {
      pc.setLocalDescription(new RTCSessionDescription(answer), function() {
        // send the answer to a server to be forwarded back to the caller (you)
      }, error);
    }, error);
  }, error);

And I'm currently reading an article from 2015 where it seems to be:

pc2.setRemoteDescription(pc1_offer).then(step3, failed);
  • Where can I find up to date and "official" documentation for WebRTC API's?
  • How do you keep up with these frequent changes?

Edit

http://www.w3.org/TR/webrtc/ is not far off, but I'm rather looking for something where Firefox's and Chrome's current implementation status of the API can be followed (is over will-be if that makes sense).

jib
  • 34,243
  • 11
  • 80
  • 138
wpp
  • 6,379
  • 3
  • 31
  • 60
  • Official documentation of WebRTC's API is available on the W3C website : [here](http://www.w3.org/TR/webrtc/). However, there are modifications all the time. – Antonin M. May 18 '15 at 12:59
  • Ah yes. I should rather ask for Browser-vendor's "current" API status. I've updated the question. – wpp May 18 '15 at 13:09
  • I don't think there is something like what you want. You want an official documentation, but it should include both chrome's and firefox's implementations, which are different from the official spec at some points. Those two conditions can't both be met. – Kevin May 19 '15 at 08:07
  • @Kevin yes. I think the spec's draft version and chrome issues / webrtc mailing list are the closest things to that. – wpp May 19 '15 at 12:34

1 Answers1

2

WebRTC is still in development, so right now there is no better resource than the specification, and the best place to keep up-to-date on changes to it is: http://w3c.github.io/webrtc-pc

When it comes to individual browsers, and what's implemented, it gets harder. Just look at: http://iswebrtcreadyyet.com

The main API difference you are observing in your question is the 2014 support for promises. All asynchronous methods now return a Promise instead of taking a pair of success and failure callbacks. Chrome does not implement this yet, but Firefox does.

The following is a complete WebRTC call that works in Firefox (note: uses arrow functions):

var pc1 = new mozRTCPeerConnection(), pc2 = new mozRTCPeerConnection();

pc1.onicecandidate = e => !e.candidate ||
    pc2.addIceCandidate(e.candidate).catch(failed);
pc2.onicecandidate = e => !e.candidate ||
    pc1.addIceCandidate(e.candidate).catch(failed);
pc2.onaddstream = e => v2.mozSrcObject = e.stream;

function start() {
  navigator.mediaDevices.getUserMedia({ video: true, audio: true })
  .then(stream => pc1.addStream(v1.mozSrcObject = stream))
  .then(() => pc1.createOffer())
  .then(offer => pc1.setLocalDescription(offer))
  .then(() => pc2.setRemoteDescription(pc1.localDescription))
  .then(() => pc2.createAnswer())
  .then(answer => pc2.setLocalDescription(answer))
  .then(() => pc1.setRemoteDescription(pc2.localDescription))
  .then(() => log("Connected!"))
  .catch(failed);
}

var log = msg => div.innerHTML += "<p>" + msg + "</p>";
var failed = e => log(e.name +": "+ e.message +" line "+ e.lineNumber);
<video id="v1" height="120" width="160" autoplay></video>
<video id="v2" height="120" width="160" autoplay></video><br>
<button onclick="start()">Start!</button><div id="div"></div>

That's 20 lines of code, quite a bit smaller than other versions you may have seen.

Don't despair if it looks cryptic, as promises and arrow functions are new concepts that take a bit of getting used to, especially when used in combination like this. I recommend reading up on them separately using the links above.

The old callback versions are still available for all the RTCPeerConnection methods, so the use of promises is optional. Chrome supports promises in the browser (just not for WebRTC), but not arrow functions yet, so it'll probably be a while before the above becomes common.

This difference aside, Chrome and Firefox are quite stable when it comes to high-level call setup, even re-negotiation. The areas of the specification that are still changing have to do with new lower-level control surfaces like RTCRtpSender, and a refocus from specifying streams to specifying tracks (with addTrack instead of addStream etc.).

Unfortunately, I know of no good browser-specific documentation links. As you point out the MDN link is outdated (though the MDN link for getUserMedia was recently updated, so there's hope this will change). I find that looking at working demos and examples is still the most helpful in figuring out what is supported by the different browsers.

A few differences I know of:

  • getUserMedia constaints - Chrome implements the spec circa 2013 here, whereas Firefox implements the spec (but limited to width/height/frameRate and facingMode).
  • getStats - Chrome's implementation, while more mature, is non-standard, whereas Firefox implements the spec (but limited to rtp/rtcp, ice candidates and a few other things).
  • RTCOfferOptions - Chrome chokes on these, so instead of e.g. { offerOptions: true } use the older { mandatory: OfferOptions: true } (notice the case-difference 'o' vs. 'O') as this works in both browsers.
  • addTrack/removeTrack Stick to addStream(stream) for now (though Firefox does not implement removeStream so use removeTrack there).

You still need adapter.js due to prefixes and other differences, but there is more adapter.js could and should do. Hopefully, newer versions of it will narrow this gap further by providing a polyfill for some of the above differences.

My knowledge of Firefox is better than Chrome, so my apologies if I missed something.

I hope some of this helps.

Community
  • 1
  • 1
jib
  • 34,243
  • 11
  • 80
  • 138
  • Thank you very much for that thorough answer. A mix of iswebrtcreadyet and the specs is really what I was thinking about. Unfortunately there does not seem to be such a resource. (I'll accept your answer in a couple of days, in case someone proves us wrong :)). – wpp May 19 '15 at 12:37