websocket cleanup (#1346)

* websocket cleanup

* resume event

* Update Resumed.js

* Update WebSocketManager.js
This commit is contained in:
Gus Caplan
2017-04-10 13:02:17 -05:00
committed by Crawl
parent 8436cbe8b1
commit 0a56fa0aae
8 changed files with 167 additions and 79 deletions

View File

@@ -1,4 +1,5 @@
const Constants = require('../util/Constants');
const WebSocketConnection = require('./websocket/WebSocketConnection');
/**
* Manages the State and Background Tasks of the Client
@@ -29,7 +30,9 @@ class ClientManager {
this.client.emit(Constants.Events.DEBUG, `Authenticated using token ${token}`);
this.client.token = token;
const timeout = this.client.setTimeout(() => reject(new Error(Constants.Errors.TOOK_TOO_LONG)), 1000 * 300);
this.client.rest.methods.getGateway().then(gateway => {
this.client.rest.methods.getGateway().then(res => {
const protocolVersion = Constants.DefaultOptions.ws.version;
const gateway = `${res.url}/?v=${protocolVersion}&encoding=${WebSocketConnection.ENCODING}`;
this.client.emit(Constants.Events.DEBUG, `Using gateway ${gateway}`);
this.client.ws.connect(gateway);
this.client.ws.once('close', event => {