浏览代码

fix(BridgeChannel): prevent multiple websockets on retries (#2179)

* fix(BridgeChannel): prevent multiple websockets on retries

* fix(BridgeChannel): ignore different websocket close event

* fix(BridgeChannel): Keep onclose log

* ref: Add comment for retry timeout on connecting ws

* ref: Use logger debug instead info
tags/v0.0.2
Ilya Sunduev 3 年前
父节点
当前提交
a373005103
没有帐户链接到提交者的电子邮件
共有 1 个文件被更改,包括 19 次插入1 次删除
  1. 19
    1
      modules/RTC/BridgeChannel.js

+ 19
- 1
modules/RTC/BridgeChannel.js 查看文件

100
         let timeoutS = 1;
100
         let timeoutS = 1;
101
 
101
 
102
         const reload = () => {
102
         const reload = () => {
103
+            const isConnecting = this._channel && (this._channel.readyState === 'connecting'
104
+                    || this._channel.readyState === WebSocket.CONNECTING);
105
+
106
+            // Should not spawn new websockets while one is already trying to connect.
107
+            if (isConnecting) {
108
+                // Timeout is still required as there is flag `_areRetriesEnabled` that
109
+                // blocks new retrying cycles until any channel opens in current cycle.
110
+                this._retryTimeout = setTimeout(reload, timeoutS * 1000);
111
+
112
+                return;
113
+            }
114
+
103
             if (this.isOpen()) {
115
             if (this.isOpen()) {
104
                 return;
116
                 return;
105
             }
117
             }
410
         };
422
         };
411
 
423
 
412
         channel.onclose = event => {
424
         channel.onclose = event => {
413
-            logger.info(`Channel closed by ${this._closedFromClient ? 'client' : 'server'}`);
425
+            logger.debug(`Channel closed by ${this._closedFromClient ? 'client' : 'server'}`);
426
+
427
+            if (channel !== this._channel) {
428
+                logger.debug('Skip close handler, channel instance is not equal to stored one');
429
+
430
+                return;
431
+            }
414
 
432
 
415
             if (this._mode === 'websocket') {
433
             if (this._mode === 'websocket') {
416
                 if (!this._closedFromClient) {
434
                 if (!this._closedFromClient) {

正在加载...
取消
保存