// Purple: I want to have a video chat with my friend!
var purpleConnection = new RTCPeerConnection(...);

          

// I'll create a data channel to relay chat messages with my friend.
var p2bChat = purpleConnection.createDataChannel('CHAT', ...);

          

// and another one for sending files.
var p2bFiles = purpleConnection.createDataChannel('FILES', ...);

          

// I'll create a video/audio stream so we can videochat.
navigator.getUserMedia({audio: true, video: true}, function(stream) {

  // And I'll add that stream to my connection.
  purpleConnection.addStream(stream);

  ...

});

          

// I want to talk to Blue, so I'll make Blue an offer to chat.
purpleConnection.createOffer(function(offer) {
          

  // I'll save it locally...
  purpleConnection.setLocalDescription(offer, function() {
          

    // ...and pass it on to Blue.
    magicallySend(offer, blueClient);

    // we'll talk about our magical sending apparatus in a bit.
          

  }, errorHandler);
          

});
          

// Blue: I've magically received an offer, and I want to chat.

var blueConnection = new RTCPeerConnection(...);

blueConnection.setRemoteDescription(purpleOffer, function() {
          

  // I'll share my own media, but I only want to share video.
  navigator.getUserMedia({video: true}, function(stream) {
    blueConnection.addStream(stream);
          

    blueConnection.createAnswer(function(answer) {
          

      blueConnection.setLocalDescription(answer, function() {
          

        magicallySend(answer, purpleClient);
          

      }, errorHandler);
          

    });

          

  });

          

}, errorHandler);
          
iswebrtcreadyyet.com (&yet)
iswebrtcreadyyet.com (&yet)

Issue #138

// A simple config for an RTCPeerConnection...
var pcDotDotDot2 = {'iceServers': [
  { url: 'stun:stun.l.google.com:19302' },
  { url: 'turn:homeo@turn.bistri.com:80', credential: 'homeo' }
]};

          

// What it looks like for some older versions of some browsers...
var pcDotDotDot1 = {'iceServers': [
  { url: 'stun:23.21.150.121:19302' }
]};

          

// For a UDP data channel on some browsers...
var dcDotDotDot1 = {
  maxRetransmits: 0,
  ordered: false
};

          

// For a UDP data channel on older versions of some browsers...
var dcDotDotDot2 = {
  reliable: false
};
          

But it doesn't have to be that scary.

(WebRTC can be easy, remember?)