mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 09:03:29 +01:00
fix: emit resume event, silent disconnects, error event param (#3192)
* src: Fix shardResumed event not being emitted
* docs: Document Client#error again
* src: Fix onError due to incorrect typings
* src: handle onError properly for both uws and ws
* src: Try to fix silent disconnects when using uWs
* fix(WebSocketShard): uws emits plain objects, not errors
Emitting line of code: 39aa429f94/src/uws.js (L80-L83)
Listener attaching is here: https://github.com/discordjs/uws/blob/master/src/uws.js#L128
For reference, found a clue here: https://github.com/discordjs/discord.js/issues/1528
This commit is contained in:
@@ -239,7 +239,7 @@ class WebSocketShard extends EventEmitter {
|
||||
|
||||
/**
|
||||
* Called whenever a message is received.
|
||||
* @param {Event} event Event received
|
||||
* @param {MessageEvent} event Event received
|
||||
* @private
|
||||
*/
|
||||
onMessage({ data }) {
|
||||
@@ -266,11 +266,14 @@ class WebSocketShard extends EventEmitter {
|
||||
|
||||
/**
|
||||
* Called whenever an error occurs with the WebSocket.
|
||||
* @param {ErrorEvent} error The error that occurred
|
||||
* @param {ErrorEvent|Object} event The error that occurred
|
||||
* @private
|
||||
*/
|
||||
onError({ error }) {
|
||||
if (error && error.message === 'uWs client connection error') {
|
||||
onError(event) {
|
||||
const error = event && event.error ? event.error : error;
|
||||
if (!error) return;
|
||||
|
||||
if (error.message === 'uWs client connection error') {
|
||||
this.debug('Received a uWs error. Closing the connection and reconnecting...');
|
||||
this.connection.close(4000);
|
||||
return;
|
||||
@@ -295,6 +298,11 @@ class WebSocketShard extends EventEmitter {
|
||||
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/ErrorEvent}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @external MessageEvent
|
||||
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Called whenever a connection to the gateway is closed.
|
||||
* @param {CloseEvent} event Close event that was received
|
||||
@@ -581,7 +589,7 @@ class WebSocketShard extends EventEmitter {
|
||||
this.setHeartbeatTimer(-1);
|
||||
this.setHelloTimeout(-1);
|
||||
// Close the WebSocket connection, if any
|
||||
if (this.connection) {
|
||||
if (this.connection && this.connection.readyState !== WebSocket.CLOSED) {
|
||||
this.connection.close(closeCode);
|
||||
} else {
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user