Michelle Bu 12 vuotta sitten
vanhempi
commit
f2fbd5c265
1 muutettua tiedostoa jossa 40 lisäystä ja 6 poistoa
  1. 40 6
      lib/connectionmanager.js

+ 40 - 6
lib/connectionmanager.js

@@ -54,16 +54,33 @@ ConnectionManager.prototype.initialize = function(id, socket) {
   // Listen for ICE candidates.
   this._setupIce();
 
-  // Listen for negotiation needed.
-  // Chrome only **
-  this._setupNegotiationHandler();
-
   // Listen for data channel.
   this._setupDataChannel();
 
+  // Listen for negotiation needed.
+  // Chrome only--Firefox instead has to manually makeOffer.
+  if (util.browserisms !== 'Firefox') {
+    this._setupNegotiationHandler();
+  } else if (this._options.originator) {
+    this._firefoxAdditional()
+  }
+
   this.initialize = function() { };
 };
 
+/** Firefoxism that requires a fake media stream. */
+ConnectionManager.prototype._firefoxAdditional = function() {
+  var self = this;
+  getUserMedia({ audio: true, fake: true }, function(s) {
+    self.pc.addStream(s);
+    if (self._options.originator) {
+      self._makeOffer();
+    } else {
+      self._makeAnswer();
+    }
+  }, function(err) { util.log('Could not getUserMedia'); });
+};
+
 /** Start a PC. */
 ConnectionManager.prototype._startPeerConnection = function() {
   util.log('Creating RTCPeerConnection');
@@ -210,13 +227,30 @@ ConnectionManager.prototype._attachConnectionListeners = function(connection) {
 
 /** Handle an SDP. */
 ConnectionManager.prototype.handleSDP = function(sdp, type) {
-  sdp = new RTCSessionDescription(sdp);
+  if (util.browserisms !== 'Firefox') {
+    // Doesn't need to happen for FF.
+    sdp = new RTCSessionDescription(sdp);
+  }
 
   var self = this;
   this.pc.setRemoteDescription(sdp, function() {
     util.log('Set remoteDescription: ' + type);
     if (type === 'OFFER') {
-      self._makeAnswer();
+      if (util.browserisms === 'Firefox') {
+        self._firefoxAdditional();
+      } else {
+        self._makeAnswer();
+      }
+    } else if (util.browserisms === 'Firefox') {
+      // Firefoxism.
+      self.pc.connectDataConnection(self.localPort, self.remotePort);
+      self._socket.send({
+        type: 'PORT',
+        payload: {
+          remote: self._localPort,
+          local: self._remotePort
+        }
+      });
     }
   }, function(err) {
     self.emit('error', err);