|
@@ -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 {
|