mirror of
https://github.com/danbulant/discord.js
synced 2026-07-06 11:40:41 +00:00
Webpack build for branch wsrewrite: 65da634d1f355ef8679e0e66e96aeb46b584b1d7
This commit is contained in:
parent
595c3779ba
commit
d1466f2857
2 changed files with 32 additions and 2 deletions
|
|
@ -15973,6 +15973,11 @@ class WebSocketConnection extends EventEmitter {
|
||||||
this.status = Constants.Status.IDLE;
|
this.status = Constants.Status.IDLE;
|
||||||
this.packetManager = new PacketManager(this);
|
this.packetManager = new PacketManager(this);
|
||||||
this.pingSendTime = 0;
|
this.pingSendTime = 0;
|
||||||
|
this.rateLimit = {
|
||||||
|
queue: [],
|
||||||
|
remaining: 120,
|
||||||
|
resetTime: -1,
|
||||||
|
};
|
||||||
this.connect(gateway);
|
this.connect(gateway);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -16024,13 +16029,38 @@ class WebSocketConnection extends EventEmitter {
|
||||||
return erlpack ? erlpack.pack(data) : JSON.stringify(data);
|
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) {
|
if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
|
||||||
return this.debug(`Tried to send packet ${data} but no WebSocket is available!`);
|
return this.debug(`Tried to send packet ${data} but no WebSocket is available!`);
|
||||||
}
|
}
|
||||||
return this.ws.send(this.pack(data));
|
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) {
|
connect(gateway = this.gateway, after = 0, force = false) {
|
||||||
if (after) return this.client.setTimeout(() => this.connect(gateway, 0, force), after); // eslint-disable-line
|
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');
|
if (this.ws && !force) return this.debug('WebSocket connection already exists');
|
||||||
|
|
|
||||||
2
discord.wsrewrite.min.js
vendored
2
discord.wsrewrite.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue