Webpack build for branch wsrewrite: 65da634d1f355ef8679e0e66e96aeb46b584b1d7

This commit is contained in:
Travis CI 2017-04-24 20:43:31 +00:00
parent 595c3779ba
commit d1466f2857
2 changed files with 32 additions and 2 deletions

View file

@ -15973,6 +15973,11 @@ class WebSocketConnection extends EventEmitter {
this.status = Constants.Status.IDLE;
this.packetManager = new PacketManager(this);
this.pingSendTime = 0;
this.rateLimit = {
queue: [],
remaining: 120,
resetTime: -1,
};
this.connect(gateway);
}
@ -16024,13 +16029,38 @@ class WebSocketConnection extends EventEmitter {
return erlpack ? erlpack.pack(data) : JSON.stringify(data);
}
send(data) {
processQueue() {
if (this.rateLimit.remaining === 0) return;
if (this.rateLimit.queue.length === 0) return;
if (this.rateLimit.remaining === 120) {
this.rateLimit.resetTimer = setTimeout(() => {
this.rateLimit.remaining = 120;
this.processQueue();
}, 120e3); // eslint-disable-line
}
while (this.rateLimit.remaining > 0) {
const item = this.rateLimit.queue.shift();
if (!item) return;
this._send(item);
this.rateLimit.remaining--;
}
}
_send(data) {
if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
return this.debug(`Tried to send packet ${data} but no WebSocket is available!`);
}
return this.ws.send(this.pack(data));
}
send(data) {
if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
return this.debug(`Tried to send packet ${data} but no WebSocket is available!`);
}
this.rateLimit.queue.push(data);
return this.processQueue();
}
connect(gateway = this.gateway, after = 0, force = false) {
if (after) return this.client.setTimeout(() => this.connect(gateway, 0, force), after); // eslint-disable-line
if (this.ws && !force) return this.debug('WebSocket connection already exists');

File diff suppressed because one or more lines are too long