var WEBRTC = require('../');

var config = {
  iceServers: [
    {
      url: 'stun:stun.l.google.com:19302',
    },
  ],
};

var constraints = {
  optional: [
    {
      DtlsSrtpKeyAgreement: false,
    },
  ],
  mandatory: {
    OfferToReceiveAudio: true,
    OfferToReceiveVideo: true,
  },
};

var alice = new WEBRTC.RTCPeerConnection(config, constraints);
var bob = new WEBRTC.RTCPeerConnection(config, constraints);

alice.onicecandidate = function (event) {
  var candidate = event.candidate || event;
  bob.addIceCandidate(candidate);
};

bob.onicecandidate = function (event) {
  var candidate = event.candidate || event;
  alice.addIceCandidate(candidate);
};

alice.onnegotiationneeded = function () {
  alice.createOffer(function (sdp) {
    alice.setLocalDescription(sdp, function () {
      bob.setRemoteDescription(sdp, function () {
        bob.createAnswer(function (sdp) {
          bob.setLocalDescription(sdp, function () {
            alice.setRemoteDescription(sdp, function () {

            });
          });
        });
      });
    });
  });
};

bob.onnegotiationneeded = function () {
  bob.createOffer(function (sdp) {
    bob.setLocalDescription(sdp, function () {
      alice.setRemoteDescription(sdp, function () {
        alice.createAnswer(function (sdp) {
          alice.setLocalDescription(sdp, function () {
            bob.setRemoteDescription(sdp, function () {

            });
          });
        });
      });
    });
  });
};

WEBRTC.getSources(function (inputs) {
  console.log(inputs);

  WEBRTC.getUserMedia({
    audio: true,
    video: true,
  }, function (stream) {
    alice.addStream(stream);
  });
});


@@ -23,16 +23,40 @@
 ../');%0A%0A
+WEBRTC.setDebug(true);%0A%0A
 var conf
@@ -163,16 +163,29 @@
 nts = %7B%0A
+  audio: %7B%0A  
   option
@@ -194,24 +194,26 @@
 : %5B%0A    
+  
 %7B%0A      
 DtlsSrtp
@@ -208,34 +208,703 @@
     
-DtlsSrtpKeyAgreement: fals
+  googEchoCancellation: true,%0A        googEchoCancellation2: true,%0A        googDAEchoCancellation: true,%0A        googAutoGainControl: true,%0A        googAutoGainControl2: true,%0A        googNoiseSuppression: true,%0A        googNoiseSuppression2: true,%0A        googHighpassFilter: true,%0A        googTypingNoiseDetection: true,%0A        googAudioMirroring: true,%0A      %7D,%0A    %5D,%0A  %7D,%0A  video: %7B%0A    optional: %5B%0A      %7B%0A        minAspectRatio: 1.333,%0A        maxAspectRatio: 1.778,%0A        maxWidth: 1920,%0A        minWidth: 320,%0A        maxHeight: 1080,%0A        minHeight: 180,%0A        maxFrameRate: 60,%0A        minFrameRate: 30,%0A      %7D,%0A    %5D,%0A  %7D,%0A  optional: %5B%0A    %7B%0A      DtlsSrtpKeyAgreement: tru
 e,%0A 
@@ -1696,32 +1696,85 @@
 , function () %7B%0A
+              console.log('Alice -%3E Bob Connected!');
 %0A            %7D);
@@ -2157,16 +2157,69 @@
 on () %7B%0A
+              console.log('Bob -%3E Alice Connected!');
 %0A       
@@ -2285,181 +2285,620 @@
 %7D;%0A%0A
-WEBRTC.getSources(function (inputs) %7B%0A  console.log(inputs);%0A%0A  WEBRTC.getUserMedia(%7B%0A    audio: true,%0A    video: true,%0A  %7D, function (stream) %7B%0A    alice.addStream(stream);
+alice.onaddstream = function(stream) %7B%0A  console.log('Alice: mediaStream added!');%0A%7D;%0A%0Abob.onaddstream = function(stream) %7B%0A  console.log('Bob: mediaStream added!');%0A%7D;%0A%0Aalice.onremovestream = function(stream) %7B%0A  console.log('Alice: mediaStream removed!');%0A%7D;%0A%0Abob.onremovestream = function(stream) %7B%0A  console.log('Bob: mediaStream removed!');%0A%7D;%0A%0AWEBRTC.getSources(function (inputs) %7B%0A  console.log(inputs);%0A%0A  WEBRTC.getUserMedia(constraints, function(stream) %7B%0A    if (stream) %7B%0A      alice.addStream(stream);%0A%0A      setTimeout(function () %7B%0A        alice.close();%0A        bob.close();%0A      %7D, 5000);%0A    %7D
 %0A  %7D
@@ -2904,9 +2904,8 @@
 %7D);%0A%7D);%0A
-%0A

Update stream test