Selaa lähdekoodia

Consider ICE closed/failed as a terminal state and unbind all events

Fix unbinding of signalling data channel events and the
"connection failed" timer
Lennart Grahl 6 vuotta sitten
vanhempi
commit
c19dc3c35a
1 muutettua tiedostoa jossa 16 lisäystä ja 1 poistoa
  1. 16 1
      src/services/peerconnection.ts

+ 16 - 1
src/services/peerconnection.ts

@@ -150,7 +150,8 @@ export class PeerConnectionHelper {
                             // situations which certainly would lead to ugly race conditions.
                             this.connectionFailedTimer = null;
                             this.log.debug('ICE connection considered failed');
-                            this.pc.close();
+                            this.setConnectionState(TaskConnectionState.Disconnected);
+                            this.close();
                         }, PeerConnectionHelper.CONNECTION_FAILED_TIMEOUT_MS, true, 'connectionFailedTimer');
                         break;
                     case 'connected':
@@ -160,6 +161,7 @@ export class PeerConnectionHelper {
                     case 'failed':
                     case 'closed':
                         this.setConnectionState(TaskConnectionState.Disconnected);
+                        this.close();
                         break;
                     default:
                         this.log.warn('Ignored ICE connection state change to',
@@ -285,7 +287,18 @@ export class PeerConnectionHelper {
      * Unbind all event handler and abruptly close the peer connection.
      */
     public close(): void {
+        // Cancel connection failed timer
+        if (this.connectionFailedTimer !== null) {
+            this.timeoutService.cancel(this.connectionFailedTimer);
+            this.connectionFailedTimer = null;
+        }
+
+        // Unbind all events
         this.webrtcTask.off();
+        this.sdc.dc.onopen = null;
+        this.sdc.dc.onclose = null;
+        this.sdc.dc.onerror = null;
+        this.sdc.dc.onmessage = null;
         this.pc.onnegotiationneeded = null;
         this.pc.onconnectionstatechange = null;
         this.pc.onsignalingstatechange = null;
@@ -294,6 +307,8 @@ export class PeerConnectionHelper {
         this.pc.oniceconnectionstatechange = null;
         this.pc.onicegatheringstatechange = null;
         this.pc.ondatachannel = null;
+
+        // Close peer connection
         this.pc.close();
     }
 }