Michelle Bu 12 سال پیش
والد
کامیت
58b25bdfd3
4فایلهای تغییر یافته به همراه30 افزوده شده و 18 حذف شده
  1. 15 9
      dist/peer.js
  2. 0 0
      dist/peer.min.js
  3. 14 8
      lib/connectionmanager.js
  4. 1 1
      lib/peer.js

+ 15 - 9
dist/peer.js

@@ -1389,7 +1389,7 @@ Peer.prototype.connect = function(peer, options) {
     this.connections[peer] = {};
   }
 
-  var connectionInfo = manager.connect(options.label);
+  var connectionInfo = manager.connect(options);
   if (!!connectionInfo) {
     this.connections[peer][connectionInfo[0]] = connectionInfo[1];
   }
@@ -1624,8 +1624,8 @@ ConnectionManager.prototype._startPeerConnection = function() {
 
 /** Add DataChannels to all queued DataConnections. */
 ConnectionManager.prototype._processQueue = function() {
-  while (this._queued.length > 0) {
-    var conn = this._queued.pop();
+  var conn = this._queued.pop();
+  if (!!conn) {
     conn.addDC(this.pc.createDataChannel(conn.label, { reliable: false }));
   }
 };
@@ -1754,6 +1754,10 @@ ConnectionManager.prototype._attachConnectionListeners = function(connection) {
       self._cleanup();
     }
   });
+  connection.on('open', function() {
+    self._lock = false;
+    self._processQueue();
+  });
 };
 
 /** Handle an SDP. */
@@ -1803,14 +1807,14 @@ ConnectionManager.prototype.close = function() {
 };
 
 /** Create and returns a DataConnection with the peer with the given label. */
-ConnectionManager.prototype.connect = function(label) {
+ConnectionManager.prototype.connect = function(options) {
   if (!this.open) {
     return;
   }
 
-  var options = util.extend({
-    label: label || 'peerjs'
-  }, this._options);
+  options = util.extend({
+    label: 'peerjs'
+  }, options);
 
   // Check if label is taken...if so, generate a new label randomly.
   while (!!this.connections[options.label]) {
@@ -1821,16 +1825,18 @@ ConnectionManager.prototype.connect = function(label) {
   this.labels[options.label] = options;
 
   var dc;
-  if (!!this.pc) {
+  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 (!this.pc) {
+  if (!this.pc || this._lock) {
     this._queued.push(connection);
   }
+
+  this._lock = true
   return [options.label, connection];
 };
 

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 0 - 0
dist/peer.min.js


+ 14 - 8
lib/connectionmanager.js

@@ -72,8 +72,8 @@ ConnectionManager.prototype._startPeerConnection = function() {
 
 /** Add DataChannels to all queued DataConnections. */
 ConnectionManager.prototype._processQueue = function() {
-  while (this._queued.length > 0) {
-    var conn = this._queued.pop();
+  var conn = this._queued.pop();
+  if (!!conn) {
     conn.addDC(this.pc.createDataChannel(conn.label, { reliable: false }));
   }
 };
@@ -202,6 +202,10 @@ ConnectionManager.prototype._attachConnectionListeners = function(connection) {
       self._cleanup();
     }
   });
+  connection.on('open', function() {
+    self._lock = false;
+    self._processQueue();
+  });
 };
 
 /** Handle an SDP. */
@@ -251,14 +255,14 @@ ConnectionManager.prototype.close = function() {
 };
 
 /** Create and returns a DataConnection with the peer with the given label. */
-ConnectionManager.prototype.connect = function(label) {
+ConnectionManager.prototype.connect = function(options) {
   if (!this.open) {
     return;
   }
 
-  var options = util.extend({
-    label: label || 'peerjs'
-  }, this._options);
+  options = util.extend({
+    label: 'peerjs'
+  }, options);
 
   // Check if label is taken...if so, generate a new label randomly.
   while (!!this.connections[options.label]) {
@@ -269,16 +273,18 @@ ConnectionManager.prototype.connect = function(label) {
   this.labels[options.label] = options;
 
   var dc;
-  if (!!this.pc) {
+  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 (!this.pc) {
+  if (!this.pc || this._lock) {
     this._queued.push(connection);
   }
+
+  this._lock = true
   return [options.label, connection];
 };
 

+ 1 - 1
lib/peer.js

@@ -240,7 +240,7 @@ Peer.prototype.connect = function(peer, options) {
     this.connections[peer] = {};
   }
 
-  var connectionInfo = manager.connect(options.label);
+  var connectionInfo = manager.connect(options);
   if (!!connectionInfo) {
     this.connections[peer][connectionInfo[0]] = connectionInfo[1];
   }

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است