-
-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rewrite WebSocket internals #1410
Conversation
@@ -13,6 +13,8 @@ class ResumedHandler extends AbstractHandler { | |||
client.emit('debug', `RESUMED ${ws._trace.join(' -> ')} | replayed ${replayed} events. `); | |||
client.emit('resume', replayed); | |||
|
|||
ws.connection.triggerReady(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOOOOOOOOOOOOOOOOOOOOOO
|
||
if (this.ws.disabledEvents[packet.t] !== undefined) return false; | ||
// #if (this.ws.disabledEvents[packet.t] !== undefined) return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no more disabled events?
this._emitReady(); | ||
} | ||
switch (this.connection.status) { | ||
case Constants.Status.IDLE: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these can be compounded
case Constants.Status.IDLE:
case Constants.Status.DISCONNECTED:
this.connection.connect(gateway, 5500);
return true;
if ([4004, 4010, 4011].includes(event.code)) return; | ||
if (!this.reconnecting && event.code !== 1000) this.tryReconnect(); | ||
send(packet) { | ||
if (!this.connection) return this.debug('No connection to websocket'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
}); | ||
this.sequence = -1; | ||
destroy() { | ||
if (!this.connection) return this.debug('Attempted to destroy WebSocket but no connection exists!'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return this.debug
returns this.client.emit
which means you return based on if the debug
event has listeners
*/ | ||
send(data) { | ||
if (!this.ws || this.ws.readyState !== WebSocket.OPEN) { | ||
return this.debug(`Tried to send packet ${data} but no WebSocket is available!`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AAAAAAAAAAA
get readyState() { | ||
return this.ws.readyState; | ||
setSequence(s) { | ||
this.sequence = s > this.sequence ? s : this.sequence; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this could result in this.sequence = this.sequence
which is kinda useless
*/ | ||
reconnect() { | ||
this.client.emit(Constants.Events.RECONNECTING); | ||
this.connect(this.gateway, 5500, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this 5500 is used a lot, it should probably be moved to a variable somewhere
* @param {Error} error Error that occurred | ||
*/ | ||
onError(error) { | ||
this.debug(error); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
client error event???
this.emit('close', event); | ||
this.heartbeat(-1); | ||
// Should we reconnect? | ||
if (![1000, 4004, 4010, 4011].includes(event.code)) this.reconnect(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
constants with map of code => error message like we talked about earlier
Just wanted to comment to say I'm leaving a test script up with multiple shards on for a couple days and I'll report back when it's done. It's currently reporting idle(3) for all shards though. |
@JMTK could you add |
@hydrabolt 1st line is the Authenticated using token line so i just took it out. Everything else is what it stopped at(including my own logs) and then you can see me logging the .status of 3 The latency is fairly high but all the heartbeats afterwards were short: |
* Start rewriting Manager and Connection * more stuff * stuff * Fix ready bug * some stuff i forgot * fix some stuff * add stupid heartbeat ack like seriously who cares * woo! * fix a bug * rate limit the dumb websocket * stuff * hdocs * Docs * Remove ClientManager#setupKeepAlive as it is now redundant * Change Client._pingTimestamp to a getter that fetches the timestamp from the WebSocketConnection * are you happy now eslint smh * make gus happy * Add CloseEvent external doc * Make sure to emit 'reconnecting' when actually reconnecting * ffs * Fix RESUME logic * Add heartbeat ack debug messages, including latency data * Dumb stuff for Gus * thx eslint * more dumb stuff * more dumb crap smh gus i h8 u * moar messages * fix for using wrong status, causing certain events not to be fired (discordjs#1422)
* Start rewriting Manager and Connection * more stuff * stuff * Fix ready bug * some stuff i forgot * fix some stuff * add stupid heartbeat ack like seriously who cares * woo! * fix a bug * rate limit the dumb websocket * stuff * hdocs * Docs * Remove ClientManager#setupKeepAlive as it is now redundant * Change Client._pingTimestamp to a getter that fetches the timestamp from the WebSocketConnection * are you happy now eslint smh * make gus happy * Add CloseEvent external doc * Make sure to emit 'reconnecting' when actually reconnecting * ffs * Fix RESUME logic * Add heartbeat ack debug messages, including latency data * Dumb stuff for Gus * thx eslint * more dumb stuff * more dumb crap smh gus i h8 u * moar messages * fix for using wrong status, causing certain events not to be fired (discordjs#1422)
Please describe the changes this PR makes and why it should be merged:
Rewrites the internal WebSocket stuff so it's not as crappy and easier to use for internal sharding in the future
Semantic versioning classification:
Todo: