Browse Source

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

adam 3 years ago
parent
commit
ea8aaa4f84
2 changed files with 8 additions and 4 deletions
  1. 1
    1
      package.json
  2. 7
    3
      src/index.ts

+ 1
- 1
package.json View File

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

+ 7
- 3
src/index.ts View File

@@ -48,9 +48,11 @@ class Client {
48 48
    * 通过单例模式获取客户端链接
49 49
    * @param url websocket链接地址
50 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 56
       Client.instance = new Client(url, callback, binaryType);
55 57
     }
56 58
 
@@ -247,6 +249,8 @@ class Client {
247 249
    * 关闭客户端链接
248 250
    */
249 251
   public close(code?: number, reason?: string): void {
252
+    // 如果是主动关闭
253
+    this.reconnectLock = true;
250 254
     this.socket.close(code, reason);
251 255
   }
252 256
   /**
@@ -336,7 +340,7 @@ class Client {
336 340
     return ws;
337 341
   }
338 342
 
339
-  /**
343
+  /**`
340 344
    * 断线重连
341 345
    */
342 346
   private reconnect(): void {