feat(WebSocketShard): support new resume url
This commit is contained in:
parent
beee94c9bc
commit
9a7706fcf4
@ -62,6 +62,11 @@ class WebSocketShard extends EventEmitter {
|
|||||||
*/
|
*/
|
||||||
this.sessionId = null;
|
this.sessionId = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* URL to use when resuming
|
||||||
|
*/
|
||||||
|
this.resumeURL = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The previous heartbeat ping of the shard
|
* The previous heartbeat ping of the shard
|
||||||
* @type {number}
|
* @type {number}
|
||||||
@ -258,7 +263,7 @@ class WebSocketShard extends EventEmitter {
|
|||||||
|
|
||||||
this.debug(
|
this.debug(
|
||||||
`[CONNECT]
|
`[CONNECT]
|
||||||
Gateway : ${gateway}
|
Gateway : ${this.resumeURL ?? gateway}
|
||||||
Version : ${client.options.ws.version}
|
Version : ${client.options.ws.version}
|
||||||
Encoding : ${WebSocket.encoding}
|
Encoding : ${WebSocket.encoding}
|
||||||
Compression: ${zlib ? 'zlib-stream' : 'none'}
|
Compression: ${zlib ? 'zlib-stream' : 'none'}
|
||||||
@ -276,7 +281,7 @@ class WebSocketShard extends EventEmitter {
|
|||||||
this.debug(`Using proxy ${client.options.proxy}`, args);
|
this.debug(`Using proxy ${client.options.proxy}`, args);
|
||||||
}
|
}
|
||||||
// Adding a handshake timeout to just make sure no zombie connection appears.
|
// Adding a handshake timeout to just make sure no zombie connection appears.
|
||||||
const ws = (this.connection = WebSocket.create(gateway, wsQuery, args));
|
const ws = (this.connection = WebSocket.create(this.resumeURL ?? gateway, wsQuery, args));
|
||||||
ws.onopen = this.onOpen.bind(this);
|
ws.onopen = this.onOpen.bind(this);
|
||||||
ws.onmessage = this.onMessage.bind(this);
|
ws.onmessage = this.onMessage.bind(this);
|
||||||
ws.onerror = this.onError.bind(this);
|
ws.onerror = this.onError.bind(this);
|
||||||
@ -425,9 +430,10 @@ class WebSocketShard extends EventEmitter {
|
|||||||
this.emit(ShardEvents.READY);
|
this.emit(ShardEvents.READY);
|
||||||
|
|
||||||
this.sessionId = packet.d.session_id;
|
this.sessionId = packet.d.session_id;
|
||||||
|
this.resumeURL = packet.d.resume_gateway_url;
|
||||||
this.expectedGuilds = new Set(packet.d.guilds.filter(d => d?.unavailable == true).map(d => d.id));
|
this.expectedGuilds = new Set(packet.d.guilds.filter(d => d?.unavailable == true).map(d => d.id));
|
||||||
this.status = Status.WAITING_FOR_GUILDS;
|
this.status = Status.WAITING_FOR_GUILDS;
|
||||||
this.debug(`[READY] Session ${this.sessionId}.`);
|
this.debug(`[READY] Session ${this.sessionId} | ResumeURL ${this.resumeURL}.`);
|
||||||
this.lastHeartbeatAcked = true;
|
this.lastHeartbeatAcked = true;
|
||||||
this.sendHeartbeat('ReadyHeartbeat');
|
this.sendHeartbeat('ReadyHeartbeat');
|
||||||
break;
|
break;
|
||||||
|
1
typings/index.d.ts
vendored
1
typings/index.d.ts
vendored
@ -3336,6 +3336,7 @@ export class WebSocketShard extends EventEmitter {
|
|||||||
private sequence: number;
|
private sequence: number;
|
||||||
private closeSequence: number;
|
private closeSequence: number;
|
||||||
private sessionId: string | null;
|
private sessionId: string | null;
|
||||||
|
private resumeURL: string | null;
|
||||||
private lastPingTimestamp: number;
|
private lastPingTimestamp: number;
|
||||||
private lastHeartbeatAcked: boolean;
|
private lastHeartbeatAcked: boolean;
|
||||||
private ratelimit: { queue: unknown[]; total: number; remaining: number; time: 60e3; timer: NodeJS.Timeout | null };
|
private ratelimit: { queue: unknown[]; total: number; remaining: number; time: 60e3; timer: NodeJS.Timeout | null };
|
||||||
|
Loading…
Reference in New Issue
Block a user