Sfoglia il codice sorgente

websocket重连优化

li.shaoyi 3 anni fa
parent
commit
800768d149
2 ha cambiato i file con 7 aggiunte e 3 eliminazioni
  1. 6 2
      src/services/index.ts
  2. 1 1
      src/utils/websocket/index.ts

+ 6 - 2
src/services/index.ts

@@ -1,4 +1,4 @@
-import { checkTokenAction, stopCheckToken } from '@/services/bus/token';
+import { checkTokenAction, handleTokenCheck, stopCheckToken } from '@/services/bus/token';
 import { NeedClearSourceDataType, NoClearSourceDataType } from '@/services/dataCenter/interface';
 import { funCode } from '@/services/funcode/index';
 import { serviceURL } from '@/services/request/index';
@@ -97,10 +97,12 @@ export default new (class LifeCycleCtr {
     sendQuoteServer(p: Package40, rsp?: number, callback?: Callback): void {
         this.Socket['quote'].send(p, rsp, callback);
     }
+
     /** 主动关闭行情服务 */
     closeQuote() {
         this.Socket['quote'].close();
     }
+
     /** 主动关闭长链接 */
     closeServer(): void {
         this.Socket['trade'].close();
@@ -193,7 +195,9 @@ export default new (class LifeCycleCtr {
                 /** 重连成功,将进行业务操作 */
                 case ReconnectChangeState.ReconnectSuccessed:
                     // 重新启动定时 token 校验
-                    checkTokenAction()
+                    handleTokenCheck().then(() => {
+                        checkTokenAction();
+                    })
                     console.log(obj.host, '重连成功,将进行业务操作');
                     break;
                 /** 重连成功后业务操作失败并将再次重试,由业务模块发起 */

+ 1 - 1
src/utils/websocket/index.ts

@@ -151,7 +151,6 @@ export class MTP2WebSocket<T extends Package40 | Package50> {
                 // 连接发生错误
                 this.socket.onerror = () => {
                     const message = this.host + '连接发生错误';
-                    this.connState = 'Unconnected';
                     this.onError && this.onError(this, new Error(message));
                     this.callAllAsyncTaskOnReconnecting();  // 回调当前所有发送信息错误块
                     this.reconnect();
@@ -468,6 +467,7 @@ export class MTP2WebSocket<T extends Package40 | Package50> {
                 // 重连失败处理,如果重连过程中主动断开的了就不再进行重连
                 if (!this.isBrokenReconnecting) {
                     console.log(this.packageType, this.host, `第${this.reconnectCount}次重连失败`);
+                    this.connState = 'Unconnected';
                     this.reconnect();
                 }
             })