Jelajahi Sumber

unmerge firefox for now

Michelle Bu 12 tahun lalu
induk
melakukan
34e704e063
9 mengubah file dengan 49 tambahan dan 266 penghapusan
  1. 21 129
      dist/peer.js
  2. 0 0
      dist/peer.min.js
  3. 5 5
      docs/api.md
  4. 1 2
      examples/chat.html
  5. 1 1
      examples/helloworld.html
  6. 11 104
      lib/connectionmanager.js
  7. 2 5
      lib/dataconnection.js
  8. 7 19
      lib/peer.js
  9. 1 1
      lib/util.js

+ 21 - 129
dist/peer.js

@@ -721,7 +721,7 @@ EventEmitter.prototype.emit = function(type) {
 var util = {
   
   chromeCompatible: true,
-  firefoxCompatible: true,
+  firefoxCompatible: false,
   chromeVersion: 26,
   firefoxVersion: 22,
 
@@ -1287,12 +1287,6 @@ Peer.prototype._handleServerJSONMessage = function(message) {
   var peer = message.src;
   var manager = this.managers[peer];
   var payload = message.payload;
-
-  // Check that browsers match.
-  if (!!payload && !!payload.browserisms && payload.browserisms !== util.browserisms) {
-    this._warn('incompatible-peer', 'Peer ' + self.peer + ' is on an incompatible browser. Please clean up this peer.');
-  }
-
   switch (message.type) {
     case 'OPEN':
       this._processQueue();
@@ -1347,11 +1341,10 @@ Peer.prototype._handleServerJSONMessage = function(message) {
       this._abort('invalid-key', 'API KEY "' + this._key + '" is invalid');
       break;
     case 'PORT':
-      // Firefoxism: exchanging ports.
-      if (util.browserisms === 'Firefox' && manager) {
-        manager.handlePort(payload);
-        break;
-      }
+      //if (util.browserisms === 'Firefox') {
+      //  connection.handlePort(payload);
+      //  break;
+      //}
     default:
       util.log('Unrecognized message type:', message.type);
       break;
@@ -1392,12 +1385,6 @@ Peer.prototype._abort = function(type, message) {
   this.destroy();
   this.emit('error', err);
 };
-/** Emits an error message that things may not work. */
-Peer.prototype._warn = function(type, message) {
-  var err = new Error(message);
-  err.type = type;
-  this.emit('error', err);
-};
 
 Peer.prototype._cleanup = function() {
   var self = this;
@@ -1419,14 +1406,15 @@ Peer.prototype._cleanup = function() {
  * is waiting for an ID. */
 Peer.prototype.connect = function(peer, options) {
   if (this.disconnected) {
-    this._warn('server-disconnected', 'This Peer has been disconnected from the server and can no longer make connections.');
+    var err = new Error('This Peer has been disconnected from the server and can no longer make connections.');
+    err.type = 'server-disconnected';
+    this.emit('error', err);
     return;
   }
 
   options = util.extend({
     config: this._options.config
   }, options);
-  options.originator = true;
 
   var manager = this.managers[peer];
   if (!manager) {
@@ -1491,12 +1479,10 @@ function DataConnection(peer, dc, options) {
   this.open = false;
 
   this.label = options.label;
-  // Firefox is not this finely configurable.
   this.metadata = options.metadata;
-  this.serialization = util.browserisms !== 'Firefox' ? options.serialization : 'binary';
-  this._isReliable = util.browserisms !== 'Firefox' ? options.reliable : false;
-
+  this.serialization = options.serialization;
   this.peer = peer;
+  this._isReliable = options.reliable;
 
   this._dc = dc;
   if (!!this._dc) {
@@ -1507,7 +1493,6 @@ function DataConnection(peer, dc, options) {
 util.inherits(DataConnection, EventEmitter);
 
 DataConnection.prototype._configureDataChannel = function() {
-  util.log('Configuring DataChannel with peer ' + this.peer);
   var self = this;
   if (util.browserisms !== 'Webkit') {
     this._dc.binaryType = 'arraybuffer';
@@ -1666,80 +1651,25 @@ ConnectionManager.prototype.initialize = function(id, socket) {
     this._socket = socket;
   }
 
-  // Firefoxism where ports need to be generated.
-  if (util.browserisms === 'Firefox') {
-    this._firefoxPortSetup();
-  }
-
   // Set up PeerConnection.
   this._startPeerConnection();
 
   // Process queued DCs.
-  if (util.browserisms !== 'Firefox') {
-    this._processQueue();
-  }
+  this._processQueue();
 
   // 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._firefoxHandlerSetup()
-    this._firefoxAdditional()
-  }
-
   this.initialize = function() { };
 };
 
-/** Firefoxism that requires a fake media stream. */
-ConnectionManager.prototype._firefoxAdditional = function() {
-  util.log('Additional media stream for Firefox.');
-  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'); });
-};
-
-/** Firefoxism that requires ports to be set up. */
-ConnectionManager.prototype._firefoxPortSetup = function() {
-  if (!ConnectionManager.usedPorts) {
-    ConnectionManager.usedPorts = [];
-  }
-  this._localPort = util.randomPort();
-  while (ConnectionManager.usedPorts.indexOf(this._localPort) != -1) {
-    this._localPort = util.randomPort();
-  }
-  this._remotePort = util.randomPort();
-  while (this._remotePort === this._localPort ||
-      ConnectionManager.usedPorts.indexOf(this._remotePort) != -1) {
-    this._remotePort = util.randomPort();
-  }
-  ConnectionManager.usedPorts.push(this._remotePort);
-  ConnectionManager.usedPorts.push(this._localPort);
-};
-
-/** Firefoxism that is `onconnection`. */
-ConnectionManager.prototype._firefoxHandlerSetup = function() {
-  util.log('Setup Firefox `onconnection`.');
-  var self = this;
-  this.pc.onconnection = function() {
-    util.log('FIREFOX: onconnection triggered');
-
-    self._processQueue();
-  }
-};
-
 /** Start a PC. */
 ConnectionManager.prototype._startPeerConnection = function() {
   util.log('Creating RTCPeerConnection');
@@ -1788,17 +1718,11 @@ ConnectionManager.prototype._setupDataChannel = function() {
   util.log('Listening for data channel');
   this.pc.ondatachannel = function(evt) {
     util.log('Received data channel');
-    // Firefoxism: ondatachannel receives channel directly. NOT TO SPEC.
-    var dc = util.browserisms === 'Firefox' ? evt : evt.channel;
+    var dc = evt.channel;
     var label = dc.label;
-
     // This should not be empty.
-    // NOTE: Multiple DCs are currently not configurable in FF. Will have to
-    // come up with reasonable defaults.
-    var options = self.labels[label] || { label: label };
+    var options = self.labels[label] || {};
     var connection  = new DataConnection(self.peer, dc, options);
-    delete self.labels[label];
-
     self._attachConnectionListeners(connection);
     self.connections[label] = connection;
     self.emit('connection', connection);
@@ -1815,7 +1739,6 @@ ConnectionManager.prototype._makeOffer = function() {
       self._socket.send({
         type: 'OFFER',
         payload: {
-          browserisms: util.browserisms,
           sdp: offer,
           config: self._options.config,
           labels: self.labels
@@ -1841,7 +1764,6 @@ ConnectionManager.prototype._makeAnswer = function() {
       self._socket.send({
         type: 'ANSWER',
         payload: {
-          browserisms: util.browserisms,
           sdp: answer
         },
         dst: self.peer
@@ -1892,45 +1814,15 @@ ConnectionManager.prototype._attachConnectionListeners = function(connection) {
   });
 };
 
-/** Firefoxism: handle receiving a set of ports. */
-ConnectionManager.prototype.handlePort = function(ports) {
-  util.log('Received ports, calling connectDataConnection.');
-  if (!ConnectionManager.usedPorts) {
-    ConnectionManager.usedPorts = [];
-  }
-  ConnectionManager.usedPorts.push(ports.local);
-  ConnectionManager.usedPorts.push(ports.remote);
-  this.pc.connectDataConnection(ports.local, ports.remote);
-};
-
 /** Handle an SDP. */
 ConnectionManager.prototype.handleSDP = function(sdp, type) {
-  if (util.browserisms !== 'Firefox') {
-    // Doesn't need to happen for FF.
-    sdp = new RTCSessionDescription(sdp);
-  }
+  sdp = new RTCSessionDescription(sdp);
 
   var self = this;
   this.pc.setRemoteDescription(sdp, function() {
     util.log('Set remoteDescription: ' + type);
     if (type === 'OFFER') {
-      if (util.browserisms === 'Firefox') {
-        self._firefoxAdditional();
-      } else {
-        self._makeAnswer();
-      }
-    } else if (util.browserisms === 'Firefox') {
-      // Firefoxism.
-      util.log('Peer ANSWER received, connectDataConnection called.');
-      self.pc.connectDataConnection(self._localPort, self._remotePort);
-      self._socket.send({
-        type: 'PORT',
-        payload: {
-          remote: self._localPort,
-          local: self._remotePort
-        },
-        dst: self.peer
-      });
+      self._makeAnswer();
     }
   }, function(err) {
     self.emit('error', err);
@@ -1987,14 +1879,14 @@ ConnectionManager.prototype.connect = function(options) {
   this.labels[options.label] = options;
 
   var dc;
-  if (!!this.pc && !this._lock && (util.browserisms !== 'Firefox' || Object.keys(this.connections).length !== 0)) {
+  if (!!this.pc && !this._lock) {
     dc = this.pc.createDataChannel(options.label, { reliable: false });
   }
   var connection = new DataConnection(this.peer, dc, options);
   this._attachConnectionListeners(connection);
   this.connections[options.label] = connection;
 
-  if (!dc) {
+  if (!this.pc || this._lock) {
     this._queued.push(connection);
   }
 

File diff ditekan karena terlalu besar
+ 0 - 0
dist/peer.min.js


+ 5 - 5
docs/api.md

@@ -46,9 +46,9 @@ Returns a `DataConnection` object.
 * `id` String. The id of the remote peer to connect to.
 * `options` Object.
   * `label` Optional label for the underlying DataChannel, to differentiate between DataConnections between the same two peers. If left unspecified, a label will be assigned at random.
-  * `metadata` Optional metadata to pass to the remote peer. Can be any serializable type. **Only available in Firefox on the first DataConnection established between two Peers.**
-  * `serialization` String, which can be `binary`, `binary-utf8`, `json`, or `none`. This will be the serialization format of all data sent over the P2P DataConnection. Defaults to `binary`. **Will always be `binary` in Firefox.**
-  * `reliable` Boolean, which if `true` activates experimental reliable transfer (while waiting for actual reliable transfer to be implemented in Chrome). Defaults to `false` until Chrome implements reliable/large data transfer. This parameter is only available in the most recent build. **Will always be `true` in Firefox.**
+  * `metadata` Optional metadata to pass to the remote peer. Can be any serializable type.
+  * `serialization` String, which can be `binary`, `binary-utf8`, `json`, or `none`. This will be the serialization format of all data sent over the P2P DataConnection. Defaults to `binary`.
+  * `reliable` Boolean, which if `true` activates experimental reliable transfer (while waiting for actual reliable transfer to be implemented in Chrome). Defaults to `false` until Chrome implements reliable/large data transfer. This parameter is only available in the most recent build.
 
 Before writing to / data will be emitted from the `DataConnection` object that is returned, the `open` event must fire. Also the `error` event should be checked in case a connection cannot be made.
 
@@ -86,7 +86,8 @@ This event does not need to fire before creating or receiving connections.
 
 `function (error) { }`
 
-Emitted when an unexpected event occurs. All errors on the Peer except `server-disconnected` and `incompatible-peer` are **fatal**. Errors from the underlying socket and PeerConnections are forwarded here.
+Emitted when an unexpected event occurs. Errors on the Peer are **always
+fatal**. Errors from the underlying socket and PeerConnections are forwarded here.
 
 The `error` object also has a `type` parameter that may be helpful in responding to client errors properly:
 * `browser-incompatible`: The client's browser does not support some or all WebRTC features that you are trying to use.
@@ -99,7 +100,6 @@ The `error` object also has a `type` parameter that may be helpful in responding
   * `socket-closed`: The underlying socket closed unexpectedly.
 * (The Peer object is destroyed after one of the errors above are emitted.)
 * `server-disconnected`: A Peer that has been disconnected is being used to try to connect.
-* `incompatible-peer`: The peer that is trying to connect or that you are trying to connect to is using a browser that is different from yours. **Currently DataChannels are not interoperable between Chrome and Firefox.**
 
 ### Event: 'close'
 

+ 1 - 2
examples/chat.html

@@ -9,10 +9,9 @@
 
 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script> 
 <script type="text/javascript" src="http://cdn.peerjs.com/0/peer.js"></script>
-<script type="text/javascript" src="../dist/peer.js"></script>
 <script>
 // Connect to PeerJS, have server assign an ID instead of providing one
-peer = new Peer({key: 'lwjd5qra8257b9', debug: true});
+var peer = new Peer({key: 'lwjd5qra8257b9', debug: true});
 
 // Show this peer's ID.
 peer.on('open', function(id){

+ 1 - 1
examples/helloworld.html

@@ -7,12 +7,12 @@
 
 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script> 
 <script type="text/javascript" src="http://cdn.peerjs.com/0/peer.js"></script>
-<script src="../dist/peer.js"></script>
 <script>
   // This is a very simple code example. See chat.html for a more involved
   // example.
 
   $(document).ready(function() {
+    var peer1, peer2, peerId1;
 
     // Create a new Peer with our demo API key, with debug set to true so we can
     // see what's going on.

+ 11 - 104
lib/connectionmanager.js

@@ -45,80 +45,25 @@ ConnectionManager.prototype.initialize = function(id, socket) {
     this._socket = socket;
   }
 
-  // Firefoxism where ports need to be generated.
-  if (util.browserisms === 'Firefox') {
-    this._firefoxPortSetup();
-  }
-
   // Set up PeerConnection.
   this._startPeerConnection();
 
   // Process queued DCs.
-  if (util.browserisms !== 'Firefox') {
-    this._processQueue();
-  }
+  this._processQueue();
 
   // 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._firefoxHandlerSetup()
-    this._firefoxAdditional()
-  }
-
   this.initialize = function() { };
 };
 
-/** Firefoxism that requires a fake media stream. */
-ConnectionManager.prototype._firefoxAdditional = function() {
-  util.log('Additional media stream for Firefox.');
-  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'); });
-};
-
-/** Firefoxism that requires ports to be set up. */
-ConnectionManager.prototype._firefoxPortSetup = function() {
-  if (!ConnectionManager.usedPorts) {
-    ConnectionManager.usedPorts = [];
-  }
-  this._localPort = util.randomPort();
-  while (ConnectionManager.usedPorts.indexOf(this._localPort) != -1) {
-    this._localPort = util.randomPort();
-  }
-  this._remotePort = util.randomPort();
-  while (this._remotePort === this._localPort ||
-      ConnectionManager.usedPorts.indexOf(this._remotePort) != -1) {
-    this._remotePort = util.randomPort();
-  }
-  ConnectionManager.usedPorts.push(this._remotePort);
-  ConnectionManager.usedPorts.push(this._localPort);
-};
-
-/** Firefoxism that is `onconnection`. */
-ConnectionManager.prototype._firefoxHandlerSetup = function() {
-  util.log('Setup Firefox `onconnection`.');
-  var self = this;
-  this.pc.onconnection = function() {
-    util.log('FIREFOX: onconnection triggered');
-
-    self._processQueue();
-  }
-};
-
 /** Start a PC. */
 ConnectionManager.prototype._startPeerConnection = function() {
   util.log('Creating RTCPeerConnection');
@@ -167,17 +112,11 @@ ConnectionManager.prototype._setupDataChannel = function() {
   util.log('Listening for data channel');
   this.pc.ondatachannel = function(evt) {
     util.log('Received data channel');
-    // Firefoxism: ondatachannel receives channel directly. NOT TO SPEC.
-    var dc = util.browserisms === 'Firefox' ? evt : evt.channel;
+    var dc = evt.channel;
     var label = dc.label;
-
     // This should not be empty.
-    // NOTE: Multiple DCs are currently not configurable in FF. Will have to
-    // come up with reasonable defaults.
-    var options = self.labels[label] || { label: label };
+    var options = self.labels[label] || {};
     var connection  = new DataConnection(self.peer, dc, options);
-    delete self.labels[label];
-
     self._attachConnectionListeners(connection);
     self.connections[label] = connection;
     self.emit('connection', connection);
@@ -194,7 +133,6 @@ ConnectionManager.prototype._makeOffer = function() {
       self._socket.send({
         type: 'OFFER',
         payload: {
-          browserisms: util.browserisms,
           sdp: offer,
           config: self._options.config,
           labels: self.labels
@@ -220,7 +158,6 @@ ConnectionManager.prototype._makeAnswer = function() {
       self._socket.send({
         type: 'ANSWER',
         payload: {
-          browserisms: util.browserisms,
           sdp: answer
         },
         dst: self.peer
@@ -271,45 +208,15 @@ ConnectionManager.prototype._attachConnectionListeners = function(connection) {
   });
 };
 
-/** Firefoxism: handle receiving a set of ports. */
-ConnectionManager.prototype.handlePort = function(ports) {
-  util.log('Received ports, calling connectDataConnection.');
-  if (!ConnectionManager.usedPorts) {
-    ConnectionManager.usedPorts = [];
-  }
-  ConnectionManager.usedPorts.push(ports.local);
-  ConnectionManager.usedPorts.push(ports.remote);
-  this.pc.connectDataConnection(ports.local, ports.remote);
-};
-
 /** Handle an SDP. */
 ConnectionManager.prototype.handleSDP = function(sdp, type) {
-  if (util.browserisms !== 'Firefox') {
-    // Doesn't need to happen for FF.
-    sdp = new RTCSessionDescription(sdp);
-  }
+  sdp = new RTCSessionDescription(sdp);
 
   var self = this;
   this.pc.setRemoteDescription(sdp, function() {
     util.log('Set remoteDescription: ' + type);
     if (type === 'OFFER') {
-      if (util.browserisms === 'Firefox') {
-        self._firefoxAdditional();
-      } else {
-        self._makeAnswer();
-      }
-    } else if (util.browserisms === 'Firefox') {
-      // Firefoxism.
-      util.log('Peer ANSWER received, connectDataConnection called.');
-      self.pc.connectDataConnection(self._localPort, self._remotePort);
-      self._socket.send({
-        type: 'PORT',
-        payload: {
-          remote: self._localPort,
-          local: self._remotePort
-        },
-        dst: self.peer
-      });
+      self._makeAnswer();
     }
   }, function(err) {
     self.emit('error', err);
@@ -366,14 +273,14 @@ ConnectionManager.prototype.connect = function(options) {
   this.labels[options.label] = options;
 
   var dc;
-  if (!!this.pc && !this._lock && (util.browserisms !== 'Firefox' || Object.keys(this.connections).length !== 0)) {
+  if (!!this.pc && !this._lock) {
     dc = this.pc.createDataChannel(options.label, { reliable: false });
   }
   var connection = new DataConnection(this.peer, dc, options);
   this._attachConnectionListeners(connection);
   this.connections[options.label] = connection;
 
-  if (!dc) {
+  if (!this.pc || this._lock) {
     this._queued.push(connection);
   }
 

+ 2 - 5
lib/dataconnection.js

@@ -14,12 +14,10 @@ function DataConnection(peer, dc, options) {
   this.open = false;
 
   this.label = options.label;
-  // Firefox is not this finely configurable.
   this.metadata = options.metadata;
-  this.serialization = util.browserisms !== 'Firefox' ? options.serialization : 'binary';
-  this._isReliable = util.browserisms !== 'Firefox' ? options.reliable : false;
-
+  this.serialization = options.serialization;
   this.peer = peer;
+  this._isReliable = options.reliable;
 
   this._dc = dc;
   if (!!this._dc) {
@@ -30,7 +28,6 @@ function DataConnection(peer, dc, options) {
 util.inherits(DataConnection, EventEmitter);
 
 DataConnection.prototype._configureDataChannel = function() {
-  util.log('Configuring DataChannel with peer ' + this.peer);
   var self = this;
   if (util.browserisms !== 'Webkit') {
     this._dc.binaryType = 'arraybuffer';

+ 7 - 19
lib/peer.js

@@ -115,12 +115,6 @@ Peer.prototype._handleServerJSONMessage = function(message) {
   var peer = message.src;
   var manager = this.managers[peer];
   var payload = message.payload;
-
-  // Check that browsers match.
-  if (!!payload && !!payload.browserisms && payload.browserisms !== util.browserisms) {
-    this._warn('incompatible-peer', 'Peer ' + self.peer + ' is on an incompatible browser. Please clean up this peer.');
-  }
-
   switch (message.type) {
     case 'OPEN':
       this._processQueue();
@@ -175,11 +169,10 @@ Peer.prototype._handleServerJSONMessage = function(message) {
       this._abort('invalid-key', 'API KEY "' + this._key + '" is invalid');
       break;
     case 'PORT':
-      // Firefoxism: exchanging ports.
-      if (util.browserisms === 'Firefox' && manager) {
-        manager.handlePort(payload);
-        break;
-      }
+      //if (util.browserisms === 'Firefox') {
+      //  connection.handlePort(payload);
+      //  break;
+      //}
     default:
       util.log('Unrecognized message type:', message.type);
       break;
@@ -220,12 +213,6 @@ Peer.prototype._abort = function(type, message) {
   this.destroy();
   this.emit('error', err);
 };
-/** Emits an error message that things may not work. */
-Peer.prototype._warn = function(type, message) {
-  var err = new Error(message);
-  err.type = type;
-  this.emit('error', err);
-};
 
 Peer.prototype._cleanup = function() {
   var self = this;
@@ -247,14 +234,15 @@ Peer.prototype._cleanup = function() {
  * is waiting for an ID. */
 Peer.prototype.connect = function(peer, options) {
   if (this.disconnected) {
-    this._warn('server-disconnected', 'This Peer has been disconnected from the server and can no longer make connections.');
+    var err = new Error('This Peer has been disconnected from the server and can no longer make connections.');
+    err.type = 'server-disconnected';
+    this.emit('error', err);
     return;
   }
 
   options = util.extend({
     config: this._options.config
   }, options);
-  options.originator = true;
 
   var manager = this.managers[peer];
   if (!manager) {

+ 1 - 1
lib/util.js

@@ -1,7 +1,7 @@
 var util = {
   
   chromeCompatible: true,
-  firefoxCompatible: true,
+  firefoxCompatible: false,
   chromeVersion: 26,
   firefoxVersion: 22,
 

Beberapa file tidak ditampilkan karena terlalu banyak file yang berubah dalam diff ini