Add client.destroy();

This commit is contained in:
Amish Shah
2016-08-30 13:05:50 +01:00
parent 56352220af
commit d249aa10cc
18 changed files with 74 additions and 42 deletions

View File

@@ -76,11 +76,17 @@ class WebSocketManager {
this.doQueue();
}
destroy() {
this.ws.close(1000);
this._queue = [];
this.status = Constants.Status.IDLE;
}
doQueue() {
const item = this._queue[0];
if (this.ws.readyState === WebSocket.OPEN && item) {
if (this._remaining === 0) {
return setTimeout(() => {
return this.client.setTimeout(() => {
this.doQueue();
}, 1000);
}
@@ -88,7 +94,7 @@ class WebSocketManager {
this.ws.send(item);
this._queue.shift();
this.doQueue();
setTimeout(() => this._remaining++, 1000);
this.client.setTimeout(() => this._remaining++, 1000);
}
}
@@ -144,11 +150,10 @@ class WebSocketManager {
* @returns {null}
*/
eventClose(event) {
console.log(event.code);
if (event.code === 4004) {
throw Constants.Errors.BAD_LOGIN;
}
if (!this.reconnecting) {
if (!this.reconnecting && event.code !== 1000) {
this.tryReconnect();
}
}