Skip to content

Commit e19a10b

Browse files
committed
improve: disconnection handling
This commit improves how the library handles disconnections in the WebSocket.
1 parent 970fddb commit e19a10b

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

index.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ const MAX_NONCE = 2 ** 32
1515
const MAX_TIMESTAMP = 2 ** 32
1616
const MAX_SEQUENCE = 2 ** 16
1717
const DISCORD_CLOSE_CODES = {
18+
1006: { reconnect: true },
1819
4014: { error: false },
19-
4015: { reconnect: true },
20+
4015: { reconnect: true }
2021
}
2122

2223
const ssrcs = {}
@@ -289,7 +290,6 @@ class Connection extends EventEmitter {
289290
const closeCode = DISCORD_CLOSE_CODES[code]
290291

291292
if (closeCode?.reconnect) {
292-
this._updateState({ status: 'disconnected', reason: 'websocketClose', code })
293293
this._updatePlayerState({ status: 'idle', reason: 'reconnecting' })
294294

295295
this.emit('reconnecting', reason)
@@ -299,9 +299,6 @@ class Connection extends EventEmitter {
299299
} else {
300300
this._destroy({ status: 'disconnected', reason: 'websocketClose', code })
301301

302-
if (closeCode?.error !== false)
303-
this.emit('error', new Error(reason || `WebSocket closed with code: ${code}`))
304-
305302
return;
306303
}
307304
})

0 commit comments

Comments
 (0)