瀏覽代碼

Consider further 'close' events as terminal states

Lennart Grahl 6 年之前
父節點
當前提交
09c5a83ff6
共有 1 個文件被更改,包括 15 次插入1 次删除
  1. 15 1
      src/services/webclient.ts

+ 15 - 1
src/services/webclient.ts

@@ -577,6 +577,17 @@ export class WebClientService {
                         this.arpLog.warn('Unknown signaling state:', state);
                 }
             }
+
+            // Close the peer connection.
+            // Note: For some reason, we do not receive 'close' events for the main data channel,
+            //       so this is a fallback mechanism.
+            if (this.pcHelper !== null && state === 'closed') {
+                this.arpLog.debug('Closing peer connection');
+                this.stateService.updateTaskConnectionState(threema.TaskConnectionState.Disconnected);
+                this.pcHelper.onConnectionStateChange = null;
+                this.pcHelper.close();
+            }
+
             this.stateService.updateSignalingConnectionState(state, this.chosenTask, this.handoverDone);
         });
 
@@ -1095,7 +1106,10 @@ export class WebClientService {
                 });
             };
             dc.onclose = () => {
-                this.arpLog.info(`Data channel ${dc.label} closed`);
+                this.arpLog.info(`Data channel ${dc.label} closed, closing peer connection`);
+                this.stateService.updateTaskConnectionState(threema.TaskConnectionState.Disconnected);
+                this.pcHelper.onConnectionStateChange = null;
+                this.pcHelper.close();
             };
             dc.onerror = (event) => {
                 this.arpLog.error(`Data channel ${dc.label} error:`, event);