Sfoglia il codice sorgente

update:修正关闭的时候的自动重连&提供非单例模式

adam 3 anni fa
parent
commit
ea8aaa4f84
2 ha cambiato i file con 8 aggiunte e 4 eliminazioni
  1. 1
    1
      package.json
  2. 7
    3
      src/index.ts

+ 1
- 1
package.json Vedi File

1
 {
1
 {
2
   "name": "@bilingo.com/ts-linker-sdk",
2
   "name": "@bilingo.com/ts-linker-sdk",
3
-  "version": "1.0.3",
3
+  "version": "1.0.4",
4
   "description": "linker's ts sdk",
4
   "description": "linker's ts sdk",
5
   "main": "dist/umd/index.js",
5
   "main": "dist/umd/index.js",
6
   "types": "dist/types/index.d.ts",
6
   "types": "dist/types/index.d.ts",

+ 7
- 3
src/index.ts Vedi File

48
    * 通过单例模式获取客户端链接
48
    * 通过单例模式获取客户端链接
49
    * @param url websocket链接地址
49
    * @param url websocket链接地址
50
    * @param readyStateCallback 链接状态回调,可以处理onOpen、onClose、onError
50
    * @param readyStateCallback 链接状态回调,可以处理onOpen、onClose、onError
51
+   * @param binaryType "arraybuffer" | "blob"
52
+   * @param allwaysNew 是否保持新建Client
51
    */
53
    */
52
-  public static getInstance(url: string, callback: ReadyStateCallback, binaryType?: BinaryType): Client {
53
-    if (!Client.instance) {
54
+  public static getInstance(url: string, callback: ReadyStateCallback, binaryType?: BinaryType, allwaysNew?: boolean): Client {
55
+    if (allwaysNew || !Client.instance) {
54
       Client.instance = new Client(url, callback, binaryType);
56
       Client.instance = new Client(url, callback, binaryType);
55
     }
57
     }
56
 
58
 
247
    * 关闭客户端链接
249
    * 关闭客户端链接
248
    */
250
    */
249
   public close(code?: number, reason?: string): void {
251
   public close(code?: number, reason?: string): void {
252
+    // 如果是主动关闭
253
+    this.reconnectLock = true;
250
     this.socket.close(code, reason);
254
     this.socket.close(code, reason);
251
   }
255
   }
252
   /**
256
   /**
336
     return ws;
340
     return ws;
337
   }
341
   }
338
 
342
 
339
-  /**
343
+  /**`
340
    * 断线重连
344
    * 断线重连
341
    */
345
    */
342
   private reconnect(): void {
346
   private reconnect(): void {