Skip to content

Commit

Permalink
fix(ws): add destory method to WS Provider
Browse files Browse the repository at this point in the history
  • Loading branch information
osdio committed Jul 26, 2020
1 parent 54f02f9 commit dfcf417
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/WS/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class WsRpc extends IPC_WS {
this.clientConfig = options.clientConfig;

this._timeout = null;
this._destroyed = false;

this.reconnect();

Expand All @@ -45,6 +46,7 @@ class WsRpc extends IPC_WS {
}

reconnect() {
if (this._destroyed) return;
this.disconnect();
this.socket = new Websocket(this.path, this.protocol, null, this.headers, null, this.clientConfig);
this.socket.onopen = () => {
Expand All @@ -67,6 +69,14 @@ class WsRpc extends IPC_WS {
clearTimeout(this._timeout);
this.socket = null;
}

destroy() {
this.disconnect();
this.remove('error');
this.remove('close');
this.remove('connect');
this._destroyed = true;
}
}

export const WS_RPC = WsRpc;
Expand Down

0 comments on commit dfcf417

Please sign in to comment.