mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-16 19:43:29 +01:00
@@ -35,6 +35,13 @@ class WebSocketShard extends EventEmitter {
|
|||||||
*/
|
*/
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The resume URL for this shard
|
||||||
|
* @type {?string}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
this.resumeURL = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The current status of the shard
|
* The current status of the shard
|
||||||
* @type {Status}
|
* @type {Status}
|
||||||
@@ -191,12 +198,14 @@ class WebSocketShard extends EventEmitter {
|
|||||||
* or reject if we couldn't connect
|
* or reject if we couldn't connect
|
||||||
*/
|
*/
|
||||||
connect() {
|
connect() {
|
||||||
const { gateway, client } = this.manager;
|
const { client } = this.manager;
|
||||||
|
|
||||||
if (this.connection?.readyState === WebSocket.OPEN && this.status === Status.READY) {
|
if (this.connection?.readyState === WebSocket.OPEN && this.status === Status.READY) {
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const gateway = this.resumeURL ?? this.manager.gateway;
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const cleanup = () => {
|
const cleanup = () => {
|
||||||
this.removeListener(ShardEvents.CLOSE, onClose);
|
this.removeListener(ShardEvents.CLOSE, onClose);
|
||||||
@@ -418,10 +427,11 @@ class WebSocketShard extends EventEmitter {
|
|||||||
*/
|
*/
|
||||||
this.emit(ShardEvents.READY);
|
this.emit(ShardEvents.READY);
|
||||||
|
|
||||||
|
this.resumeURL = packet.d.resume_gateway_url;
|
||||||
this.sessionId = packet.d.session_id;
|
this.sessionId = packet.d.session_id;
|
||||||
this.expectedGuilds = new Set(packet.d.guilds.map(d => d.id));
|
this.expectedGuilds = new Set(packet.d.guilds.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} | Resume url ${this.resumeURL}.`);
|
||||||
this.lastHeartbeatAcked = true;
|
this.lastHeartbeatAcked = true;
|
||||||
this.sendHeartbeat('ReadyHeartbeat');
|
this.sendHeartbeat('ReadyHeartbeat');
|
||||||
break;
|
break;
|
||||||
@@ -840,8 +850,9 @@ class WebSocketShard extends EventEmitter {
|
|||||||
// Step 4: Cache the old sequence (use to attempt a resume)
|
// Step 4: Cache the old sequence (use to attempt a resume)
|
||||||
if (this.sequence !== -1) this.closeSequence = this.sequence;
|
if (this.sequence !== -1) this.closeSequence = this.sequence;
|
||||||
|
|
||||||
// Step 5: Reset the sequence and session id if requested
|
// Step 5: Reset the sequence, resume URL and session id if requested
|
||||||
if (reset) {
|
if (reset) {
|
||||||
|
this.resumeURL = null;
|
||||||
this.sequence = -1;
|
this.sequence = -1;
|
||||||
this.sessionId = null;
|
this.sessionId = null;
|
||||||
}
|
}
|
||||||
|
|||||||
1
typings/index.d.ts
vendored
1
typings/index.d.ts
vendored
@@ -2923,6 +2923,7 @@ export class WebSocketShard extends EventEmitter {
|
|||||||
private constructor(manager: WebSocketManager, id: number);
|
private constructor(manager: WebSocketManager, id: number);
|
||||||
private sequence: number;
|
private sequence: number;
|
||||||
private closeSequence: number;
|
private closeSequence: number;
|
||||||
|
private resumeURL: string | null;
|
||||||
private sessionId: string | null;
|
private sessionId: string | null;
|
||||||
private lastPingTimestamp: number;
|
private lastPingTimestamp: number;
|
||||||
private lastHeartbeatAcked: boolean;
|
private lastHeartbeatAcked: boolean;
|
||||||
|
|||||||
Reference in New Issue
Block a user