//require('es5-shim-sham');

var rtc = require('../../')();
var Peer = require('simple-peer');
var crel = require('crel');
var browser = require('detect-browser');
var onStreamLoaded = require('../../util/onStreamLoaded');

window.rtc = rtc;

function debug(peer){
  peer.on('signal', function(m){
    console.debug('[debug] signal', m);
  });
}
function makeVideo(stream) {
  var el = crel('video', {
    muted: true,
    autoplay: true,
    className: 'video-stream',
    style: 'height:100px; width:100px; display:inline-block; background-color:black;'
  });
  return rtc.attachStream(el, stream);
}

rtc.getUserMedia(function(err, stream){
  if (err) {
    return console.error(err);
  }
  onStreamLoaded(stream, function(err, res){
    console.log(err, res);
  });

  var initiator = new Peer({
    initiator: true,
    stream: stream,
    wrtc: rtc
  });

  var receiver = new Peer({
    stream: stream,
    wrtc: rtc
  });

  //debug(initiator);
  //debug(receiver);

  initiator.on('error', console.error.bind(console));
  receiver.on('error', console.error.bind(console));

  initiator.on('signal', receiver.signal.bind(receiver));
  receiver.on('signal', initiator.signal.bind(initiator));

  initiator.once('connect', function(){
    console.log('Connected!');
  });

  initiator.once('stream', function(stream){
    console.log('got stream');
    //crel(document.body, makeVideo(stream));
  });

  receiver.once('stream', function(stream){
    //crel(document.body, makeVideo(stream));
  });
});

@@ -585,18 +585,18 @@
 eam(
-el, 
 stream
+, el
 );%0A%7D
@@ -1348,26 +1348,24 @@
 ream');%0A    
-//
 crel(documen
@@ -1447,18 +1447,16 @@
 m)%7B%0A    
-//
 crel(doc

fix sample