Procházet zdrojové kódy

make answer in right place

ericz před 12 roky
rodič
revize
e0e2496e6e
1 změnil soubory, kde provedl 8 přidání a 10 odebrání
  1. 8 10
      lib/connection.js

+ 8 - 10
lib/connection.js

@@ -42,11 +42,9 @@ function DataConnection(id, peer, socket, cb, options) {
   var self = this;
   if (options.sdp) {
     this.handleSDP({ type: 'OFFER', sdp: options.sdp });
-    if (util.browserisms !== 'Firefox') { 
-      this._makeAnswer();
-    }
   }
   
+  // Makes offer if Firefox
   if (util.browserisms === 'Firefox') {
     this._firefoxAdditional();
   }
@@ -179,8 +177,6 @@ DataConnection.prototype._firefoxAdditional = function() {
     self._pc.addStream(s);
     if (self._originator) {
       self._makeOffer();
-    } else {
-      self._makeAnswer();
     }
   }, function(err) { util.log('Could not getUserMedia'); });
 }
@@ -231,14 +227,14 @@ DataConnection.prototype._makeAnswer = function() {
 
 
 DataConnection.prototype._cleanup = function() {
-  if (!!this._pc && this._pc.readyState != 'closed') {
-    this._pc.close();
-    this._pc = null;
-  }
   if (!!this._dc && this._dc.readyState != 'closed') {
     this._dc.close();
     this._dc = null;
   }
+  if (!!this._pc && this._pc.readyState != 'closed') {
+    this._pc.close();
+    this._pc = null;
+  }
   this.emit('close', this._peer);
 };
 
@@ -315,9 +311,11 @@ DataConnection.prototype.handleSDP = function(message) {
         remote: self.localPort,
         local: self.remotePort
       });
+    } else if (message.type === 'OFFER') {
+      self._makeAnswer();
     }
   }, function(err) {
-    this._cb('Failed to setRemoteDescription');
+    self._cb('Failed to setRemoteDescription');
     util.log('Failed to setRemoteDescription, ', err);
   });
 };