Reorganise disabledEvents stuff

This commit is contained in:
Schuyler Cebulskie
2016-10-09 14:41:57 -04:00
parent 7b571f9729
commit dabe51fc8d
3 changed files with 9 additions and 13 deletions

View File

@@ -41,13 +41,6 @@ class Client extends EventEmitter {
throw new TypeError('The disabledEvents client option must be an array.');
}
let disabledEvents = {};
for (const event in this.options.disabledEvents) {
disabledEvents[event] = true;
}
this.options.disabledEvents = disabledEvents;
/**
* The REST manager of the client
* @type {RESTManager}

View File

@@ -59,6 +59,13 @@ class WebSocketManager extends EventEmitter {
*/
this.ws = null;
/**
* An object with keys that are websocket event names that should be ignored
* @type {Object}
*/
this.disabledEvents = {};
for (const event in client.options.disabledEvents) this.disabledEvents[event] = true;
this.first = true;
}
@@ -69,9 +76,7 @@ class WebSocketManager extends EventEmitter {
_connect(gateway) {
this.client.emit('debug', `Connecting to gateway ${gateway}`);
this.normalReady = false;
if (this.status !== Constants.Status.RECONNECTING) {
this.status = Constants.Status.CONNECTING;
}
if (this.status !== Constants.Status.RECONNECTING) this.status = Constants.Status.CONNECTING;
this.ws = new WebSocket(gateway);
this.ws.onopen = () => this.eventOpen();
this.ws.onclose = (d) => this.eventClose(d);

View File

@@ -84,9 +84,7 @@ class WebSocketPacketManager {
this.setSequence(packet.s);
if (this.ws.client.options.disabledEvents[packet.t] !== undefined) {
return false;
}
if (this.ws.disabledEvents[packet.t] !== undefined) return false;
if (this.ws.status !== Constants.Status.READY) {
if (BeforeReadyWhitelist.indexOf(packet.t) === -1) {