afrokick 6 年之前
父节点
当前提交
07053a9ba8
共有 3 个文件被更改,包括 37 次插入4 次删除
  1. 1 1
      lib/baseconnection.ts
  2. 14 0
      lib/dataconnection.ts
  3. 22 3
      lib/mediaconnection.ts

+ 1 - 1
lib/baseconnection.ts

@@ -19,7 +19,7 @@ export abstract class BaseConnection extends EventEmitter {
 
 
   constructor(
   constructor(
     readonly peer: string,
     readonly peer: string,
-    readonly provider: Peer,
+    public provider: Peer,
     readonly options: any
     readonly options: any
   ) {
   ) {
     super();
     super();

+ 14 - 0
lib/dataconnection.ts

@@ -173,6 +173,20 @@ export class DataConnection extends BaseConnection {
       this._negotiator = null;
       this._negotiator = null;
     }
     }
 
 
+    if (this.provider) {
+      const connections = this.provider.connections[this.peer];
+
+      if (connections) {
+        const index = connections.indexOf(this);
+
+        if (index !== -1) {
+          connections.splice(index, 1);
+        }
+      }
+
+      this.provider = null;
+    }
+
     if (!this.open) {
     if (!this.open) {
       return;
       return;
     }
     }

+ 22 - 3
lib/mediaconnection.ts

@@ -75,10 +75,8 @@ export class MediaConnection extends BaseConnection {
       return;
       return;
     }
     }
 
 
-    this.options._payload._stream = stream;
-
     this._localStream = stream;
     this._localStream = stream;
-    this._negotiator.startConnection(this.options._payload);
+    this._negotiator.startConnection({ ...this.options._payload, _stream: stream });
     // Retrieve lost messages stored because PeerConnection not set up.
     // Retrieve lost messages stored because PeerConnection not set up.
     const messages = this.provider._getMessages(this.connectionId);
     const messages = this.provider._getMessages(this.connectionId);
 
 
@@ -100,6 +98,27 @@ export class MediaConnection extends BaseConnection {
       this._negotiator = null;
       this._negotiator = null;
     }
     }
 
 
+    this._localStream = null;
+    this._remoteStream = null;
+
+    if (this.provider) {
+      const connections = this.provider.connections[this.peer];
+
+      if (connections) {
+        const index = connections.indexOf(this);
+
+        if (index !== -1) {
+          connections.splice(index, 1);
+        }
+      }
+
+      this.provider = null;
+    }
+
+    if (this.options && this.options._stream) {
+      this.options._stream = null;
+    }
+
     if (!this.open) {
     if (!this.open) {
       return;
       return;
     }
     }