mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
feat(WebSocketShard): support new resume url (#8480)
This commit is contained in:
@@ -57,7 +57,7 @@
|
||||
"@sapphire/async-queue": "^1.4.0",
|
||||
"@types/ws": "^8.5.3",
|
||||
"@vladfrangu/async_event_emitter": "^2.0.1",
|
||||
"discord-api-types": "^0.36.3",
|
||||
"discord-api-types": "^0.37.2",
|
||||
"tslib": "^2.4.0",
|
||||
"ws": "^8.8.1"
|
||||
},
|
||||
|
||||
@@ -43,6 +43,10 @@ export interface SessionInfo {
|
||||
* The total number of shards at the time of this shard identifying
|
||||
*/
|
||||
shardCount: number;
|
||||
/**
|
||||
* URL to use when resuming
|
||||
*/
|
||||
resumeURL: string;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -107,8 +107,6 @@ export class WebSocketShard extends AsyncEventEmitter<WebSocketShardEventsMap> {
|
||||
throw new Error("Tried to connect a shard that wasn't idle");
|
||||
}
|
||||
|
||||
const data = this.strategy.options.gatewayInformation;
|
||||
|
||||
const { version, encoding, compression } = this.strategy.options;
|
||||
const params = new URLSearchParams({ v: version, encoding });
|
||||
if (compression) {
|
||||
@@ -127,7 +125,9 @@ export class WebSocketShard extends AsyncEventEmitter<WebSocketShardEventsMap> {
|
||||
}
|
||||
}
|
||||
|
||||
const url = `${data.url}?${params.toString()}`;
|
||||
const session = this.session ?? (await this.strategy.retrieveSessionInfo(this.id));
|
||||
|
||||
const url = `${session?.resumeURL ?? this.strategy.options.gatewayInformation.url}?${params.toString()}`;
|
||||
this.debug([`Connecting to ${url}`]);
|
||||
const connection = new WebSocket(url, { handshakeTimeout: this.strategy.options.handshakeTimeout ?? undefined })
|
||||
/* eslint-disable @typescript-eslint/no-misused-promises */
|
||||
@@ -143,7 +143,6 @@ export class WebSocketShard extends AsyncEventEmitter<WebSocketShardEventsMap> {
|
||||
|
||||
await this.waitForEvent(WebSocketShardEvents.Hello, this.strategy.options.helloTimeout);
|
||||
|
||||
const session = this.session ?? (await this.strategy.retrieveSessionInfo(this.id));
|
||||
if (session?.shardCount === this.strategy.options.shardCount) {
|
||||
this.session = session;
|
||||
await this.resume(session);
|
||||
@@ -382,6 +381,7 @@ export class WebSocketShard extends AsyncEventEmitter<WebSocketShardEventsMap> {
|
||||
sessionId: payload.d.session_id,
|
||||
shardId: this.id,
|
||||
shardCount: this.strategy.options.shardCount,
|
||||
resumeURL: payload.d.resume_gateway_url,
|
||||
};
|
||||
|
||||
await this.strategy.updateSessionInfo(this.id, this.session);
|
||||
|
||||
Reference in New Issue
Block a user