浏览代码

disconnect

Michelle Bu 11 年之前
父节点
当前提交
f15526bbfb
共有 3 个文件被更改,包括 12 次插入11 次删除
  1. 6 5
      dist/peer.js
  2. 0 0
      dist/peer.min.js
  3. 6 6
      lib/dataconnection.js

+ 6 - 5
dist/peer.js

@@ -1689,13 +1689,14 @@ DataConnection.prototype._configureDataChannel = function() {
 }
 }
 
 
 DataConnection.prototype._cleanup = function() {
 DataConnection.prototype._cleanup = function() {
-  if (this._dc && this._dc.readyState !== 'closed') {
+  if (this._dc.readyState !== 'closing' && this._dc.readyState !== 'closed') {
     this._dc.close();
     this._dc.close();
-    this._dc = null;
+    this.open = false;
+    Negotiator.cleanup(this);
+    this.emit('close');
+  } else {
+    this.emit('error', new Error('The connection has already been closed'));
   }
   }
-  this.open = false;
-  Negotiator.cleanup(this);
-  this.emit('close');
 }
 }
 
 
 // Handles a DataChannel message.
 // Handles a DataChannel message.

文件差异内容过多而无法显示
+ 0 - 0
dist/peer.min.js


+ 6 - 6
lib/dataconnection.js

@@ -81,14 +81,14 @@ DataConnection.prototype._configureDataChannel = function() {
 }
 }
 
 
 DataConnection.prototype._cleanup = function() {
 DataConnection.prototype._cleanup = function() {
-  if (this._dc && this._dc.readyState !== 'closed') {
-    console.log('closing', this._dc);
+  if (this._dc.readyState !== 'closing' && this._dc.readyState !== 'closed') {
     this._dc.close();
     this._dc.close();
-    this._dc = null;
+    this.open = false;
+    Negotiator.cleanup(this);
+    this.emit('close');
+  } else {
+    this.emit('error', new Error('The connection has already been closed'));
   }
   }
-  this.open = false;
-  Negotiator.cleanup(this);
-  this.emit('close');
 }
 }
 
 
 // Handles a DataChannel message.
 // Handles a DataChannel message.

部分文件因为文件数量过多而无法显示