开发:增加websocket状态和正确的关闭

pull/1649/head
ChenX 3 years ago
parent e7dff7a49f
commit 51db33de77

@ -6,6 +6,7 @@ import { Log } from "../Common/Log";
export class WebSocketClientServer export class WebSocketClientServer
{ {
private ws: WebSocket; private ws: WebSocket;
private _Closeing = false;//关闭中,停止尝试
mode: string; mode: string;
@ -40,7 +41,7 @@ export class WebSocketClientServer
this.OnLinkEvent(false); this.OnLinkEvent(false);
if (retry && e.code !== 1000) if (retry && e.code !== 1000 && !this._Closeing)
setTimeout(() => this.Connect(), 1 * 1000); setTimeout(() => this.Connect(), 1 * 1000);
}; };
}); });
@ -67,13 +68,18 @@ export class WebSocketClientServer
{ {
this.mode = event.data; this.mode = event.data;
}; };
get IsLink() { return this.ws?.readyState === 1; }
OnLinkEvent(isLink: boolean) OnLinkEvent(isLink: boolean)
{ {
if (isLink) if (isLink)
Log("成功连接到效果图软件!"); Log("成功连接到效果图软件!");
} }
async Close() async Close()
{ {
this._Closeing = true;
if (this._ConnectionPromise) if (this._ConnectionPromise)
await this._ConnectionPromise; await this._ConnectionPromise;
if (this.ws) if (this.ws)

Loading…
Cancel
Save