فهرست منبع

source updated a bit, still need streams. can start hacking on sink.

Michelle Bu 12 سال پیش
والد
کامیت
ae0f2f1f60
4فایلهای تغییر یافته به همراه9 افزوده شده و 27 حذف شده
  1. 1 8
      public/js/sink.js
  2. 6 17
      public/js/source.js
  3. 1 1
      public/sink.html
  4. 1 1
      public/sinkoriginator.html

+ 1 - 8
public/js/sink.js

@@ -1,5 +1,5 @@
 function SinkPeer(options) {
-  this._config = options.config || {"iceServers": [{"url": "stun:stun.l.google.com:19302"}]};
+  this._config = options.config || { 'iceServers': [{ 'url': 'stun:stun.l.google.com:19302' }]};
   this._source = options.source || null;
   this._video = options.video;
   this._data = options.data != undefined ? options.data : true;
@@ -85,7 +85,6 @@ SinkPeer.prototype.socketInit = function() {
           // Firefoxism
           if (browserisms == 'Firefox') {
             self._pc.connectDataConnection(self.localPort, self.remotePort);
-            //self._pc.connectDataConnection(5000, 5001);
             self._socket.emit('port', { sink: data.sink, remote: self.localPort, local: self.remotePort });
           }
           console.log('ORIGINATOR: PeerConnection success');
@@ -136,10 +135,6 @@ SinkPeer.prototype.makeAnswer = function(target) {
           { 'sink': self._id,
             'sdp': answer,
             'source': target });
-      // Firefoxism
-      //if (browserisms && browserisms == 'Firefox') {
-        //self._pc.connectDataConnection(5001, 5000);
-      //}
     }, function(err) {
       console.log('failed to setLocalDescription, ', err)
     });
@@ -166,10 +161,8 @@ SinkPeer.prototype.makeOffer = function(target) {
 
 
 SinkPeer.prototype.setupAudioVideo = function() {
-  console.log('setupAudioVideo');
   var self = this;
   this._pc.onaddstream = function(obj) {
-    console.log('onaddstream');
     this._stream = true;
     if (!!self._handlers['remotestream']) {
       self._handlers['remotestream'](obj.type, obj.stream);

+ 6 - 17
public/js/source.js

@@ -1,6 +1,7 @@
 function SourcePeer(options) {
+  // TODO: Update for streams.
   // TODO: Allow passing in own ID.
-  this._config = options.config || {};
+  this._config = options.config || { 'iceServers': [{ 'url': 'stun:stun.l.google.com:19302' }]};
   this._streams = options.streamType || 'd';
   this._name = options.name || 'StreamAPI';
   // PeerConnections open for this source. Client name => PC.
@@ -55,7 +56,8 @@ SourcePeer.prototype.socketInit = function() {
     });
 
     self._socket.on('answer', function(data) {
-      self._pcs[data.sink].setRemoteDescription(data.sdp, function() {
+      self._pcs[data.sink].setRemoteDescription(new RTCSessionDescription(data.sdp),
+          function() {
         // Firefoxism
         if (browserisms == 'Firefox') {
           self._pcs[data.sink].connectDataConnection(self.localPort, self.remotePort);
@@ -74,7 +76,7 @@ SourcePeer.prototype.socketInit = function() {
 // a stream.
 SourcePeer.prototype.maybeBrowserisms = function(pc, target) {
   var self = this;
-  if (browserisms == 'Firefox') {
+  if (browserisms == 'Firefox' && !this._video && !this._audio && !this._stream) {
     getUserMedia({ audio: true, fake: true }, function(s) {
       pc.addStream(s);
       self.makeOffer(target);
@@ -107,20 +109,7 @@ SourcePeer.prototype.handleStream = function(pc, target, cb) {
   pc.onaddstream = function(obj) {
     console.log('SOURCE: data stream get');
   };
-  /*if (this._streams === 'v') {
-  } else if (this._streams === 'a') {
-  } else if (this._streams === 'av') {
-  } else if (this._streams === 'd') {*/
-    this.setupDataChannel(pc, target, cb);
-  /*} else if (this._streams === 'dav') {
-    this.setupDataChannel(pc, target);
-  } else if (this._streams === 'da') {
-    this.setupDataChannel(pc, target);
-  } else if (this._streams === 'dv') {
-    this.setupDataChannel(pc, target);
-  } else {
-    //error
-  }*/
+  this.setupDataChannel(pc, target, cb);
 };
 
 

+ 1 - 1
public/sink.html

@@ -16,7 +16,7 @@
 $(document).ready(function() {
   $('#connect').click(function() {
     var source = $('#source').val();
-    sink = new SinkPeer({ source: source, audio: false });
+    sink = new SinkPeer({ source: source, audio: true, video: true });
     sink.on('data', function(data) {
       console.log(data);
       sink.send('I am so scared.');

+ 1 - 1
public/sinkoriginator.html

@@ -14,7 +14,7 @@
 <script type="text/javascript" src="/js/sink.js"></script>
 <script>
 $(document).ready(function() {
-  originator = new SinkPeer({ video: true });
+  originator = new SinkPeer({ video: false });
   originator.on('ready', function(id) {
     console.log(id);
   });