Skip to content

Commit

Permalink
🚑️ fix: url for resuming should be different
Browse files Browse the repository at this point in the history
  • Loading branch information
Helloyunho committed May 17, 2024
1 parent eda5336 commit 027a8f8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/gateway/handlers/ready.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const ready: GatewayEventHandler = async (
gateway: Gateway,
d: Ready
) => {
gateway._resumeGatewayURL = d.resume_gateway_url
gateway._guildsToBeLoaded =
gateway.client.intents!.includes(GatewayIntents.GUILDS) === true
? d.guilds.length
Expand Down
11 changes: 8 additions & 3 deletions src/gateway/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export class Gateway extends HarmonyEventEmitter<GatewayTypedEvents> {
shards?: number[]
ping: number = 0

_resumeGatewayURL?: string
_readyReceived: Promise<void>
_resolveReadyReceived?: () => void
_guildsToBeLoaded?: number
Expand Down Expand Up @@ -466,17 +467,21 @@ export class Gateway extends HarmonyEventEmitter<GatewayTypedEvents> {
}

this.closeGateway(RECONNECT_CODE, 'Reconnecting...')
this.initWebsocket()
this.initWebsocket(!(forceNew ?? false))
}

initWebsocket(): void {
initWebsocket(resume: boolean = false): void {
if (this.#destroyCalled) return
if (resume && this._resumeGatewayURL === undefined)
throw new Error('Resume was requested but no resume URL was found')

this.emit('init')
this.debug('Initializing WebSocket...')
const url = resume ? this._resumeGatewayURL : Constants.DISCORD_GATEWAY_URL
this._resumeGatewayURL = undefined
this.websocket = new WebSocket(
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
`${Constants.DISCORD_GATEWAY_URL}/?v=${Constants.DISCORD_API_VERSION}&encoding=json`,
`${url}/?v=${Constants.DISCORD_API_VERSION}&encoding=json`,
[]
)
this.websocket.binaryType = 'arraybuffer'
Expand Down

0 comments on commit 027a8f8

Please sign in to comment.