@discordjs/ws 0.3.0-dev.1660478713-bc06cc6.0 → 0.3.0-dev.1660910640-e475b63.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"utils.cjs","sources":["../../src/utils/utils.ts"],"sourcesContent":["import type { ShardRange } from '../ws/WebSocketManager';\n\nexport type Awaitable<T> = T | Promise<T>;\n\n/**\n * Yields the numbers in the given range as an array\n * @example\n * range({ start: 3, end: 5 }); // [3, 4, 5]\n */\nexport function range({ start, end }: ShardRange): number[] {\n\treturn Array.from({ length: end - start + 1 }, (_, i) => i + start);\n}\n\n/**\n * Lazily evaluate a callback, storing its result\n */\nexport function lazy<T>(cb: () => T): () => T {\n\tlet defaultValue: T;\n\treturn () => (defaultValue ??= cb());\n}\n"],"names":[],"mappings":";;;;AAAO,SAAS,KAAK,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;AACtC,EAAE,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,GAAG,KAAK,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,CAAC;AACtE,CAAC;AACM,SAAS,IAAI,CAAC,EAAE,EAAE;AACzB,EAAE,IAAI,YAAY,CAAC;AACnB,EAAE,OAAO,MAAM,YAAY,KAAK,YAAY,GAAG,EAAE,EAAE,CAAC,CAAC;AACrD;;;;;"}
1
+ {"version":3,"file":"utils.cjs","sources":["../../src/utils/utils.ts"],"sourcesContent":["import type { ShardRange } from '../ws/WebSocketManager';\n\nexport type Awaitable<T> = T | Promise<T>;\n\n/**\n * Yields the numbers in the given range as an array\n *\n * @example\n * ```ts\n * range({ start: 3, end: 5 }); // [3, 4, 5]\n * ```\n */\nexport function range({ start, end }: ShardRange): number[] {\n\treturn Array.from({ length: end - start + 1 }, (_, i) => i + start);\n}\n\n/**\n * Lazily evaluate a callback, storing its result\n */\nexport function lazy<T>(cb: () => T): () => T {\n\tlet defaultValue: T;\n\treturn () => (defaultValue ??= cb());\n}\n"],"names":[],"mappings":";;;;AAAO,SAAS,KAAK,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;AACtC,EAAE,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,GAAG,KAAK,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,CAAC;AACtE,CAAC;AACM,SAAS,IAAI,CAAC,EAAE,EAAE;AACzB,EAAE,IAAI,YAAY,CAAC;AACnB,EAAE,OAAO,MAAM,YAAY,KAAK,YAAY,GAAG,EAAE,EAAE,CAAC,CAAC;AACrD;;;;;"}
@@ -2,8 +2,11 @@ import type { ShardRange } from '../ws/WebSocketManager';
2
2
  export declare type Awaitable<T> = T | Promise<T>;
3
3
  /**
4
4
  * Yields the numbers in the given range as an array
5
+ *
5
6
  * @example
7
+ * ```ts
6
8
  * range({ start: 3, end: 5 }); // [3, 4, 5]
9
+ * ```
7
10
  */
8
11
  export declare function range({ start, end }: ShardRange): number[];
9
12
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEzD,oBAAY,SAAS,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAE1C;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,UAAU,GAAG,MAAM,EAAE,CAE1D;AAED;;GAEG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,CAG5C"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEzD,oBAAY,SAAS,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAE1C;;;;;;;GAOG;AACH,wBAAgB,KAAK,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,UAAU,GAAG,MAAM,EAAE,CAE1D;AAED;;GAEG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,CAG5C"}
@@ -1 +1 @@
1
- {"version":3,"file":"utils.mjs","sources":["../../src/utils/utils.ts"],"sourcesContent":["import type { ShardRange } from '../ws/WebSocketManager';\n\nexport type Awaitable<T> = T | Promise<T>;\n\n/**\n * Yields the numbers in the given range as an array\n * @example\n * range({ start: 3, end: 5 }); // [3, 4, 5]\n */\nexport function range({ start, end }: ShardRange): number[] {\n\treturn Array.from({ length: end - start + 1 }, (_, i) => i + start);\n}\n\n/**\n * Lazily evaluate a callback, storing its result\n */\nexport function lazy<T>(cb: () => T): () => T {\n\tlet defaultValue: T;\n\treturn () => (defaultValue ??= cb());\n}\n"],"names":[],"mappings":"AAAO,SAAS,KAAK,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;AACtC,EAAE,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,GAAG,KAAK,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,CAAC;AACtE,CAAC;AACM,SAAS,IAAI,CAAC,EAAE,EAAE;AACzB,EAAE,IAAI,YAAY,CAAC;AACnB,EAAE,OAAO,MAAM,YAAY,KAAK,YAAY,GAAG,EAAE,EAAE,CAAC,CAAC;AACrD;;;;"}
1
+ {"version":3,"file":"utils.mjs","sources":["../../src/utils/utils.ts"],"sourcesContent":["import type { ShardRange } from '../ws/WebSocketManager';\n\nexport type Awaitable<T> = T | Promise<T>;\n\n/**\n * Yields the numbers in the given range as an array\n *\n * @example\n * ```ts\n * range({ start: 3, end: 5 }); // [3, 4, 5]\n * ```\n */\nexport function range({ start, end }: ShardRange): number[] {\n\treturn Array.from({ length: end - start + 1 }, (_, i) => i + start);\n}\n\n/**\n * Lazily evaluate a callback, storing its result\n */\nexport function lazy<T>(cb: () => T): () => T {\n\tlet defaultValue: T;\n\treturn () => (defaultValue ??= cb());\n}\n"],"names":[],"mappings":"AAAO,SAAS,KAAK,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;AACtC,EAAE,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,GAAG,KAAK,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,CAAC;AACtE,CAAC;AACM,SAAS,IAAI,CAAC,EAAE,EAAE;AACzB,EAAE,IAAI,YAAY,CAAC;AACnB,EAAE,OAAO,MAAM,YAAY,KAAK,YAAY,GAAG,EAAE,EAAE,CAAC,CAAC;AACrD;;;;"}
@@ -66,6 +66,12 @@ class WebSocketManager extends async_event_emitter.AsyncEventEmitter {
66
66
  }
67
67
  async connect() {
68
68
  const shardCount = await this.getShardCount();
69
+ const data = await this.fetchGatewayInformation();
70
+ if (data.session_start_limit.remaining < shardCount) {
71
+ throw new Error(
72
+ `Not enough sessions remaining to spawn ${shardCount} shards; only ${data.session_start_limit.remaining} remaining; resets at ${new Date(Date.now() + data.session_start_limit.reset_after).toISOString()}`
73
+ );
74
+ }
69
75
  await this.updateShardCount(shardCount);
70
76
  await this.strategy.connect();
71
77
  }
@@ -1 +1 @@
1
- {"version":3,"file":"WebSocketManager.cjs","sources":["../../src/ws/WebSocketManager.ts"],"sourcesContent":["import type { REST } from '@discordjs/rest';\nimport { AsyncEventEmitter } from '@vladfrangu/async_event_emitter';\nimport {\n\tAPIGatewayBotInfo,\n\tGatewayIdentifyProperties,\n\tGatewayPresenceUpdateData,\n\tRESTGetAPIGatewayBotResult,\n\tGatewayIntentBits,\n\tRoutes,\n\tGatewaySendPayload,\n} from 'discord-api-types/v10';\nimport type { WebSocketShardDestroyOptions, WebSocketShardEventsMap } from './WebSocketShard';\nimport type { IShardingStrategy } from '../strategies/sharding/IShardingStrategy';\nimport { SimpleShardingStrategy } from '../strategies/sharding/SimpleShardingStrategy';\nimport { CompressionMethod, DefaultWebSocketManagerOptions, Encoding } from '../utils/constants';\nimport { Awaitable, range } from '../utils/utils';\n\n/**\n * Represents a range of shard ids\n */\nexport interface ShardRange {\n\tstart: number;\n\tend: number;\n}\n\n/**\n * Session information for a given shard, used to resume a session\n */\nexport interface SessionInfo {\n\t/**\n\t * Session id for this shard\n\t */\n\tsessionId: string;\n\t/**\n\t * The sequence number of the last message sent by the shard\n\t */\n\tsequence: number;\n\t/**\n\t * The id of the shard\n\t */\n\tshardId: number;\n\t/**\n\t * The total number of shards at the time of this shard identifying\n\t */\n\tshardCount: number;\n\t/**\n\t * URL to use when resuming\n\t */\n\tresumeURL: string;\n}\n\n/**\n * Required options for the WebSocketManager\n */\nexport interface RequiredWebSocketManagerOptions {\n\t/**\n\t * The token to use for identifying with the gateway\n\t */\n\ttoken: string;\n\t/**\n\t * The intents to request\n\t */\n\tintents: GatewayIntentBits;\n\t/**\n\t * The REST instance to use for fetching gateway information\n\t */\n\trest: REST;\n}\n\n/**\n * Optional additional configuration for the WebSocketManager\n */\nexport interface OptionalWebSocketManagerOptions {\n\t/**\n\t * The total number of shards across all WebsocketManagers you intend to instantiate.\n\t * Use `null` to use Discord's recommended shard count\n\t */\n\tshardCount: number | null;\n\t/**\n\t * The ids of the shards this WebSocketManager should manage.\n\t * Use `null` to simply spawn 0 through `shardCount - 1`\n\t * @example\n\t * const manager = new WebSocketManager({\n\t * shardIds: [1, 3, 7], // spawns shard 1, 3, and 7, nothing else\n\t * });\n\t * @example\n\t * const manager = new WebSocketManager({\n\t * shardIds: {\n\t * start: 3,\n\t * end: 6,\n\t * }, // spawns shards 3, 4, 5, and 6\n\t * });\n\t */\n\tshardIds: number[] | ShardRange | null;\n\t/**\n\t * Value between 50 and 250, total number of members where the gateway will stop sending offline members in the guild member list\n\t */\n\tlargeThreshold: number | null;\n\t/**\n\t * Initial presence data to send to the gateway when identifying\n\t */\n\tinitialPresence: GatewayPresenceUpdateData | null;\n\t/**\n\t * Properties to send to the gateway when identifying\n\t */\n\tidentifyProperties: GatewayIdentifyProperties;\n\t/**\n\t * The gateway version to use\n\t * @default '10'\n\t */\n\tversion: string;\n\t/**\n\t * The encoding to use\n\t * @default 'json'\n\t */\n\tencoding: Encoding;\n\t/**\n\t * The compression method to use\n\t * @default null (no compression)\n\t */\n\tcompression: CompressionMethod | null;\n\t/**\n\t * Function used to retrieve session information (and attempt to resume) for a given shard\n\t * @example\n\t * const manager = new WebSocketManager({\n\t * async retrieveSessionInfo(shardId): Awaitable<SessionInfo | null> {\n\t * // Fetch this info from redis or similar\n\t * return { sessionId: string, sequence: number };\n\t * // Return null if no information is found\n\t * },\n\t * });\n\t */\n\tretrieveSessionInfo: (shardId: number) => Awaitable<SessionInfo | null>;\n\t/**\n\t * Function used to store session information for a given shard\n\t */\n\tupdateSessionInfo: (shardId: number, sessionInfo: SessionInfo | null) => Awaitable<void>;\n\t/**\n\t * How long to wait for a shard to connect before giving up\n\t */\n\thandshakeTimeout: number | null;\n\t/**\n\t * How long to wait for a shard's HELLO packet before giving up\n\t */\n\thelloTimeout: number | null;\n\t/**\n\t * How long to wait for a shard's READY packet before giving up\n\t */\n\treadyTimeout: number | null;\n}\n\nexport type WebSocketManagerOptions = RequiredWebSocketManagerOptions & OptionalWebSocketManagerOptions;\n\nexport type ManagerShardEventsMap = {\n\t[K in keyof WebSocketShardEventsMap]: [\n\t\tWebSocketShardEventsMap[K] extends [] ? { shardId: number } : WebSocketShardEventsMap[K][0] & { shardId: number },\n\t];\n};\n\nexport class WebSocketManager extends AsyncEventEmitter<ManagerShardEventsMap> {\n\t/**\n\t * The options being used by this manager\n\t */\n\tpublic readonly options: WebSocketManagerOptions;\n\n\t/**\n\t * Internal cache for a GET /gateway/bot result\n\t */\n\tprivate gatewayInformation: {\n\t\tdata: APIGatewayBotInfo;\n\t\texpiresAt: number;\n\t} | null = null;\n\n\t/**\n\t * Internal cache for the shard ids\n\t */\n\tprivate shardIds: number[] | null = null;\n\n\t/**\n\t * Strategy used to manage shards\n\t * @default SimpleManagerToShardStrategy\n\t */\n\tprivate strategy: IShardingStrategy = new SimpleShardingStrategy(this);\n\n\tpublic constructor(options: RequiredWebSocketManagerOptions & Partial<OptionalWebSocketManagerOptions>) {\n\t\tsuper();\n\t\tthis.options = { ...DefaultWebSocketManagerOptions, ...options };\n\t}\n\n\tpublic setStrategy(strategy: IShardingStrategy) {\n\t\tthis.strategy = strategy;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Fetches the gateway information from Discord - or returns it from cache if available\n\t * @param force Whether to ignore the cache and force a fresh fetch\n\t */\n\tpublic async fetchGatewayInformation(force = false) {\n\t\tif (this.gatewayInformation) {\n\t\t\tif (this.gatewayInformation.expiresAt <= Date.now()) {\n\t\t\t\tthis.gatewayInformation = null;\n\t\t\t} else if (!force) {\n\t\t\t\treturn this.gatewayInformation.data;\n\t\t\t}\n\t\t}\n\n\t\tconst data = (await this.options.rest.get(Routes.gatewayBot())) as RESTGetAPIGatewayBotResult;\n\n\t\tthis.gatewayInformation = { data, expiresAt: Date.now() + data.session_start_limit.reset_after };\n\t\treturn this.gatewayInformation.data;\n\t}\n\n\t/**\n\t * Updates your total shard count on-the-fly, spawning shards as needed\n\t * @param shardCount The new shard count to use\n\t */\n\tpublic async updateShardCount(shardCount: number | null) {\n\t\tawait this.strategy.destroy({ reason: 'User is adjusting their shards' });\n\t\tthis.options.shardCount = shardCount;\n\n\t\tconst shardIds = await this.getShardIds(true);\n\t\tawait this.strategy.spawn(shardIds);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Yields the total number of shards across for your bot, accounting for Discord recommendations\n\t */\n\tpublic async getShardCount(): Promise<number> {\n\t\tif (this.options.shardCount) {\n\t\t\treturn this.options.shardCount;\n\t\t}\n\n\t\tconst shardIds = await this.getShardIds();\n\t\treturn Math.max(...shardIds) + 1;\n\t}\n\n\t/**\n\t * Yields the ids of the shards this manager should manage\n\t */\n\tpublic async getShardIds(force = false): Promise<number[]> {\n\t\tif (this.shardIds && !force) {\n\t\t\treturn this.shardIds;\n\t\t}\n\n\t\tlet shardIds: number[];\n\t\tif (this.options.shardIds) {\n\t\t\tif (Array.isArray(this.options.shardIds)) {\n\t\t\t\tshardIds = this.options.shardIds;\n\t\t\t} else {\n\t\t\t\tshardIds = range(this.options.shardIds);\n\t\t\t}\n\t\t} else {\n\t\t\tconst data = await this.fetchGatewayInformation();\n\t\t\tshardIds = range({ start: 0, end: (this.options.shardCount ?? data.shards) - 1 });\n\t\t}\n\n\t\tthis.shardIds = shardIds;\n\t\treturn shardIds;\n\t}\n\n\tpublic async connect() {\n\t\tconst shardCount = await this.getShardCount();\n\t\t// First, make sure all our shards are spawned\n\t\tawait this.updateShardCount(shardCount);\n\t\tawait this.strategy.connect();\n\t}\n\n\tpublic destroy(options?: Omit<WebSocketShardDestroyOptions, 'recover'>) {\n\t\treturn this.strategy.destroy(options);\n\t}\n\n\tpublic send(shardId: number, payload: GatewaySendPayload) {\n\t\treturn this.strategy.send(shardId, payload);\n\t}\n}\n"],"names":["AsyncEventEmitter","SimpleShardingStrategy","DefaultWebSocketManagerOptions","Routes","range"],"mappings":";;;;;;;;;;AAOO,MAAM,gBAAgB,SAASA,qCAAiB,CAAC;AACxD,EAAE,WAAW,CAAC,OAAO,EAAE;AACvB,IAAI,KAAK,EAAE,CAAC;AACZ,IAAI,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC;AACnC,IAAI,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;AACzB,IAAI,IAAI,CAAC,QAAQ,GAAG,IAAIC,6CAAsB,CAAC,IAAI,C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G,QAAQ,CAAC;AAC7B,IAAI,OAAO,QAAQ,CAAC;AACpB,GAAG;AACH,EAAE,MAAM,OAAO,GAAG;AAClB,IAAI,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC;AAClD,IAAI,MAAM,IAAI,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC;AAC5C,IAAI,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;AAClC,GAAG;AACH,EAAE,OAAO,CAAC,OAAO,EAAE;AACnB,IAAI,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;AAC1C,GAAG;AACH,EAAE,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE;AACzB,IAAI,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAChD,GAAG;AACH;;;;"}
1
+ {"version":3,"file":"WebSocketManager.cjs","sources":["../../src/ws/WebSocketManager.ts"],"sourcesContent":["import type { REST } from '@discordjs/rest';\nimport { AsyncEventEmitter } from '@vladfrangu/async_event_emitter';\nimport {\n\tAPIGatewayBotInfo,\n\tGatewayIdentifyProperties,\n\tGatewayPresenceUpdateData,\n\tRESTGetAPIGatewayBotResult,\n\tGatewayIntentBits,\n\tRoutes,\n\tGatewaySendPayload,\n} from 'discord-api-types/v10';\nimport type { WebSocketShardDestroyOptions, WebSocketShardEventsMap } from './WebSocketShard';\nimport type { IShardingStrategy } from '../strategies/sharding/IShardingStrategy';\nimport { SimpleShardingStrategy } from '../strategies/sharding/SimpleShardingStrategy';\nimport { CompressionMethod, DefaultWebSocketManagerOptions, Encoding } from '../utils/constants';\nimport { Awaitable, range } from '../utils/utils';\n\n/**\n * Represents a range of shard ids\n */\nexport interface ShardRange {\n\tstart: number;\n\tend: number;\n}\n\n/**\n * Session information for a given shard, used to resume a session\n */\nexport interface SessionInfo {\n\t/**\n\t * Session id for this shard\n\t */\n\tsessionId: string;\n\t/**\n\t * The sequence number of the last message sent by the shard\n\t */\n\tsequence: number;\n\t/**\n\t * The id of the shard\n\t */\n\tshardId: number;\n\t/**\n\t * The total number of shards at the time of this shard identifying\n\t */\n\tshardCount: number;\n\t/**\n\t * URL to use when resuming\n\t */\n\tresumeURL: string;\n}\n\n/**\n * Required options for the WebSocketManager\n */\nexport interface RequiredWebSocketManagerOptions {\n\t/**\n\t * The token to use for identifying with the gateway\n\t */\n\ttoken: string;\n\t/**\n\t * The intents to request\n\t */\n\tintents: GatewayIntentBits;\n\t/**\n\t * The REST instance to use for fetching gateway information\n\t */\n\trest: REST;\n}\n\n/**\n * Optional additional configuration for the WebSocketManager\n */\nexport interface OptionalWebSocketManagerOptions {\n\t/**\n\t * The total number of shards across all WebsocketManagers you intend to instantiate.\n\t * Use `null` to use Discord's recommended shard count\n\t */\n\tshardCount: number | null;\n\t/**\n\t * The ids of the shards this WebSocketManager should manage.\n\t * Use `null` to simply spawn 0 through `shardCount - 1`\n\t *\n\t * @example\n\t * ```ts\n\t * const manager = new WebSocketManager({\n\t * shardIds: [1, 3, 7], // spawns shard 1, 3, and 7, nothing else\n\t * });\n\t * ```\n\t *\n\t * @example\n\t * ```ts\n\t * const manager = new WebSocketManager({\n\t * shardIds: {\n\t * start: 3,\n\t * end: 6,\n\t * }, // spawns shards 3, 4, 5, and 6\n\t * });\n\t * ```\n\t */\n\tshardIds: number[] | ShardRange | null;\n\t/**\n\t * Value between 50 and 250, total number of members where the gateway will stop sending offline members in the guild member list\n\t */\n\tlargeThreshold: number | null;\n\t/**\n\t * Initial presence data to send to the gateway when identifying\n\t */\n\tinitialPresence: GatewayPresenceUpdateData | null;\n\t/**\n\t * Properties to send to the gateway when identifying\n\t */\n\tidentifyProperties: GatewayIdentifyProperties;\n\t/**\n\t * The gateway version to use\n\t * @default '10'\n\t */\n\tversion: string;\n\t/**\n\t * The encoding to use\n\t * @default 'json'\n\t */\n\tencoding: Encoding;\n\t/**\n\t * The compression method to use\n\t * @default null (no compression)\n\t */\n\tcompression: CompressionMethod | null;\n\t/**\n\t * Function used to retrieve session information (and attempt to resume) for a given shard\n\t *\n\t * @example\n\t * ```ts\n\t * const manager = new WebSocketManager({\n\t * async retrieveSessionInfo(shardId): Awaitable<SessionInfo | null> {\n\t * // Fetch this info from redis or similar\n\t * return { sessionId: string, sequence: number };\n\t * // Return null if no information is found\n\t * },\n\t * });\n\t * ```\n\t */\n\tretrieveSessionInfo: (shardId: number) => Awaitable<SessionInfo | null>;\n\t/**\n\t * Function used to store session information for a given shard\n\t */\n\tupdateSessionInfo: (shardId: number, sessionInfo: SessionInfo | null) => Awaitable<void>;\n\t/**\n\t * How long to wait for a shard to connect before giving up\n\t */\n\thandshakeTimeout: number | null;\n\t/**\n\t * How long to wait for a shard's HELLO packet before giving up\n\t */\n\thelloTimeout: number | null;\n\t/**\n\t * How long to wait for a shard's READY packet before giving up\n\t */\n\treadyTimeout: number | null;\n}\n\nexport type WebSocketManagerOptions = RequiredWebSocketManagerOptions & OptionalWebSocketManagerOptions;\n\nexport type ManagerShardEventsMap = {\n\t[K in keyof WebSocketShardEventsMap]: [\n\t\tWebSocketShardEventsMap[K] extends [] ? { shardId: number } : WebSocketShardEventsMap[K][0] & { shardId: number },\n\t];\n};\n\nexport class WebSocketManager extends AsyncEventEmitter<ManagerShardEventsMap> {\n\t/**\n\t * The options being used by this manager\n\t */\n\tpublic readonly options: WebSocketManagerOptions;\n\n\t/**\n\t * Internal cache for a GET /gateway/bot result\n\t */\n\tprivate gatewayInformation: {\n\t\tdata: APIGatewayBotInfo;\n\t\texpiresAt: number;\n\t} | null = null;\n\n\t/**\n\t * Internal cache for the shard ids\n\t */\n\tprivate shardIds: number[] | null = null;\n\n\t/**\n\t * Strategy used to manage shards\n\t * @default SimpleManagerToShardStrategy\n\t */\n\tprivate strategy: IShardingStrategy = new SimpleShardingStrategy(this);\n\n\tpublic constructor(options: RequiredWebSocketManagerOptions & Partial<OptionalWebSocketManagerOptions>) {\n\t\tsuper();\n\t\tthis.options = { ...DefaultWebSocketManagerOptions, ...options };\n\t}\n\n\tpublic setStrategy(strategy: IShardingStrategy) {\n\t\tthis.strategy = strategy;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Fetches the gateway information from Discord - or returns it from cache if available\n\t * @param force Whether to ignore the cache and force a fresh fetch\n\t */\n\tpublic async fetchGatewayInformation(force = false) {\n\t\tif (this.gatewayInformation) {\n\t\t\tif (this.gatewayInformation.expiresAt <= Date.now()) {\n\t\t\t\tthis.gatewayInformation = null;\n\t\t\t} else if (!force) {\n\t\t\t\treturn this.gatewayInformation.data;\n\t\t\t}\n\t\t}\n\n\t\tconst data = (await this.options.rest.get(Routes.gatewayBot())) as RESTGetAPIGatewayBotResult;\n\n\t\tthis.gatewayInformation = { data, expiresAt: Date.now() + data.session_start_limit.reset_after };\n\t\treturn this.gatewayInformation.data;\n\t}\n\n\t/**\n\t * Updates your total shard count on-the-fly, spawning shards as needed\n\t * @param shardCount The new shard count to use\n\t */\n\tpublic async updateShardCount(shardCount: number | null) {\n\t\tawait this.strategy.destroy({ reason: 'User is adjusting their shards' });\n\t\tthis.options.shardCount = shardCount;\n\n\t\tconst shardIds = await this.getShardIds(true);\n\t\tawait this.strategy.spawn(shardIds);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Yields the total number of shards across for your bot, accounting for Discord recommendations\n\t */\n\tpublic async getShardCount(): Promise<number> {\n\t\tif (this.options.shardCount) {\n\t\t\treturn this.options.shardCount;\n\t\t}\n\n\t\tconst shardIds = await this.getShardIds();\n\t\treturn Math.max(...shardIds) + 1;\n\t}\n\n\t/**\n\t * Yields the ids of the shards this manager should manage\n\t */\n\tpublic async getShardIds(force = false): Promise<number[]> {\n\t\tif (this.shardIds && !force) {\n\t\t\treturn this.shardIds;\n\t\t}\n\n\t\tlet shardIds: number[];\n\t\tif (this.options.shardIds) {\n\t\t\tif (Array.isArray(this.options.shardIds)) {\n\t\t\t\tshardIds = this.options.shardIds;\n\t\t\t} else {\n\t\t\t\tshardIds = range(this.options.shardIds);\n\t\t\t}\n\t\t} else {\n\t\t\tconst data = await this.fetchGatewayInformation();\n\t\t\tshardIds = range({ start: 0, end: (this.options.shardCount ?? data.shards) - 1 });\n\t\t}\n\n\t\tthis.shardIds = shardIds;\n\t\treturn shardIds;\n\t}\n\n\tpublic async connect() {\n\t\tconst shardCount = await this.getShardCount();\n\n\t\tconst data = await this.fetchGatewayInformation();\n\t\tif (data.session_start_limit.remaining < shardCount) {\n\t\t\tthrow new Error(\n\t\t\t\t`Not enough sessions remaining to spawn ${shardCount} shards; only ${\n\t\t\t\t\tdata.session_start_limit.remaining\n\t\t\t\t} remaining; resets at ${new Date(Date.now() + data.session_start_limit.reset_after).toISOString()}`,\n\t\t\t);\n\t\t}\n\n\t\t// First, make sure all our shards are spawned\n\t\tawait this.updateShardCount(shardCount);\n\t\tawait this.strategy.connect();\n\t}\n\n\tpublic destroy(options?: Omit<WebSocketShardDestroyOptions, 'recover'>) {\n\t\treturn this.strategy.destroy(options);\n\t}\n\n\tpublic send(shardId: number, payload: GatewaySendPayload) {\n\t\treturn this.strategy.send(shardId, payload);\n\t}\n}\n"],"names":["AsyncEventEmitter","SimpleShardingStrategy","DefaultWebSocketManagerOptions","Routes","range"],"mappings":";;;;;;;;;;AAOO,MAAM,gBAAgB,SAASA,qCAAiB,CAAC;AACxD,EAAE,WAAW,CAAC,OAAO,EAAE;AACvB,IAAI,KAAK,EAAE,CAAC;AACZ,IAAI,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC;AACnC,IAAI,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;AACzB,IAAI,IAAI,CAAC,QAAQ,GAAG,IAAIC,6CAAsB,CAAC,IAAI,CAAC,CAAC;AACrD,IAAI,IAAI,CAAC,OAAO,GAAG,EAAE,GAAGC,wCAA8B,EAAE,GAAG,OAAO,EAAE,CAAC;AACrE,GAAG;AACH,EAAE,WAAW,CAAC,QAAQ,EAAE;AACxB,IAAI,IAA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AAI,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,uBAAuB,EAAE,CAAC;AACtD,IAAI,IAAI,IAAI,CAAC,mBAAmB,CAAC,SAAS,GAAG,UAAU,EAAE;AACzD,MAAM,MAAM,IAAI,KAAK;AACrB,QAAQ,CAAC,uCAAuC,EAAE,UAAU,CAAC,cAAc,EAAE,IAAI,CAAC,mBAAmB,CAAC,SAAS,CAAC,sBAAsB,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,mBAAmB,CAAC,WAAW,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;AACnN,OAAO,CAAC;AACR,KAAK;AACL,IAAI,MAAM,IAAI,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC;AAC5C,IAAI,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;AAClC,GAAG;AACH,EAAE,OAAO,CAAC,OAAO,EAAE;AACnB,IAAI,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;AAC1C,GAAG;AACH,EAAE,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE;AACzB,IAAI,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAChD,GAAG;AACH;;;;"}
@@ -66,17 +66,23 @@ export interface OptionalWebSocketManagerOptions {
66
66
  /**
67
67
  * The ids of the shards this WebSocketManager should manage.
68
68
  * Use `null` to simply spawn 0 through `shardCount - 1`
69
+ *
69
70
  * @example
71
+ * ```ts
70
72
  * const manager = new WebSocketManager({
71
73
  * shardIds: [1, 3, 7], // spawns shard 1, 3, and 7, nothing else
72
74
  * });
75
+ * ```
76
+ *
73
77
  * @example
78
+ * ```ts
74
79
  * const manager = new WebSocketManager({
75
80
  * shardIds: {
76
81
  * start: 3,
77
82
  * end: 6,
78
83
  * }, // spawns shards 3, 4, 5, and 6
79
84
  * });
85
+ * ```
80
86
  */
81
87
  shardIds: number[] | ShardRange | null;
82
88
  /**
@@ -108,7 +114,9 @@ export interface OptionalWebSocketManagerOptions {
108
114
  compression: CompressionMethod | null;
109
115
  /**
110
116
  * Function used to retrieve session information (and attempt to resume) for a given shard
117
+ *
111
118
  * @example
119
+ * ```ts
112
120
  * const manager = new WebSocketManager({
113
121
  * async retrieveSessionInfo(shardId): Awaitable<SessionInfo | null> {
114
122
  * // Fetch this info from redis or similar
@@ -116,6 +124,7 @@ export interface OptionalWebSocketManagerOptions {
116
124
  * // Return null if no information is found
117
125
  * },
118
126
  * });
127
+ * ```
119
128
  */
120
129
  retrieveSessionInfo: (shardId: number) => Awaitable<SessionInfo | null>;
121
130
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"WebSocketManager.d.ts","sourceRoot":"","sources":["../../src/ws/WebSocketManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EACN,iBAAiB,EACjB,yBAAyB,EACzB,yBAAyB,EAEzB,iBAAiB,EAEjB,kBAAkB,EAClB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,4BAA4B,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAC9F,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAElF,OAAO,EAAE,iBAAiB,EAAkC,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACjG,OAAO,EAAE,SAAS,EAAS,MAAM,gBAAgB,CAAC;AAElD;;GAEG;AACH,MAAM,WAAW,UAAU;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACZ;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC3B;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;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F,WAAW,CAAC,QAAQ,EAAE,iBAAiB;IAK9C;;;OAGG;IACU,uBAAuB,CAAC,KAAK,UAAQ;IAelD;;;OAGG;IACU,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAUvD;;OAEG;IACU,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAS7C;;OAEG;IACU,WAAW,CAAC,KAAK,UAAQ,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAqB7C,OAAO;IAiBb,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,4BAA4B,EAAE,SAAS,CAAC;IAI/D,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,kBAAkB;CAGxD"}
@@ -62,6 +62,12 @@ class WebSocketManager extends AsyncEventEmitter {
62
62
  }
63
63
  async connect() {
64
64
  const shardCount = await this.getShardCount();
65
+ const data = await this.fetchGatewayInformation();
66
+ if (data.session_start_limit.remaining < shardCount) {
67
+ throw new Error(
68
+ `Not enough sessions remaining to spawn ${shardCount} shards; only ${data.session_start_limit.remaining} remaining; resets at ${new Date(Date.now() + data.session_start_limit.reset_after).toISOString()}`
69
+ );
70
+ }
65
71
  await this.updateShardCount(shardCount);
66
72
  await this.strategy.connect();
67
73
  }
@@ -1 +1 @@
1
- {"version":3,"file":"WebSocketManager.mjs","sources":["../../src/ws/WebSocketManager.ts"],"sourcesContent":["import type { REST } from '@discordjs/rest';\nimport { AsyncEventEmitter } from '@vladfrangu/async_event_emitter';\nimport {\n\tAPIGatewayBotInfo,\n\tGatewayIdentifyProperties,\n\tGatewayPresenceUpdateData,\n\tRESTGetAPIGatewayBotResult,\n\tGatewayIntentBits,\n\tRoutes,\n\tGatewaySendPayload,\n} from 'discord-api-types/v10';\nimport type { WebSocketShardDestroyOptions, WebSocketShardEventsMap } from './WebSocketShard';\nimport type { IShardingStrategy } from '../strategies/sharding/IShardingStrategy';\nimport { SimpleShardingStrategy } from '../strategies/sharding/SimpleShardingStrategy';\nimport { CompressionMethod, DefaultWebSocketManagerOptions, Encoding } from '../utils/constants';\nimport { Awaitable, range } from '../utils/utils';\n\n/**\n * Represents a range of shard ids\n */\nexport interface ShardRange {\n\tstart: number;\n\tend: number;\n}\n\n/**\n * Session information for a given shard, used to resume a session\n */\nexport interface SessionInfo {\n\t/**\n\t * Session id for this shard\n\t */\n\tsessionId: string;\n\t/**\n\t * The sequence number of the last message sent by the shard\n\t */\n\tsequence: number;\n\t/**\n\t * The id of the shard\n\t */\n\tshardId: number;\n\t/**\n\t * The total number of shards at the time of this shard identifying\n\t */\n\tshardCount: number;\n\t/**\n\t * URL to use when resuming\n\t */\n\tresumeURL: string;\n}\n\n/**\n * Required options for the WebSocketManager\n */\nexport interface RequiredWebSocketManagerOptions {\n\t/**\n\t * The token to use for identifying with the gateway\n\t */\n\ttoken: string;\n\t/**\n\t * The intents to request\n\t */\n\tintents: GatewayIntentBits;\n\t/**\n\t * The REST instance to use for fetching gateway information\n\t */\n\trest: REST;\n}\n\n/**\n * Optional additional configuration for the WebSocketManager\n */\nexport interface OptionalWebSocketManagerOptions {\n\t/**\n\t * The total number of shards across all WebsocketManagers you intend to instantiate.\n\t * Use `null` to use Discord's recommended shard count\n\t */\n\tshardCount: number | null;\n\t/**\n\t * The ids of the shards this WebSocketManager should manage.\n\t * Use `null` to simply spawn 0 through `shardCount - 1`\n\t * @example\n\t * const manager = new WebSocketManager({\n\t * shardIds: [1, 3, 7], // spawns shard 1, 3, and 7, nothing else\n\t * });\n\t * @example\n\t * const manager = new WebSocketManager({\n\t * shardIds: {\n\t * start: 3,\n\t * end: 6,\n\t * }, // spawns shards 3, 4, 5, and 6\n\t * });\n\t */\n\tshardIds: number[] | ShardRange | null;\n\t/**\n\t * Value between 50 and 250, total number of members where the gateway will stop sending offline members in the guild member list\n\t */\n\tlargeThreshold: number | null;\n\t/**\n\t * Initial presence data to send to the gateway when identifying\n\t */\n\tinitialPresence: GatewayPresenceUpdateData | null;\n\t/**\n\t * Properties to send to the gateway when identifying\n\t */\n\tidentifyProperties: GatewayIdentifyProperties;\n\t/**\n\t * The gateway version to use\n\t * @default '10'\n\t */\n\tversion: string;\n\t/**\n\t * The encoding to use\n\t * @default 'json'\n\t */\n\tencoding: Encoding;\n\t/**\n\t * The compression method to use\n\t * @default null (no compression)\n\t */\n\tcompression: CompressionMethod | null;\n\t/**\n\t * Function used to retrieve session information (and attempt to resume) for a given shard\n\t * @example\n\t * const manager = new WebSocketManager({\n\t * async retrieveSessionInfo(shardId): Awaitable<SessionInfo | null> {\n\t * // Fetch this info from redis or similar\n\t * return { sessionId: string, sequence: number };\n\t * // Return null if no information is found\n\t * },\n\t * });\n\t */\n\tretrieveSessionInfo: (shardId: number) => Awaitable<SessionInfo | null>;\n\t/**\n\t * Function used to store session information for a given shard\n\t */\n\tupdateSessionInfo: (shardId: number, sessionInfo: SessionInfo | null) => Awaitable<void>;\n\t/**\n\t * How long to wait for a shard to connect before giving up\n\t */\n\thandshakeTimeout: number | null;\n\t/**\n\t * How long to wait for a shard's HELLO packet before giving up\n\t */\n\thelloTimeout: number | null;\n\t/**\n\t * How long to wait for a shard's READY packet before giving up\n\t */\n\treadyTimeout: number | null;\n}\n\nexport type WebSocketManagerOptions = RequiredWebSocketManagerOptions & OptionalWebSocketManagerOptions;\n\nexport type ManagerShardEventsMap = {\n\t[K in keyof WebSocketShardEventsMap]: [\n\t\tWebSocketShardEventsMap[K] extends [] ? { shardId: number } : WebSocketShardEventsMap[K][0] & { shardId: number },\n\t];\n};\n\nexport class WebSocketManager extends AsyncEventEmitter<ManagerShardEventsMap> {\n\t/**\n\t * The options being used by this manager\n\t */\n\tpublic readonly options: WebSocketManagerOptions;\n\n\t/**\n\t * Internal cache for a GET /gateway/bot result\n\t */\n\tprivate gatewayInformation: {\n\t\tdata: APIGatewayBotInfo;\n\t\texpiresAt: number;\n\t} | null = null;\n\n\t/**\n\t * Internal cache for the shard ids\n\t */\n\tprivate shardIds: number[] | null = null;\n\n\t/**\n\t * Strategy used to manage shards\n\t * @default SimpleManagerToShardStrategy\n\t */\n\tprivate strategy: IShardingStrategy = new SimpleShardingStrategy(this);\n\n\tpublic constructor(options: RequiredWebSocketManagerOptions & Partial<OptionalWebSocketManagerOptions>) {\n\t\tsuper();\n\t\tthis.options = { ...DefaultWebSocketManagerOptions, ...options };\n\t}\n\n\tpublic setStrategy(strategy: IShardingStrategy) {\n\t\tthis.strategy = strategy;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Fetches the gateway information from Discord - or returns it from cache if available\n\t * @param force Whether to ignore the cache and force a fresh fetch\n\t */\n\tpublic async fetchGatewayInformation(force = false) {\n\t\tif (this.gatewayInformation) {\n\t\t\tif (this.gatewayInformation.expiresAt <= Date.now()) {\n\t\t\t\tthis.gatewayInformation = null;\n\t\t\t} else if (!force) {\n\t\t\t\treturn this.gatewayInformation.data;\n\t\t\t}\n\t\t}\n\n\t\tconst data = (await this.options.rest.get(Routes.gatewayBot())) as RESTGetAPIGatewayBotResult;\n\n\t\tthis.gatewayInformation = { data, expiresAt: Date.now() + data.session_start_limit.reset_after };\n\t\treturn this.gatewayInformation.data;\n\t}\n\n\t/**\n\t * Updates your total shard count on-the-fly, spawning shards as needed\n\t * @param shardCount The new shard count to use\n\t */\n\tpublic async updateShardCount(shardCount: number | null) {\n\t\tawait this.strategy.destroy({ reason: 'User is adjusting their shards' });\n\t\tthis.options.shardCount = shardCount;\n\n\t\tconst shardIds = await this.getShardIds(true);\n\t\tawait this.strategy.spawn(shardIds);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Yields the total number of shards across for your bot, accounting for Discord recommendations\n\t */\n\tpublic async getShardCount(): Promise<number> {\n\t\tif (this.options.shardCount) {\n\t\t\treturn this.options.shardCount;\n\t\t}\n\n\t\tconst shardIds = await this.getShardIds();\n\t\treturn Math.max(...shardIds) + 1;\n\t}\n\n\t/**\n\t * Yields the ids of the shards this manager should manage\n\t */\n\tpublic async getShardIds(force = false): Promise<number[]> {\n\t\tif (this.shardIds && !force) {\n\t\t\treturn this.shardIds;\n\t\t}\n\n\t\tlet shardIds: number[];\n\t\tif (this.options.shardIds) {\n\t\t\tif (Array.isArray(this.options.shardIds)) {\n\t\t\t\tshardIds = this.options.shardIds;\n\t\t\t} else {\n\t\t\t\tshardIds = range(this.options.shardIds);\n\t\t\t}\n\t\t} else {\n\t\t\tconst data = await this.fetchGatewayInformation();\n\t\t\tshardIds = range({ start: 0, end: (this.options.shardCount ?? data.shards) - 1 });\n\t\t}\n\n\t\tthis.shardIds = shardIds;\n\t\treturn shardIds;\n\t}\n\n\tpublic async connect() {\n\t\tconst shardCount = await this.getShardCount();\n\t\t// First, make sure all our shards are spawned\n\t\tawait this.updateShardCount(shardCount);\n\t\tawait this.strategy.connect();\n\t}\n\n\tpublic destroy(options?: Omit<WebSocketShardDestroyOptions, 'recover'>) {\n\t\treturn this.strategy.destroy(options);\n\t}\n\n\tpublic send(shardId: number, payload: GatewaySendPayload) {\n\t\treturn this.strategy.send(shardId, payload);\n\t}\n}\n"],"names":[],"mappings":";;;;;;AAOO,MAAM,gBAAgB,SAAS,iBAAiB,CAAC;AACxD,EAAE,WAAW,CAAC,OAAO,EAAE;AACvB,IAAI,KAAK,EAAE,CAAC;AACZ,IAAI,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC;AACnC,IAAI,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;AACzB,IAAI,IAAI,CAAC,QAAQ,GAAG,IAAI,sBAAsB,CAAC,IAAI,CAAC,CAAC;AACrD,IAAI,IAAI,CAAC,OAAO,GAAG,EAAE,GAAG,8BAA8B,EAAE,GAAG,OAAO,EAAE,CAAC;AACrE,GAAG;AACH,EAAE,WAAW,CAAC,QAAQ,EAAE;AACxB,IAAI,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;AAC7B,IAAI,OAAO,IAAI,CAAC;AAChB,GAAG;AACH,EAAE,MAAM,uBAAuB,CAAC,KAAK,GAAG,KAAK,EAAE;AAC/C,IAAI,IAAI,I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O,EAAE;AACnB,IAAI,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;AAC1C,GAAG;AACH,EAAE,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE;AACzB,IAAI,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAChD,GAAG;AACH;;;;"}
1
+ {"version":3,"file":"WebSocketManager.mjs","sources":["../../src/ws/WebSocketManager.ts"],"sourcesContent":["import type { REST } from '@discordjs/rest';\nimport { AsyncEventEmitter } from '@vladfrangu/async_event_emitter';\nimport {\n\tAPIGatewayBotInfo,\n\tGatewayIdentifyProperties,\n\tGatewayPresenceUpdateData,\n\tRESTGetAPIGatewayBotResult,\n\tGatewayIntentBits,\n\tRoutes,\n\tGatewaySendPayload,\n} from 'discord-api-types/v10';\nimport type { WebSocketShardDestroyOptions, WebSocketShardEventsMap } from './WebSocketShard';\nimport type { IShardingStrategy } from '../strategies/sharding/IShardingStrategy';\nimport { SimpleShardingStrategy } from '../strategies/sharding/SimpleShardingStrategy';\nimport { CompressionMethod, DefaultWebSocketManagerOptions, Encoding } from '../utils/constants';\nimport { Awaitable, range } from '../utils/utils';\n\n/**\n * Represents a range of shard ids\n */\nexport interface ShardRange {\n\tstart: number;\n\tend: number;\n}\n\n/**\n * Session information for a given shard, used to resume a session\n */\nexport interface SessionInfo {\n\t/**\n\t * Session id for this shard\n\t */\n\tsessionId: string;\n\t/**\n\t * The sequence number of the last message sent by the shard\n\t */\n\tsequence: number;\n\t/**\n\t * The id of the shard\n\t */\n\tshardId: number;\n\t/**\n\t * The total number of shards at the time of this shard identifying\n\t */\n\tshardCount: number;\n\t/**\n\t * URL to use when resuming\n\t */\n\tresumeURL: string;\n}\n\n/**\n * Required options for the WebSocketManager\n */\nexport interface RequiredWebSocketManagerOptions {\n\t/**\n\t * The token to use for identifying with the gateway\n\t */\n\ttoken: string;\n\t/**\n\t * The intents to request\n\t */\n\tintents: GatewayIntentBits;\n\t/**\n\t * The REST instance to use for fetching gateway information\n\t */\n\trest: REST;\n}\n\n/**\n * Optional additional configuration for the WebSocketManager\n */\nexport interface OptionalWebSocketManagerOptions {\n\t/**\n\t * The total number of shards across all WebsocketManagers you intend to instantiate.\n\t * Use `null` to use Discord's recommended shard count\n\t */\n\tshardCount: number | null;\n\t/**\n\t * The ids of the shards this WebSocketManager should manage.\n\t * Use `null` to simply spawn 0 through `shardCount - 1`\n\t *\n\t * @example\n\t * ```ts\n\t * const manager = new WebSocketManager({\n\t * shardIds: [1, 3, 7], // spawns shard 1, 3, and 7, nothing else\n\t * });\n\t * ```\n\t *\n\t * @example\n\t * ```ts\n\t * const manager = new WebSocketManager({\n\t * shardIds: {\n\t * start: 3,\n\t * end: 6,\n\t * }, // spawns shards 3, 4, 5, and 6\n\t * });\n\t * ```\n\t */\n\tshardIds: number[] | ShardRange | null;\n\t/**\n\t * Value between 50 and 250, total number of members where the gateway will stop sending offline members in the guild member list\n\t */\n\tlargeThreshold: number | null;\n\t/**\n\t * Initial presence data to send to the gateway when identifying\n\t */\n\tinitialPresence: GatewayPresenceUpdateData | null;\n\t/**\n\t * Properties to send to the gateway when identifying\n\t */\n\tidentifyProperties: GatewayIdentifyProperties;\n\t/**\n\t * The gateway version to use\n\t * @default '10'\n\t */\n\tversion: string;\n\t/**\n\t * The encoding to use\n\t * @default 'json'\n\t */\n\tencoding: Encoding;\n\t/**\n\t * The compression method to use\n\t * @default null (no compression)\n\t */\n\tcompression: CompressionMethod | null;\n\t/**\n\t * Function used to retrieve session information (and attempt to resume) for a given shard\n\t *\n\t * @example\n\t * ```ts\n\t * const manager = new WebSocketManager({\n\t * async retrieveSessionInfo(shardId): Awaitable<SessionInfo | null> {\n\t * // Fetch this info from redis or similar\n\t * return { sessionId: string, sequence: number };\n\t * // Return null if no information is found\n\t * },\n\t * });\n\t * ```\n\t */\n\tretrieveSessionInfo: (shardId: number) => Awaitable<SessionInfo | null>;\n\t/**\n\t * Function used to store session information for a given shard\n\t */\n\tupdateSessionInfo: (shardId: number, sessionInfo: SessionInfo | null) => Awaitable<void>;\n\t/**\n\t * How long to wait for a shard to connect before giving up\n\t */\n\thandshakeTimeout: number | null;\n\t/**\n\t * How long to wait for a shard's HELLO packet before giving up\n\t */\n\thelloTimeout: number | null;\n\t/**\n\t * How long to wait for a shard's READY packet before giving up\n\t */\n\treadyTimeout: number | null;\n}\n\nexport type WebSocketManagerOptions = RequiredWebSocketManagerOptions & OptionalWebSocketManagerOptions;\n\nexport type ManagerShardEventsMap = {\n\t[K in keyof WebSocketShardEventsMap]: [\n\t\tWebSocketShardEventsMap[K] extends [] ? { shardId: number } : WebSocketShardEventsMap[K][0] & { shardId: number },\n\t];\n};\n\nexport class WebSocketManager extends AsyncEventEmitter<ManagerShardEventsMap> {\n\t/**\n\t * The options being used by this manager\n\t */\n\tpublic readonly options: WebSocketManagerOptions;\n\n\t/**\n\t * Internal cache for a GET /gateway/bot result\n\t */\n\tprivate gatewayInformation: {\n\t\tdata: APIGatewayBotInfo;\n\t\texpiresAt: number;\n\t} | null = null;\n\n\t/**\n\t * Internal cache for the shard ids\n\t */\n\tprivate shardIds: number[] | null = null;\n\n\t/**\n\t * Strategy used to manage shards\n\t * @default SimpleManagerToShardStrategy\n\t */\n\tprivate strategy: IShardingStrategy = new SimpleShardingStrategy(this);\n\n\tpublic constructor(options: RequiredWebSocketManagerOptions & Partial<OptionalWebSocketManagerOptions>) {\n\t\tsuper();\n\t\tthis.options = { ...DefaultWebSocketManagerOptions, ...options };\n\t}\n\n\tpublic setStrategy(strategy: IShardingStrategy) {\n\t\tthis.strategy = strategy;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Fetches the gateway information from Discord - or returns it from cache if available\n\t * @param force Whether to ignore the cache and force a fresh fetch\n\t */\n\tpublic async fetchGatewayInformation(force = false) {\n\t\tif (this.gatewayInformation) {\n\t\t\tif (this.gatewayInformation.expiresAt <= Date.now()) {\n\t\t\t\tthis.gatewayInformation = null;\n\t\t\t} else if (!force) {\n\t\t\t\treturn this.gatewayInformation.data;\n\t\t\t}\n\t\t}\n\n\t\tconst data = (await this.options.rest.get(Routes.gatewayBot())) as RESTGetAPIGatewayBotResult;\n\n\t\tthis.gatewayInformation = { data, expiresAt: Date.now() + data.session_start_limit.reset_after };\n\t\treturn this.gatewayInformation.data;\n\t}\n\n\t/**\n\t * Updates your total shard count on-the-fly, spawning shards as needed\n\t * @param shardCount The new shard count to use\n\t */\n\tpublic async updateShardCount(shardCount: number | null) {\n\t\tawait this.strategy.destroy({ reason: 'User is adjusting their shards' });\n\t\tthis.options.shardCount = shardCount;\n\n\t\tconst shardIds = await this.getShardIds(true);\n\t\tawait this.strategy.spawn(shardIds);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Yields the total number of shards across for your bot, accounting for Discord recommendations\n\t */\n\tpublic async getShardCount(): Promise<number> {\n\t\tif (this.options.shardCount) {\n\t\t\treturn this.options.shardCount;\n\t\t}\n\n\t\tconst shardIds = await this.getShardIds();\n\t\treturn Math.max(...shardIds) + 1;\n\t}\n\n\t/**\n\t * Yields the ids of the shards this manager should manage\n\t */\n\tpublic async getShardIds(force = false): Promise<number[]> {\n\t\tif (this.shardIds && !force) {\n\t\t\treturn this.shardIds;\n\t\t}\n\n\t\tlet shardIds: number[];\n\t\tif (this.options.shardIds) {\n\t\t\tif (Array.isArray(this.options.shardIds)) {\n\t\t\t\tshardIds = this.options.shardIds;\n\t\t\t} else {\n\t\t\t\tshardIds = range(this.options.shardIds);\n\t\t\t}\n\t\t} else {\n\t\t\tconst data = await this.fetchGatewayInformation();\n\t\t\tshardIds = range({ start: 0, end: (this.options.shardCount ?? data.shards) - 1 });\n\t\t}\n\n\t\tthis.shardIds = shardIds;\n\t\treturn shardIds;\n\t}\n\n\tpublic async connect() {\n\t\tconst shardCount = await this.getShardCount();\n\n\t\tconst data = await this.fetchGatewayInformation();\n\t\tif (data.session_start_limit.remaining < shardCount) {\n\t\t\tthrow new Error(\n\t\t\t\t`Not enough sessions remaining to spawn ${shardCount} shards; only ${\n\t\t\t\t\tdata.session_start_limit.remaining\n\t\t\t\t} remaining; resets at ${new Date(Date.now() + data.session_start_limit.reset_after).toISOString()}`,\n\t\t\t);\n\t\t}\n\n\t\t// First, make sure all our shards are spawned\n\t\tawait this.updateShardCount(shardCount);\n\t\tawait this.strategy.connect();\n\t}\n\n\tpublic destroy(options?: Omit<WebSocketShardDestroyOptions, 'recover'>) {\n\t\treturn this.strategy.destroy(options);\n\t}\n\n\tpublic send(shardId: number, payload: GatewaySendPayload) {\n\t\treturn this.strategy.send(shardId, payload);\n\t}\n}\n"],"names":[],"mappings":";;;;;;AAOO,MAAM,gBAAgB,SAAS,iBAAiB,CAAC;AACxD,EAAE,WAAW,CAAC,OAAO,EAAE;AACvB,IAAI,KAAK,EAAE,CAAC;AACZ,IAAI,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC;AACnC,IAAI,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;AACzB,IAAI,IAAI,CAAC,QAAQ,GAAG,IAAI,sBAAsB,CAAC,IAAI,CAAC,CAAC;AACrD,IAAI,IAAI,CAAC,OAAO,GAAG,EAAE,GAAG,8BAA8B,EAAE,GAAG,OAAO,EAAE,CAAC;AACrE,GAAG;AACH,EAAE,WAAW,CAAC,QAAQ,EAAE;AACxB,IAAI,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;AAC7B,IAAI,OAAO,IAAI,CAAC;AAChB,GAAG;AACH,EAAE,MAAM,uBAAuB,CAAC,KAAK,GAAG,KAAK,EAAE;AAC/C,IAAI,IAAI,IAAI,CAAC,kBAAkB,EAAE;AACjC,MAAM,IAAI,IAAI,CAAC,kBAAkB,CAAC,SAAS,IAAI,IAAI,CAAC,GAAG,EAAE,EAAE;AAC3D,QAAQ,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC;AACvC,OAAO,MAAM,IAAI,CAAC,KAAK,EAAE;AACzB,QAAQ,OAAO,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AAC;AACnN,OAAO,CAAC;AACR,KAAK;AACL,IAAI,MAAM,IAAI,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC;AAC5C,IAAI,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;AAClC,GAAG;AACH,EAAE,OAAO,CAAC,OAAO,EAAE;AACnB,IAAI,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;AAC1C,GAAG;AACH,EAAE,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE;AACzB,IAAI,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAChD,GAAG;AACH;;;;"}
@@ -123,7 +123,11 @@ class WebSocketShard extends async_event_emitter.AsyncEventEmitter {
123
123
  await this.strategy.updateSessionInfo(this.id, null);
124
124
  }
125
125
  if (this.connection && (this.connection.readyState === ws.WebSocket.OPEN || this.connection.readyState === ws.WebSocket.CONNECTING)) {
126
+ this.connection.removeAllListeners("message");
127
+ this.connection.removeAllListeners("close");
126
128
  this.connection.close(options.code, options.reason);
129
+ await node_events.once(this.connection, "close");
130
+ this.connection.removeAllListeners("error");
127
131
  }
128
132
  this.status = 0 /* Idle */;
129
133
  if (options.recover !== void 0) {
@@ -1 +1 @@
1
- {"version":3,"file":"WebSocketShard.cjs","sources":["../../src/ws/WebSocketShard.ts"],"sourcesContent":["import { once } from 'node:events';\nimport { setTimeout } from 'node:timers';\nimport { setTimeout as sleep } from 'node:timers/promises';\nimport { TextDecoder } from 'node:util';\nimport { inflate } from 'node:zlib';\nimport { Collection } from '@discordjs/collection';\nimport { AsyncQueue } from '@sapphire/async-queue';\nimport { AsyncEventEmitter } from '@vladfrangu/async_event_emitter';\nimport {\n\tGatewayCloseCodes,\n\tGatewayDispatchEvents,\n\tGatewayDispatchPayload,\n\tGatewayIdentifyData,\n\tGatewayOpcodes,\n\tGatewayReceivePayload,\n\tGatewaySendPayload,\n} from 'discord-api-types/v10';\nimport { RawData, WebSocket } from 'ws';\nimport type { Inflate } from 'zlib-sync';\nimport type { SessionInfo } from './WebSocketManager';\nimport type { IContextFetchingStrategy } from '../strategies/context/IContextFetchingStrategy';\nimport { ImportantGatewayOpcodes } from '../utils/constants';\nimport { lazy } from '../utils/utils';\n\nconst getZlibSync = lazy(() => import('zlib-sync').then((mod) => mod.default).catch(() => null));\n\nexport enum WebSocketShardEvents {\n\tDebug = 'debug',\n\tHello = 'hello',\n\tReady = 'ready',\n\tResumed = 'resumed',\n\tDispatch = 'dispatch',\n}\n\nexport enum WebSocketShardStatus {\n\tIdle,\n\tConnecting,\n\tResuming,\n\tReady,\n}\n\nexport enum WebSocketShardDestroyRecovery {\n\tReconnect,\n\tResume,\n}\n\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport type WebSocketShardEventsMap = {\n\t[WebSocketShardEvents.Debug]: [payload: { message: string }];\n\t[WebSocketShardEvents.Hello]: [];\n\t[WebSocketShardEvents.Ready]: [];\n\t[WebSocketShardEvents.Resumed]: [];\n\t[WebSocketShardEvents.Dispatch]: [payload: { data: GatewayDispatchPayload }];\n};\n\nexport interface WebSocketShardDestroyOptions {\n\treason?: string;\n\tcode?: number;\n\trecover?: WebSocketShardDestroyRecovery;\n}\n\nexport enum CloseCodes {\n\tNormal = 1000,\n\tResuming = 4200,\n}\n\nexport class WebSocketShard extends AsyncEventEmitter<WebSocketShardEventsMap> {\n\tprivate connection: WebSocket | null = null;\n\n\tprivate readonly id: number;\n\n\tprivate useIdentifyCompress = false;\n\n\tprivate inflate: Inflate | null = null;\n\tprivate readonly textDecoder = new TextDecoder();\n\n\tprivate status: WebSocketShardStatus = WebSocketShardStatus.Idle;\n\n\tprivate replayedEvents = 0;\n\n\tprivate isAck = true;\n\n\tprivate sendRateLimitState = {\n\t\tremaining: 120,\n\t\tresetAt: Date.now(),\n\t};\n\n\tprivate heartbeatInterval: NodeJS.Timer | null = null;\n\tprivate lastHeartbeatAt = -1;\n\n\tprivate session: SessionInfo | null = null;\n\n\tprivate readonly sendQueue = new AsyncQueue();\n\n\tprivate readonly timeouts = new Collection<WebSocketShardEvents, NodeJS.Timeout>();\n\n\tpublic readonly strategy: IContextFetchingStrategy;\n\n\tpublic constructor(strategy: IContextFetchingStrategy, id: number) {\n\t\tsuper();\n\t\tthis.strategy = strategy;\n\t\tthis.id = id;\n\t}\n\n\tpublic async connect() {\n\t\tif (this.status !== WebSocketShardStatus.Idle) {\n\t\t\tthrow new Error(\"Tried to connect a shard that wasn't idle\");\n\t\t}\n\n\t\tconst { version, encoding, compression } = this.strategy.options;\n\t\tconst params = new URLSearchParams({ v: version, encoding });\n\t\tif (compression) {\n\t\t\tconst zlib = await getZlibSync();\n\t\t\tif (zlib) {\n\t\t\t\tparams.append('compress', compression);\n\t\t\t\tthis.inflate = new zlib.Inflate({\n\t\t\t\t\tchunkSize: 65535,\n\t\t\t\t\tto: 'string',\n\t\t\t\t});\n\t\t\t} else if (!this.useIdentifyCompress) {\n\t\t\t\tthis.useIdentifyCompress = true;\n\t\t\t\tconsole.warn(\n\t\t\t\t\t'WebSocketShard: Compression is enabled but zlib-sync is not installed, falling back to identify compress',\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tconst session = this.session ?? (await this.strategy.retrieveSessionInfo(this.id));\n\n\t\tconst url = `${session?.resumeURL ?? this.strategy.options.gatewayInformation.url}?${params.toString()}`;\n\t\tthis.debug([`Connecting to ${url}`]);\n\t\tconst connection = new WebSocket(url, { handshakeTimeout: this.strategy.options.handshakeTimeout ?? undefined })\n\t\t\t/* eslint-disable @typescript-eslint/no-misused-promises */\n\t\t\t.on('message', this.onMessage.bind(this))\n\t\t\t.on('error', this.onError.bind(this))\n\t\t\t.on('close', this.onClose.bind(this));\n\t\t/* eslint-enable @typescript-eslint/no-misused-promises */\n\n\t\tconnection.binaryType = 'arraybuffer';\n\t\tthis.connection = connection;\n\n\t\tthis.status = WebSocketShardStatus.Connecting;\n\n\t\tawait this.waitForEvent(WebSocketShardEvents.Hello, this.strategy.options.helloTimeout);\n\n\t\tif (session?.shardCount === this.strategy.options.shardCount) {\n\t\t\tthis.session = session;\n\t\t\tawait this.resume(session);\n\t\t} else {\n\t\t\tawait this.identify();\n\t\t}\n\t}\n\n\tpublic async destroy(options: WebSocketShardDestroyOptions = {}) {\n\t\tif (this.status === WebSocketShardStatus.Idle) {\n\t\t\tthis.debug(['Tried to destroy a shard that was idle']);\n\t\t\treturn;\n\t\t}\n\n\t\tif (!options.code) {\n\t\t\toptions.code = options.recover === WebSocketShardDestroyRecovery.Resume ? CloseCodes.Resuming : CloseCodes.Normal;\n\t\t}\n\n\t\tthis.debug([\n\t\t\t'Destroying shard',\n\t\t\t`Reason: ${options.reason ?? 'none'}`,\n\t\t\t`Code: ${options.code}`,\n\t\t\t`Recover: ${options.recover === undefined ? 'none' : WebSocketShardDestroyRecovery[options.recover]!}`,\n\t\t]);\n\n\t\t// Reset state\n\t\tthis.isAck = true;\n\t\tif (this.heartbeatInterval) {\n\t\t\tclearInterval(this.heartbeatInterval);\n\t\t}\n\t\tthis.lastHeartbeatAt = -1;\n\n\t\t// Clear session state if applicable\n\t\tif (options.recover !== WebSocketShardDestroyRecovery.Resume && this.session) {\n\t\t\tthis.session = null;\n\t\t\tawait this.strategy.updateSessionInfo(this.id, null);\n\t\t}\n\n\t\tif (\n\t\t\tthis.connection &&\n\t\t\t(this.connection.readyState === WebSocket.OPEN || this.connection.readyState === WebSocket.CONNECTING)\n\t\t) {\n\t\t\tthis.connection.close(options.code, options.reason);\n\t\t}\n\n\t\tthis.status = WebSocketShardStatus.Idle;\n\n\t\tif (options.recover !== undefined) {\n\t\t\treturn this.connect();\n\t\t}\n\t}\n\n\tprivate async waitForEvent(event: WebSocketShardEvents, timeoutDuration?: number | null) {\n\t\tthis.debug([`Waiting for event ${event} for ${timeoutDuration ? `${timeoutDuration}ms` : 'indefinitely'}`]);\n\t\tconst controller = new AbortController();\n\t\tconst timeout = timeoutDuration ? setTimeout(() => controller.abort(), timeoutDuration).unref() : null;\n\t\tif (timeout) {\n\t\t\tthis.timeouts.set(event, timeout);\n\t\t}\n\t\tawait once(this, event, { signal: controller.signal });\n\t\tif (timeout) {\n\t\t\tclearTimeout(timeout);\n\t\t\tthis.timeouts.delete(event);\n\t\t}\n\t}\n\n\tpublic async send(payload: GatewaySendPayload) {\n\t\tif (!this.connection) {\n\t\t\tthrow new Error(\"WebSocketShard wasn't connected\");\n\t\t}\n\n\t\tif (this.status !== WebSocketShardStatus.Ready && !ImportantGatewayOpcodes.has(payload.op)) {\n\t\t\tawait once(this, WebSocketShardEvents.Ready);\n\t\t}\n\n\t\tawait this.sendQueue.wait();\n\n\t\tif (--this.sendRateLimitState.remaining <= 0) {\n\t\t\tif (this.sendRateLimitState.resetAt < Date.now()) {\n\t\t\t\tawait sleep(Date.now() - this.sendRateLimitState.resetAt);\n\t\t\t}\n\n\t\t\tthis.sendRateLimitState = {\n\t\t\t\tremaining: 119,\n\t\t\t\tresetAt: Date.now() + 60_000,\n\t\t\t};\n\t\t}\n\n\t\tthis.sendQueue.shift();\n\t\tthis.connection.send(JSON.stringify(payload));\n\t}\n\n\tprivate async identify() {\n\t\tthis.debug([\n\t\t\t'Identifying',\n\t\t\t`shard id: ${this.id.toString()}`,\n\t\t\t`shard count: ${this.strategy.options.shardCount}`,\n\t\t\t`intents: ${this.strategy.options.intents}`,\n\t\t\t`compression: ${this.inflate ? 'zlib-stream' : this.useIdentifyCompress ? 'identify' : 'none'}`,\n\t\t]);\n\t\tconst d: GatewayIdentifyData = {\n\t\t\ttoken: this.strategy.options.token,\n\t\t\tproperties: this.strategy.options.identifyProperties,\n\t\t\tintents: this.strategy.options.intents,\n\t\t\tcompress: this.useIdentifyCompress,\n\t\t\tshard: [this.id, this.strategy.options.shardCount],\n\t\t};\n\n\t\tif (this.strategy.options.largeThreshold) {\n\t\t\td.large_threshold = this.strategy.options.largeThreshold;\n\t\t}\n\n\t\tif (this.strategy.options.initialPresence) {\n\t\t\td.presence = this.strategy.options.initialPresence;\n\t\t}\n\n\t\tawait this.send({\n\t\t\top: GatewayOpcodes.Identify,\n\t\t\td,\n\t\t});\n\n\t\tawait this.waitForEvent(WebSocketShardEvents.Ready, this.strategy.options.readyTimeout);\n\t\tthis.status = WebSocketShardStatus.Ready;\n\t}\n\n\tprivate resume(session: SessionInfo) {\n\t\tthis.debug(['Resuming session']);\n\t\tthis.status = WebSocketShardStatus.Resuming;\n\t\tthis.replayedEvents = 0;\n\t\treturn this.send({\n\t\t\top: GatewayOpcodes.Resume,\n\t\t\td: {\n\t\t\t\ttoken: this.strategy.options.token,\n\t\t\t\tseq: session.sequence,\n\t\t\t\tsession_id: session.sessionId,\n\t\t\t},\n\t\t});\n\t}\n\n\tprivate async heartbeat(requested = false) {\n\t\tif (!this.isAck && !requested) {\n\t\t\treturn this.destroy({ reason: 'Zombie connection', recover: WebSocketShardDestroyRecovery.Resume });\n\t\t}\n\n\t\tawait this.send({\n\t\t\top: GatewayOpcodes.Heartbeat,\n\t\t\td: this.session?.sequence ?? null,\n\t\t});\n\n\t\tthis.lastHeartbeatAt = Date.now();\n\t\tthis.isAck = false;\n\t}\n\n\tprivate async unpackMessage(data: Buffer | ArrayBuffer, isBinary: boolean): Promise<GatewayReceivePayload | null> {\n\t\tconst decompressable = new Uint8Array(data);\n\n\t\t// Deal with no compression\n\t\tif (!isBinary) {\n\t\t\treturn JSON.parse(this.textDecoder.decode(decompressable)) as GatewayReceivePayload;\n\t\t}\n\n\t\t// Deal with identify compress\n\t\tif (this.useIdentifyCompress) {\n\t\t\treturn new Promise((resolve, reject) => {\n\t\t\t\tinflate(decompressable, { chunkSize: 65535 }, (err, result) => {\n\t\t\t\t\tif (err) {\n\t\t\t\t\t\treturn reject(err);\n\t\t\t\t\t}\n\n\t\t\t\t\tresolve(JSON.parse(this.textDecoder.decode(result)) as GatewayReceivePayload);\n\t\t\t\t});\n\t\t\t});\n\t\t}\n\n\t\t// Deal with gw wide zlib-stream compression\n\t\tif (this.inflate) {\n\t\t\tconst l = decompressable.length;\n\t\t\tconst flush =\n\t\t\t\tl >= 4 &&\n\t\t\t\tdecompressable[l - 4] === 0x00 &&\n\t\t\t\tdecompressable[l - 3] === 0x00 &&\n\t\t\t\tdecompressable[l - 2] === 0xff &&\n\t\t\t\tdecompressable[l - 1] === 0xff;\n\n\t\t\tconst zlib = (await getZlibSync())!;\n\t\t\tthis.inflate.push(Buffer.from(decompressable), flush ? zlib.Z_SYNC_FLUSH : zlib.Z_NO_FLUSH);\n\n\t\t\tif (this.inflate.err) {\n\t\t\t\tthis.emit('error', `${this.inflate.err}${this.inflate.msg ? `: ${this.inflate.msg}` : ''}`);\n\t\t\t}\n\n\t\t\tif (!flush) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst { result } = this.inflate;\n\t\t\tif (!result) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\treturn JSON.parse(typeof result === 'string' ? result : this.textDecoder.decode(result)) as GatewayReceivePayload;\n\t\t}\n\n\t\tthis.debug([\n\t\t\t'Received a message we were unable to decompress',\n\t\t\t`isBinary: ${isBinary.toString()}`,\n\t\t\t`useIdentifyCompress: ${this.useIdentifyCompress.toString()}`,\n\t\t\t`inflate: ${Boolean(this.inflate).toString()}`,\n\t\t]);\n\n\t\treturn null;\n\t}\n\n\tprivate async onMessage(data: RawData, isBinary: boolean) {\n\t\tconst payload = await this.unpackMessage(data as Buffer | ArrayBuffer, isBinary);\n\t\tif (!payload) {\n\t\t\treturn;\n\t\t}\n\n\t\tswitch (payload.op) {\n\t\t\tcase GatewayOpcodes.Dispatch: {\n\t\t\t\tif (this.status === WebSocketShardStatus.Ready || this.status === WebSocketShardStatus.Resuming) {\n\t\t\t\t\tthis.emit(WebSocketShardEvents.Dispatch, { data: payload });\n\t\t\t\t}\n\n\t\t\t\tif (this.status === WebSocketShardStatus.Resuming) {\n\t\t\t\t\tthis.replayedEvents++;\n\t\t\t\t}\n\n\t\t\t\tswitch (payload.t) {\n\t\t\t\t\tcase GatewayDispatchEvents.Ready: {\n\t\t\t\t\t\tthis.emit(WebSocketShardEvents.Ready);\n\n\t\t\t\t\t\tthis.session ??= {\n\t\t\t\t\t\t\tsequence: payload.s,\n\t\t\t\t\t\t\tsessionId: payload.d.session_id,\n\t\t\t\t\t\t\tshardId: this.id,\n\t\t\t\t\t\t\tshardCount: this.strategy.options.shardCount,\n\t\t\t\t\t\t\tresumeURL: payload.d.resume_gateway_url,\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\tawait this.strategy.updateSessionInfo(this.id, this.session);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tcase GatewayDispatchEvents.Resumed: {\n\t\t\t\t\t\tthis.status = WebSocketShardStatus.Ready;\n\t\t\t\t\t\tthis.debug([`Resumed and replayed ${this.replayedEvents} events`]);\n\t\t\t\t\t\tthis.emit(WebSocketShardEvents.Resumed);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tdefault: {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (this.session) {\n\t\t\t\t\tif (payload.s > this.session.sequence) {\n\t\t\t\t\t\tthis.session.sequence = payload.s;\n\t\t\t\t\t\tawait this.strategy.updateSessionInfo(this.id, this.session);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase GatewayOpcodes.Heartbeat: {\n\t\t\t\tawait this.heartbeat(true);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase GatewayOpcodes.Reconnect: {\n\t\t\t\tawait this.destroy({\n\t\t\t\t\treason: 'Told to reconnect by Discord',\n\t\t\t\t\trecover: WebSocketShardDestroyRecovery.Resume,\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase GatewayOpcodes.InvalidSession: {\n\t\t\t\tconst readyTimeout = this.timeouts.get(WebSocketShardEvents.Ready);\n\t\t\t\treadyTimeout?.refresh();\n\t\t\t\tthis.debug([`Invalid session; will attempt to resume: ${payload.d.toString()}`]);\n\t\t\t\tconst session = this.session ?? (await this.strategy.retrieveSessionInfo(this.id));\n\t\t\t\tif (payload.d && session) {\n\t\t\t\t\tawait this.resume(session);\n\t\t\t\t} else {\n\t\t\t\t\tawait this.destroy({\n\t\t\t\t\t\treason: 'Invalid session',\n\t\t\t\t\t\trecover: WebSocketShardDestroyRecovery.Reconnect,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase GatewayOpcodes.Hello: {\n\t\t\t\tthis.emit(WebSocketShardEvents.Hello);\n\t\t\t\tthis.debug([`Starting to heartbeat every ${payload.d.heartbeat_interval}ms`]);\n\t\t\t\tthis.heartbeatInterval = setInterval(() => void this.heartbeat(), payload.d.heartbeat_interval);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase GatewayOpcodes.HeartbeatAck: {\n\t\t\t\tthis.isAck = true;\n\t\t\t\tthis.debug([`Got heartbeat ack after ${Date.now() - this.lastHeartbeatAt}ms`]);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate onError(err: Error) {\n\t\tthis.emit('error', err);\n\t}\n\n\tprivate async onClose(code: number) {\n\t\tswitch (code) {\n\t\t\tcase CloseCodes.Normal: {\n\t\t\t\tthis.debug([`Disconnected normally from code ${code}`]);\n\t\t\t\treturn this.destroy({\n\t\t\t\t\tcode,\n\t\t\t\t\treason: 'Got disconnected by Discord',\n\t\t\t\t\trecover: WebSocketShardDestroyRecovery.Reconnect,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tcase CloseCodes.Resuming: {\n\t\t\t\tthis.debug([`Disconnected normally from code ${code}`]);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.UnknownError: {\n\t\t\t\tthis.debug([`An unknown error occured: ${code}`]);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Resume });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.UnknownOpcode: {\n\t\t\t\tthis.debug(['An invalid opcode was sent to Discord.']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Resume });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.DecodeError: {\n\t\t\t\tthis.debug(['An invalid payload was sent to Discord.']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Resume });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.NotAuthenticated: {\n\t\t\t\tthis.debug(['A request was somehow sent before the identify/resume payload.']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Reconnect });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.AuthenticationFailed: {\n\t\t\t\tthrow new Error('Authentication failed');\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.AlreadyAuthenticated: {\n\t\t\t\tthis.debug(['More than one auth payload was sent.']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Reconnect });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.InvalidSeq: {\n\t\t\t\tthis.debug(['An invalid sequence was sent.']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Reconnect });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.RateLimited: {\n\t\t\t\tthis.debug(['The WebSocket rate limit has been hit, this should never happen']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Reconnect });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.SessionTimedOut: {\n\t\t\t\tthis.debug(['Session timed out.']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Resume });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.InvalidShard: {\n\t\t\t\tthrow new Error('Invalid shard');\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.ShardingRequired: {\n\t\t\t\tthrow new Error('Sharding is required');\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.InvalidAPIVersion: {\n\t\t\t\tthrow new Error('Used an invalid API version');\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.InvalidIntents: {\n\t\t\t\tthrow new Error('Used invalid intents');\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.DisallowedIntents: {\n\t\t\t\tthrow new Error('Used disallowed intents');\n\t\t\t}\n\n\t\t\tdefault: {\n\t\t\t\tthis.debug([`The gateway closed with an unexpected code ${code}, attempting to resume.`]);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Resume });\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate debug(messages: [string, ...string[]]) {\n\t\tconst message = `${messages[0]}${\n\t\t\tmessages.length > 1\n\t\t\t\t? `\\n${messages\n\t\t\t\t\t\t.slice(1)\n\t\t\t\t\t\t.map((m) => `\t${m}`)\n\t\t\t\t\t\t.join('\\n')}`\n\t\t\t\t: ''\n\t\t}`;\n\n\t\tthis.emit(WebSocketShardEvents.Debug, { message });\n\t}\n}\n"],"names":["lazy","AsyncEventEmitter","TextDecoder","AsyncQueue","Collection","WebSocket","setTimeout","once","ImportantGatewayOpcodes","sleep","GatewayOpcodes","inflate","GatewayDispatchEvents","GatewayCloseCodes"],"mappings":";;;;;;;;;;;;;;;;;AAgBA,MAAM,WAAW,GAAGA,UAAI,CAAC,MAAM,OAAO,WAAW,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC;AACvF,IAAC,oBAAoB,mBAAmB,CAAC,CAAC,qBAAqB,KAAK;AAC9E,EAAE,qBAAqB,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;AAC3C,EAAE,qBAAqB,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;AAC3C,EAAE,qBAAqB,CAAC,OAAO,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,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;AAChD,OAAO;AACP,MAAM,KAAKA,qBAAiB,CAAC,iBAAiB,EAAE;AAChD,QAAQ,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;AACnD,OAAO;AACP,MAAM,SAAS;AACf,QAAQ,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,2CAA2C,EAAE,IAAI,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC;AAClG,QAAQ,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,eAAe,CAAC,CAAC;AAC/D,OAAO;AACP,KAAK;AACL,GAAG;AACH,EAAE,KAAK,CAAC,QAAQ,EAAE;AAClB,IAAI,MAAM,OAAO,GAAG,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,MAAM,GAAG,CAAC,GAAG,CAAC;AAC5D,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;AAC5D,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,cAAc,EAAE,OAAO,EAAE,CAAC,CAAC;AAChD,GAAG;AACH;;;;;;;;"}
1
+ {"version":3,"file":"WebSocketShard.cjs","sources":["../../src/ws/WebSocketShard.ts"],"sourcesContent":["import { once } from 'node:events';\nimport { setTimeout } from 'node:timers';\nimport { setTimeout as sleep } from 'node:timers/promises';\nimport { TextDecoder } from 'node:util';\nimport { inflate } from 'node:zlib';\nimport { Collection } from '@discordjs/collection';\nimport { AsyncQueue } from '@sapphire/async-queue';\nimport { AsyncEventEmitter } from '@vladfrangu/async_event_emitter';\nimport {\n\tGatewayCloseCodes,\n\tGatewayDispatchEvents,\n\tGatewayDispatchPayload,\n\tGatewayIdentifyData,\n\tGatewayOpcodes,\n\tGatewayReceivePayload,\n\tGatewaySendPayload,\n} from 'discord-api-types/v10';\nimport { RawData, WebSocket } from 'ws';\nimport type { Inflate } from 'zlib-sync';\nimport type { SessionInfo } from './WebSocketManager';\nimport type { IContextFetchingStrategy } from '../strategies/context/IContextFetchingStrategy';\nimport { ImportantGatewayOpcodes } from '../utils/constants';\nimport { lazy } from '../utils/utils';\n\nconst getZlibSync = lazy(() => import('zlib-sync').then((mod) => mod.default).catch(() => null));\n\nexport enum WebSocketShardEvents {\n\tDebug = 'debug',\n\tHello = 'hello',\n\tReady = 'ready',\n\tResumed = 'resumed',\n\tDispatch = 'dispatch',\n}\n\nexport enum WebSocketShardStatus {\n\tIdle,\n\tConnecting,\n\tResuming,\n\tReady,\n}\n\nexport enum WebSocketShardDestroyRecovery {\n\tReconnect,\n\tResume,\n}\n\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport type WebSocketShardEventsMap = {\n\t[WebSocketShardEvents.Debug]: [payload: { message: string }];\n\t[WebSocketShardEvents.Hello]: [];\n\t[WebSocketShardEvents.Ready]: [];\n\t[WebSocketShardEvents.Resumed]: [];\n\t[WebSocketShardEvents.Dispatch]: [payload: { data: GatewayDispatchPayload }];\n};\n\nexport interface WebSocketShardDestroyOptions {\n\treason?: string;\n\tcode?: number;\n\trecover?: WebSocketShardDestroyRecovery;\n}\n\nexport enum CloseCodes {\n\tNormal = 1000,\n\tResuming = 4200,\n}\n\nexport class WebSocketShard extends AsyncEventEmitter<WebSocketShardEventsMap> {\n\tprivate connection: WebSocket | null = null;\n\n\tprivate readonly id: number;\n\n\tprivate useIdentifyCompress = false;\n\n\tprivate inflate: Inflate | null = null;\n\tprivate readonly textDecoder = new TextDecoder();\n\n\tprivate status: WebSocketShardStatus = WebSocketShardStatus.Idle;\n\n\tprivate replayedEvents = 0;\n\n\tprivate isAck = true;\n\n\tprivate sendRateLimitState = {\n\t\tremaining: 120,\n\t\tresetAt: Date.now(),\n\t};\n\n\tprivate heartbeatInterval: NodeJS.Timer | null = null;\n\tprivate lastHeartbeatAt = -1;\n\n\tprivate session: SessionInfo | null = null;\n\n\tprivate readonly sendQueue = new AsyncQueue();\n\n\tprivate readonly timeouts = new Collection<WebSocketShardEvents, NodeJS.Timeout>();\n\n\tpublic readonly strategy: IContextFetchingStrategy;\n\n\tpublic constructor(strategy: IContextFetchingStrategy, id: number) {\n\t\tsuper();\n\t\tthis.strategy = strategy;\n\t\tthis.id = id;\n\t}\n\n\tpublic async connect() {\n\t\tif (this.status !== WebSocketShardStatus.Idle) {\n\t\t\tthrow new Error(\"Tried to connect a shard that wasn't idle\");\n\t\t}\n\n\t\tconst { version, encoding, compression } = this.strategy.options;\n\t\tconst params = new URLSearchParams({ v: version, encoding });\n\t\tif (compression) {\n\t\t\tconst zlib = await getZlibSync();\n\t\t\tif (zlib) {\n\t\t\t\tparams.append('compress', compression);\n\t\t\t\tthis.inflate = new zlib.Inflate({\n\t\t\t\t\tchunkSize: 65535,\n\t\t\t\t\tto: 'string',\n\t\t\t\t});\n\t\t\t} else if (!this.useIdentifyCompress) {\n\t\t\t\tthis.useIdentifyCompress = true;\n\t\t\t\tconsole.warn(\n\t\t\t\t\t'WebSocketShard: Compression is enabled but zlib-sync is not installed, falling back to identify compress',\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tconst session = this.session ?? (await this.strategy.retrieveSessionInfo(this.id));\n\n\t\tconst url = `${session?.resumeURL ?? this.strategy.options.gatewayInformation.url}?${params.toString()}`;\n\t\tthis.debug([`Connecting to ${url}`]);\n\t\tconst connection = new WebSocket(url, { handshakeTimeout: this.strategy.options.handshakeTimeout ?? undefined })\n\t\t\t/* eslint-disable @typescript-eslint/no-misused-promises */\n\t\t\t.on('message', this.onMessage.bind(this))\n\t\t\t.on('error', this.onError.bind(this))\n\t\t\t.on('close', this.onClose.bind(this));\n\t\t/* eslint-enable @typescript-eslint/no-misused-promises */\n\n\t\tconnection.binaryType = 'arraybuffer';\n\t\tthis.connection = connection;\n\n\t\tthis.status = WebSocketShardStatus.Connecting;\n\n\t\tawait this.waitForEvent(WebSocketShardEvents.Hello, this.strategy.options.helloTimeout);\n\n\t\tif (session?.shardCount === this.strategy.options.shardCount) {\n\t\t\tthis.session = session;\n\t\t\tawait this.resume(session);\n\t\t} else {\n\t\t\tawait this.identify();\n\t\t}\n\t}\n\n\tpublic async destroy(options: WebSocketShardDestroyOptions = {}) {\n\t\tif (this.status === WebSocketShardStatus.Idle) {\n\t\t\tthis.debug(['Tried to destroy a shard that was idle']);\n\t\t\treturn;\n\t\t}\n\n\t\tif (!options.code) {\n\t\t\toptions.code = options.recover === WebSocketShardDestroyRecovery.Resume ? CloseCodes.Resuming : CloseCodes.Normal;\n\t\t}\n\n\t\tthis.debug([\n\t\t\t'Destroying shard',\n\t\t\t`Reason: ${options.reason ?? 'none'}`,\n\t\t\t`Code: ${options.code}`,\n\t\t\t`Recover: ${options.recover === undefined ? 'none' : WebSocketShardDestroyRecovery[options.recover]!}`,\n\t\t]);\n\n\t\t// Reset state\n\t\tthis.isAck = true;\n\t\tif (this.heartbeatInterval) {\n\t\t\tclearInterval(this.heartbeatInterval);\n\t\t}\n\t\tthis.lastHeartbeatAt = -1;\n\n\t\t// Clear session state if applicable\n\t\tif (options.recover !== WebSocketShardDestroyRecovery.Resume && this.session) {\n\t\t\tthis.session = null;\n\t\t\tawait this.strategy.updateSessionInfo(this.id, null);\n\t\t}\n\n\t\tif (\n\t\t\tthis.connection &&\n\t\t\t(this.connection.readyState === WebSocket.OPEN || this.connection.readyState === WebSocket.CONNECTING)\n\t\t) {\n\t\t\t// No longer need to listen to messages\n\t\t\tthis.connection.removeAllListeners('message');\n\t\t\t// Prevent a reconnection loop by unbinding the main close event\n\t\t\tthis.connection.removeAllListeners('close');\n\t\t\tthis.connection.close(options.code, options.reason);\n\n\t\t\t// Actually wait for the connection to close\n\t\t\tawait once(this.connection, 'close');\n\n\t\t\t// Lastly, remove the error event.\n\t\t\t// Doing this earlier would cause a hard crash in case an error event fired on our `close` call\n\t\t\tthis.connection.removeAllListeners('error');\n\t\t}\n\n\t\tthis.status = WebSocketShardStatus.Idle;\n\n\t\tif (options.recover !== undefined) {\n\t\t\treturn this.connect();\n\t\t}\n\t}\n\n\tprivate async waitForEvent(event: WebSocketShardEvents, timeoutDuration?: number | null) {\n\t\tthis.debug([`Waiting for event ${event} for ${timeoutDuration ? `${timeoutDuration}ms` : 'indefinitely'}`]);\n\t\tconst controller = new AbortController();\n\t\tconst timeout = timeoutDuration ? setTimeout(() => controller.abort(), timeoutDuration).unref() : null;\n\t\tif (timeout) {\n\t\t\tthis.timeouts.set(event, timeout);\n\t\t}\n\t\tawait once(this, event, { signal: controller.signal });\n\t\tif (timeout) {\n\t\t\tclearTimeout(timeout);\n\t\t\tthis.timeouts.delete(event);\n\t\t}\n\t}\n\n\tpublic async send(payload: GatewaySendPayload) {\n\t\tif (!this.connection) {\n\t\t\tthrow new Error(\"WebSocketShard wasn't connected\");\n\t\t}\n\n\t\tif (this.status !== WebSocketShardStatus.Ready && !ImportantGatewayOpcodes.has(payload.op)) {\n\t\t\tawait once(this, WebSocketShardEvents.Ready);\n\t\t}\n\n\t\tawait this.sendQueue.wait();\n\n\t\tif (--this.sendRateLimitState.remaining <= 0) {\n\t\t\tif (this.sendRateLimitState.resetAt < Date.now()) {\n\t\t\t\tawait sleep(Date.now() - this.sendRateLimitState.resetAt);\n\t\t\t}\n\n\t\t\tthis.sendRateLimitState = {\n\t\t\t\tremaining: 119,\n\t\t\t\tresetAt: Date.now() + 60_000,\n\t\t\t};\n\t\t}\n\n\t\tthis.sendQueue.shift();\n\t\tthis.connection.send(JSON.stringify(payload));\n\t}\n\n\tprivate async identify() {\n\t\tthis.debug([\n\t\t\t'Identifying',\n\t\t\t`shard id: ${this.id.toString()}`,\n\t\t\t`shard count: ${this.strategy.options.shardCount}`,\n\t\t\t`intents: ${this.strategy.options.intents}`,\n\t\t\t`compression: ${this.inflate ? 'zlib-stream' : this.useIdentifyCompress ? 'identify' : 'none'}`,\n\t\t]);\n\t\tconst d: GatewayIdentifyData = {\n\t\t\ttoken: this.strategy.options.token,\n\t\t\tproperties: this.strategy.options.identifyProperties,\n\t\t\tintents: this.strategy.options.intents,\n\t\t\tcompress: this.useIdentifyCompress,\n\t\t\tshard: [this.id, this.strategy.options.shardCount],\n\t\t};\n\n\t\tif (this.strategy.options.largeThreshold) {\n\t\t\td.large_threshold = this.strategy.options.largeThreshold;\n\t\t}\n\n\t\tif (this.strategy.options.initialPresence) {\n\t\t\td.presence = this.strategy.options.initialPresence;\n\t\t}\n\n\t\tawait this.send({\n\t\t\top: GatewayOpcodes.Identify,\n\t\t\td,\n\t\t});\n\n\t\tawait this.waitForEvent(WebSocketShardEvents.Ready, this.strategy.options.readyTimeout);\n\t\tthis.status = WebSocketShardStatus.Ready;\n\t}\n\n\tprivate resume(session: SessionInfo) {\n\t\tthis.debug(['Resuming session']);\n\t\tthis.status = WebSocketShardStatus.Resuming;\n\t\tthis.replayedEvents = 0;\n\t\treturn this.send({\n\t\t\top: GatewayOpcodes.Resume,\n\t\t\td: {\n\t\t\t\ttoken: this.strategy.options.token,\n\t\t\t\tseq: session.sequence,\n\t\t\t\tsession_id: session.sessionId,\n\t\t\t},\n\t\t});\n\t}\n\n\tprivate async heartbeat(requested = false) {\n\t\tif (!this.isAck && !requested) {\n\t\t\treturn this.destroy({ reason: 'Zombie connection', recover: WebSocketShardDestroyRecovery.Resume });\n\t\t}\n\n\t\tawait this.send({\n\t\t\top: GatewayOpcodes.Heartbeat,\n\t\t\td: this.session?.sequence ?? null,\n\t\t});\n\n\t\tthis.lastHeartbeatAt = Date.now();\n\t\tthis.isAck = false;\n\t}\n\n\tprivate async unpackMessage(data: Buffer | ArrayBuffer, isBinary: boolean): Promise<GatewayReceivePayload | null> {\n\t\tconst decompressable = new Uint8Array(data);\n\n\t\t// Deal with no compression\n\t\tif (!isBinary) {\n\t\t\treturn JSON.parse(this.textDecoder.decode(decompressable)) as GatewayReceivePayload;\n\t\t}\n\n\t\t// Deal with identify compress\n\t\tif (this.useIdentifyCompress) {\n\t\t\treturn new Promise((resolve, reject) => {\n\t\t\t\tinflate(decompressable, { chunkSize: 65535 }, (err, result) => {\n\t\t\t\t\tif (err) {\n\t\t\t\t\t\treturn reject(err);\n\t\t\t\t\t}\n\n\t\t\t\t\tresolve(JSON.parse(this.textDecoder.decode(result)) as GatewayReceivePayload);\n\t\t\t\t});\n\t\t\t});\n\t\t}\n\n\t\t// Deal with gw wide zlib-stream compression\n\t\tif (this.inflate) {\n\t\t\tconst l = decompressable.length;\n\t\t\tconst flush =\n\t\t\t\tl >= 4 &&\n\t\t\t\tdecompressable[l - 4] === 0x00 &&\n\t\t\t\tdecompressable[l - 3] === 0x00 &&\n\t\t\t\tdecompressable[l - 2] === 0xff &&\n\t\t\t\tdecompressable[l - 1] === 0xff;\n\n\t\t\tconst zlib = (await getZlibSync())!;\n\t\t\tthis.inflate.push(Buffer.from(decompressable), flush ? zlib.Z_SYNC_FLUSH : zlib.Z_NO_FLUSH);\n\n\t\t\tif (this.inflate.err) {\n\t\t\t\tthis.emit('error', `${this.inflate.err}${this.inflate.msg ? `: ${this.inflate.msg}` : ''}`);\n\t\t\t}\n\n\t\t\tif (!flush) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst { result } = this.inflate;\n\t\t\tif (!result) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\treturn JSON.parse(typeof result === 'string' ? result : this.textDecoder.decode(result)) as GatewayReceivePayload;\n\t\t}\n\n\t\tthis.debug([\n\t\t\t'Received a message we were unable to decompress',\n\t\t\t`isBinary: ${isBinary.toString()}`,\n\t\t\t`useIdentifyCompress: ${this.useIdentifyCompress.toString()}`,\n\t\t\t`inflate: ${Boolean(this.inflate).toString()}`,\n\t\t]);\n\n\t\treturn null;\n\t}\n\n\tprivate async onMessage(data: RawData, isBinary: boolean) {\n\t\tconst payload = await this.unpackMessage(data as Buffer | ArrayBuffer, isBinary);\n\t\tif (!payload) {\n\t\t\treturn;\n\t\t}\n\n\t\tswitch (payload.op) {\n\t\t\tcase GatewayOpcodes.Dispatch: {\n\t\t\t\tif (this.status === WebSocketShardStatus.Ready || this.status === WebSocketShardStatus.Resuming) {\n\t\t\t\t\tthis.emit(WebSocketShardEvents.Dispatch, { data: payload });\n\t\t\t\t}\n\n\t\t\t\tif (this.status === WebSocketShardStatus.Resuming) {\n\t\t\t\t\tthis.replayedEvents++;\n\t\t\t\t}\n\n\t\t\t\tswitch (payload.t) {\n\t\t\t\t\tcase GatewayDispatchEvents.Ready: {\n\t\t\t\t\t\tthis.emit(WebSocketShardEvents.Ready);\n\n\t\t\t\t\t\tthis.session ??= {\n\t\t\t\t\t\t\tsequence: payload.s,\n\t\t\t\t\t\t\tsessionId: payload.d.session_id,\n\t\t\t\t\t\t\tshardId: this.id,\n\t\t\t\t\t\t\tshardCount: this.strategy.options.shardCount,\n\t\t\t\t\t\t\tresumeURL: payload.d.resume_gateway_url,\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\tawait this.strategy.updateSessionInfo(this.id, this.session);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tcase GatewayDispatchEvents.Resumed: {\n\t\t\t\t\t\tthis.status = WebSocketShardStatus.Ready;\n\t\t\t\t\t\tthis.debug([`Resumed and replayed ${this.replayedEvents} events`]);\n\t\t\t\t\t\tthis.emit(WebSocketShardEvents.Resumed);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tdefault: {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (this.session) {\n\t\t\t\t\tif (payload.s > this.session.sequence) {\n\t\t\t\t\t\tthis.session.sequence = payload.s;\n\t\t\t\t\t\tawait this.strategy.updateSessionInfo(this.id, this.session);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase GatewayOpcodes.Heartbeat: {\n\t\t\t\tawait this.heartbeat(true);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase GatewayOpcodes.Reconnect: {\n\t\t\t\tawait this.destroy({\n\t\t\t\t\treason: 'Told to reconnect by Discord',\n\t\t\t\t\trecover: WebSocketShardDestroyRecovery.Resume,\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase GatewayOpcodes.InvalidSession: {\n\t\t\t\tconst readyTimeout = this.timeouts.get(WebSocketShardEvents.Ready);\n\t\t\t\treadyTimeout?.refresh();\n\t\t\t\tthis.debug([`Invalid session; will attempt to resume: ${payload.d.toString()}`]);\n\t\t\t\tconst session = this.session ?? (await this.strategy.retrieveSessionInfo(this.id));\n\t\t\t\tif (payload.d && session) {\n\t\t\t\t\tawait this.resume(session);\n\t\t\t\t} else {\n\t\t\t\t\tawait this.destroy({\n\t\t\t\t\t\treason: 'Invalid session',\n\t\t\t\t\t\trecover: WebSocketShardDestroyRecovery.Reconnect,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase GatewayOpcodes.Hello: {\n\t\t\t\tthis.emit(WebSocketShardEvents.Hello);\n\t\t\t\tthis.debug([`Starting to heartbeat every ${payload.d.heartbeat_interval}ms`]);\n\t\t\t\tthis.heartbeatInterval = setInterval(() => void this.heartbeat(), payload.d.heartbeat_interval);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase GatewayOpcodes.HeartbeatAck: {\n\t\t\t\tthis.isAck = true;\n\t\t\t\tthis.debug([`Got heartbeat ack after ${Date.now() - this.lastHeartbeatAt}ms`]);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate onError(err: Error) {\n\t\tthis.emit('error', err);\n\t}\n\n\tprivate async onClose(code: number) {\n\t\tswitch (code) {\n\t\t\tcase CloseCodes.Normal: {\n\t\t\t\tthis.debug([`Disconnected normally from code ${code}`]);\n\t\t\t\treturn this.destroy({\n\t\t\t\t\tcode,\n\t\t\t\t\treason: 'Got disconnected by Discord',\n\t\t\t\t\trecover: WebSocketShardDestroyRecovery.Reconnect,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tcase CloseCodes.Resuming: {\n\t\t\t\tthis.debug([`Disconnected normally from code ${code}`]);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.UnknownError: {\n\t\t\t\tthis.debug([`An unknown error occured: ${code}`]);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Resume });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.UnknownOpcode: {\n\t\t\t\tthis.debug(['An invalid opcode was sent to Discord.']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Resume });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.DecodeError: {\n\t\t\t\tthis.debug(['An invalid payload was sent to Discord.']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Resume });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.NotAuthenticated: {\n\t\t\t\tthis.debug(['A request was somehow sent before the identify/resume payload.']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Reconnect });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.AuthenticationFailed: {\n\t\t\t\tthrow new Error('Authentication failed');\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.AlreadyAuthenticated: {\n\t\t\t\tthis.debug(['More than one auth payload was sent.']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Reconnect });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.InvalidSeq: {\n\t\t\t\tthis.debug(['An invalid sequence was sent.']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Reconnect });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.RateLimited: {\n\t\t\t\tthis.debug(['The WebSocket rate limit has been hit, this should never happen']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Reconnect });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.SessionTimedOut: {\n\t\t\t\tthis.debug(['Session timed out.']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Resume });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.InvalidShard: {\n\t\t\t\tthrow new Error('Invalid shard');\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.ShardingRequired: {\n\t\t\t\tthrow new Error('Sharding is required');\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.InvalidAPIVersion: {\n\t\t\t\tthrow new Error('Used an invalid API version');\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.InvalidIntents: {\n\t\t\t\tthrow new Error('Used invalid intents');\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.DisallowedIntents: {\n\t\t\t\tthrow new Error('Used disallowed intents');\n\t\t\t}\n\n\t\t\tdefault: {\n\t\t\t\tthis.debug([`The gateway closed with an unexpected code ${code}, attempting to resume.`]);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Resume });\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate debug(messages: [string, ...string[]]) {\n\t\tconst message = `${messages[0]}${\n\t\t\tmessages.length > 1\n\t\t\t\t? `\\n${messages\n\t\t\t\t\t\t.slice(1)\n\t\t\t\t\t\t.map((m) => `\t${m}`)\n\t\t\t\t\t\t.join('\\n')}`\n\t\t\t\t: ''\n\t\t}`;\n\n\t\tthis.emit(WebSocketShardEvents.Debug, { message });\n\t}\n}\n"],"names":["lazy","AsyncEventEmitter","TextDecoder","AsyncQueue","Collection","WebSocket","once","setTimeout","ImportantGatewayOpcodes","sleep","GatewayOpcodes","inflate","GatewayDispatchEvents","GatewayCloseCodes"],"mappings":";;;;;;;;;;;;;;;;;AAgBA,MAAM,WAAW,GAA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AQ,CAAC,EAAE,CAAS;IAE5B,OAAO,CAAC,mBAAmB,CAAS;IAEpC,OAAO,CAAC,OAAO,CAAwB;IACvC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAqB;IAEjD,OAAO,CAAC,MAAM,CAAmD;IAEjE,OAAO,CAAC,cAAc,CAAK;IAE3B,OAAO,CAAC,KAAK,CAAQ;IAErB,OAAO,CAAC,kBAAkB,CAGxB;IAEF,OAAO,CAAC,iBAAiB,CAA6B;IACtD,OAAO,CAAC,eAAe,CAAM;IAE7B,OAAO,CAAC,OAAO,CAA4B;IAE3C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAoB;IAE9C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA0D;IAEnF,SAAgB,QAAQ,EAAE,wBAAwB,CAAC;gBAEhC,QAAQ,EAAE,wBAAwB,EAAE,EAAE,EAAE,MAAM;IAMpD,OAAO;IAiDP,OAAO,CAAC,OAAO,GAAE,4BAAiC;YAuDjD,YAAY;IAcb,IAAI,CAAC,OAAO,EAAE,kBAAkB;YA0B/B,QAAQ;IAiCtB,OAAO,CAAC,MAAM;YAcA,SAAS;YAcT,aAAa;YA4Db,SAAS;IAkGvB,OAAO,CAAC,OAAO;YAID,OAAO;IAuFrB,OAAO,CAAC,KAAK;CAYb"}
@@ -119,7 +119,11 @@ class WebSocketShard extends AsyncEventEmitter {
119
119
  await this.strategy.updateSessionInfo(this.id, null);
120
120
  }
121
121
  if (this.connection && (this.connection.readyState === WebSocket.OPEN || this.connection.readyState === WebSocket.CONNECTING)) {
122
+ this.connection.removeAllListeners("message");
123
+ this.connection.removeAllListeners("close");
122
124
  this.connection.close(options.code, options.reason);
125
+ await once(this.connection, "close");
126
+ this.connection.removeAllListeners("error");
123
127
  }
124
128
  this.status = 0 /* Idle */;
125
129
  if (options.recover !== void 0) {
@@ -1 +1 @@
1
- {"version":3,"file":"WebSocketShard.mjs","sources":["../../src/ws/WebSocketShard.ts"],"sourcesContent":["import { once } from 'node:events';\nimport { setTimeout } from 'node:timers';\nimport { setTimeout as sleep } from 'node:timers/promises';\nimport { TextDecoder } from 'node:util';\nimport { inflate } from 'node:zlib';\nimport { Collection } from '@discordjs/collection';\nimport { AsyncQueue } from '@sapphire/async-queue';\nimport { AsyncEventEmitter } from '@vladfrangu/async_event_emitter';\nimport {\n\tGatewayCloseCodes,\n\tGatewayDispatchEvents,\n\tGatewayDispatchPayload,\n\tGatewayIdentifyData,\n\tGatewayOpcodes,\n\tGatewayReceivePayload,\n\tGatewaySendPayload,\n} from 'discord-api-types/v10';\nimport { RawData, WebSocket } from 'ws';\nimport type { Inflate } from 'zlib-sync';\nimport type { SessionInfo } from './WebSocketManager';\nimport type { IContextFetchingStrategy } from '../strategies/context/IContextFetchingStrategy';\nimport { ImportantGatewayOpcodes } from '../utils/constants';\nimport { lazy } from '../utils/utils';\n\nconst getZlibSync = lazy(() => import('zlib-sync').then((mod) => mod.default).catch(() => null));\n\nexport enum WebSocketShardEvents {\n\tDebug = 'debug',\n\tHello = 'hello',\n\tReady = 'ready',\n\tResumed = 'resumed',\n\tDispatch = 'dispatch',\n}\n\nexport enum WebSocketShardStatus {\n\tIdle,\n\tConnecting,\n\tResuming,\n\tReady,\n}\n\nexport enum WebSocketShardDestroyRecovery {\n\tReconnect,\n\tResume,\n}\n\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport type WebSocketShardEventsMap = {\n\t[WebSocketShardEvents.Debug]: [payload: { message: string }];\n\t[WebSocketShardEvents.Hello]: [];\n\t[WebSocketShardEvents.Ready]: [];\n\t[WebSocketShardEvents.Resumed]: [];\n\t[WebSocketShardEvents.Dispatch]: [payload: { data: GatewayDispatchPayload }];\n};\n\nexport interface WebSocketShardDestroyOptions {\n\treason?: string;\n\tcode?: number;\n\trecover?: WebSocketShardDestroyRecovery;\n}\n\nexport enum CloseCodes {\n\tNormal = 1000,\n\tResuming = 4200,\n}\n\nexport class WebSocketShard extends AsyncEventEmitter<WebSocketShardEventsMap> {\n\tprivate connection: WebSocket | null = null;\n\n\tprivate readonly id: number;\n\n\tprivate useIdentifyCompress = false;\n\n\tprivate inflate: Inflate | null = null;\n\tprivate readonly textDecoder = new TextDecoder();\n\n\tprivate status: WebSocketShardStatus = WebSocketShardStatus.Idle;\n\n\tprivate replayedEvents = 0;\n\n\tprivate isAck = true;\n\n\tprivate sendRateLimitState = {\n\t\tremaining: 120,\n\t\tresetAt: Date.now(),\n\t};\n\n\tprivate heartbeatInterval: NodeJS.Timer | null = null;\n\tprivate lastHeartbeatAt = -1;\n\n\tprivate session: SessionInfo | null = null;\n\n\tprivate readonly sendQueue = new AsyncQueue();\n\n\tprivate readonly timeouts = new Collection<WebSocketShardEvents, NodeJS.Timeout>();\n\n\tpublic readonly strategy: IContextFetchingStrategy;\n\n\tpublic constructor(strategy: IContextFetchingStrategy, id: number) {\n\t\tsuper();\n\t\tthis.strategy = strategy;\n\t\tthis.id = id;\n\t}\n\n\tpublic async connect() {\n\t\tif (this.status !== WebSocketShardStatus.Idle) {\n\t\t\tthrow new Error(\"Tried to connect a shard that wasn't idle\");\n\t\t}\n\n\t\tconst { version, encoding, compression } = this.strategy.options;\n\t\tconst params = new URLSearchParams({ v: version, encoding });\n\t\tif (compression) {\n\t\t\tconst zlib = await getZlibSync();\n\t\t\tif (zlib) {\n\t\t\t\tparams.append('compress', compression);\n\t\t\t\tthis.inflate = new zlib.Inflate({\n\t\t\t\t\tchunkSize: 65535,\n\t\t\t\t\tto: 'string',\n\t\t\t\t});\n\t\t\t} else if (!this.useIdentifyCompress) {\n\t\t\t\tthis.useIdentifyCompress = true;\n\t\t\t\tconsole.warn(\n\t\t\t\t\t'WebSocketShard: Compression is enabled but zlib-sync is not installed, falling back to identify compress',\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tconst session = this.session ?? (await this.strategy.retrieveSessionInfo(this.id));\n\n\t\tconst url = `${session?.resumeURL ?? this.strategy.options.gatewayInformation.url}?${params.toString()}`;\n\t\tthis.debug([`Connecting to ${url}`]);\n\t\tconst connection = new WebSocket(url, { handshakeTimeout: this.strategy.options.handshakeTimeout ?? undefined })\n\t\t\t/* eslint-disable @typescript-eslint/no-misused-promises */\n\t\t\t.on('message', this.onMessage.bind(this))\n\t\t\t.on('error', this.onError.bind(this))\n\t\t\t.on('close', this.onClose.bind(this));\n\t\t/* eslint-enable @typescript-eslint/no-misused-promises */\n\n\t\tconnection.binaryType = 'arraybuffer';\n\t\tthis.connection = connection;\n\n\t\tthis.status = WebSocketShardStatus.Connecting;\n\n\t\tawait this.waitForEvent(WebSocketShardEvents.Hello, this.strategy.options.helloTimeout);\n\n\t\tif (session?.shardCount === this.strategy.options.shardCount) {\n\t\t\tthis.session = session;\n\t\t\tawait this.resume(session);\n\t\t} else {\n\t\t\tawait this.identify();\n\t\t}\n\t}\n\n\tpublic async destroy(options: WebSocketShardDestroyOptions = {}) {\n\t\tif (this.status === WebSocketShardStatus.Idle) {\n\t\t\tthis.debug(['Tried to destroy a shard that was idle']);\n\t\t\treturn;\n\t\t}\n\n\t\tif (!options.code) {\n\t\t\toptions.code = options.recover === WebSocketShardDestroyRecovery.Resume ? CloseCodes.Resuming : CloseCodes.Normal;\n\t\t}\n\n\t\tthis.debug([\n\t\t\t'Destroying shard',\n\t\t\t`Reason: ${options.reason ?? 'none'}`,\n\t\t\t`Code: ${options.code}`,\n\t\t\t`Recover: ${options.recover === undefined ? 'none' : WebSocketShardDestroyRecovery[options.recover]!}`,\n\t\t]);\n\n\t\t// Reset state\n\t\tthis.isAck = true;\n\t\tif (this.heartbeatInterval) {\n\t\t\tclearInterval(this.heartbeatInterval);\n\t\t}\n\t\tthis.lastHeartbeatAt = -1;\n\n\t\t// Clear session state if applicable\n\t\tif (options.recover !== WebSocketShardDestroyRecovery.Resume && this.session) {\n\t\t\tthis.session = null;\n\t\t\tawait this.strategy.updateSessionInfo(this.id, null);\n\t\t}\n\n\t\tif (\n\t\t\tthis.connection &&\n\t\t\t(this.connection.readyState === WebSocket.OPEN || this.connection.readyState === WebSocket.CONNECTING)\n\t\t) {\n\t\t\tthis.connection.close(options.code, options.reason);\n\t\t}\n\n\t\tthis.status = WebSocketShardStatus.Idle;\n\n\t\tif (options.recover !== undefined) {\n\t\t\treturn this.connect();\n\t\t}\n\t}\n\n\tprivate async waitForEvent(event: WebSocketShardEvents, timeoutDuration?: number | null) {\n\t\tthis.debug([`Waiting for event ${event} for ${timeoutDuration ? `${timeoutDuration}ms` : 'indefinitely'}`]);\n\t\tconst controller = new AbortController();\n\t\tconst timeout = timeoutDuration ? setTimeout(() => controller.abort(), timeoutDuration).unref() : null;\n\t\tif (timeout) {\n\t\t\tthis.timeouts.set(event, timeout);\n\t\t}\n\t\tawait once(this, event, { signal: controller.signal });\n\t\tif (timeout) {\n\t\t\tclearTimeout(timeout);\n\t\t\tthis.timeouts.delete(event);\n\t\t}\n\t}\n\n\tpublic async send(payload: GatewaySendPayload) {\n\t\tif (!this.connection) {\n\t\t\tthrow new Error(\"WebSocketShard wasn't connected\");\n\t\t}\n\n\t\tif (this.status !== WebSocketShardStatus.Ready && !ImportantGatewayOpcodes.has(payload.op)) {\n\t\t\tawait once(this, WebSocketShardEvents.Ready);\n\t\t}\n\n\t\tawait this.sendQueue.wait();\n\n\t\tif (--this.sendRateLimitState.remaining <= 0) {\n\t\t\tif (this.sendRateLimitState.resetAt < Date.now()) {\n\t\t\t\tawait sleep(Date.now() - this.sendRateLimitState.resetAt);\n\t\t\t}\n\n\t\t\tthis.sendRateLimitState = {\n\t\t\t\tremaining: 119,\n\t\t\t\tresetAt: Date.now() + 60_000,\n\t\t\t};\n\t\t}\n\n\t\tthis.sendQueue.shift();\n\t\tthis.connection.send(JSON.stringify(payload));\n\t}\n\n\tprivate async identify() {\n\t\tthis.debug([\n\t\t\t'Identifying',\n\t\t\t`shard id: ${this.id.toString()}`,\n\t\t\t`shard count: ${this.strategy.options.shardCount}`,\n\t\t\t`intents: ${this.strategy.options.intents}`,\n\t\t\t`compression: ${this.inflate ? 'zlib-stream' : this.useIdentifyCompress ? 'identify' : 'none'}`,\n\t\t]);\n\t\tconst d: GatewayIdentifyData = {\n\t\t\ttoken: this.strategy.options.token,\n\t\t\tproperties: this.strategy.options.identifyProperties,\n\t\t\tintents: this.strategy.options.intents,\n\t\t\tcompress: this.useIdentifyCompress,\n\t\t\tshard: [this.id, this.strategy.options.shardCount],\n\t\t};\n\n\t\tif (this.strategy.options.largeThreshold) {\n\t\t\td.large_threshold = this.strategy.options.largeThreshold;\n\t\t}\n\n\t\tif (this.strategy.options.initialPresence) {\n\t\t\td.presence = this.strategy.options.initialPresence;\n\t\t}\n\n\t\tawait this.send({\n\t\t\top: GatewayOpcodes.Identify,\n\t\t\td,\n\t\t});\n\n\t\tawait this.waitForEvent(WebSocketShardEvents.Ready, this.strategy.options.readyTimeout);\n\t\tthis.status = WebSocketShardStatus.Ready;\n\t}\n\n\tprivate resume(session: SessionInfo) {\n\t\tthis.debug(['Resuming session']);\n\t\tthis.status = WebSocketShardStatus.Resuming;\n\t\tthis.replayedEvents = 0;\n\t\treturn this.send({\n\t\t\top: GatewayOpcodes.Resume,\n\t\t\td: {\n\t\t\t\ttoken: this.strategy.options.token,\n\t\t\t\tseq: session.sequence,\n\t\t\t\tsession_id: session.sessionId,\n\t\t\t},\n\t\t});\n\t}\n\n\tprivate async heartbeat(requested = false) {\n\t\tif (!this.isAck && !requested) {\n\t\t\treturn this.destroy({ reason: 'Zombie connection', recover: WebSocketShardDestroyRecovery.Resume });\n\t\t}\n\n\t\tawait this.send({\n\t\t\top: GatewayOpcodes.Heartbeat,\n\t\t\td: this.session?.sequence ?? null,\n\t\t});\n\n\t\tthis.lastHeartbeatAt = Date.now();\n\t\tthis.isAck = false;\n\t}\n\n\tprivate async unpackMessage(data: Buffer | ArrayBuffer, isBinary: boolean): Promise<GatewayReceivePayload | null> {\n\t\tconst decompressable = new Uint8Array(data);\n\n\t\t// Deal with no compression\n\t\tif (!isBinary) {\n\t\t\treturn JSON.parse(this.textDecoder.decode(decompressable)) as GatewayReceivePayload;\n\t\t}\n\n\t\t// Deal with identify compress\n\t\tif (this.useIdentifyCompress) {\n\t\t\treturn new Promise((resolve, reject) => {\n\t\t\t\tinflate(decompressable, { chunkSize: 65535 }, (err, result) => {\n\t\t\t\t\tif (err) {\n\t\t\t\t\t\treturn reject(err);\n\t\t\t\t\t}\n\n\t\t\t\t\tresolve(JSON.parse(this.textDecoder.decode(result)) as GatewayReceivePayload);\n\t\t\t\t});\n\t\t\t});\n\t\t}\n\n\t\t// Deal with gw wide zlib-stream compression\n\t\tif (this.inflate) {\n\t\t\tconst l = decompressable.length;\n\t\t\tconst flush =\n\t\t\t\tl >= 4 &&\n\t\t\t\tdecompressable[l - 4] === 0x00 &&\n\t\t\t\tdecompressable[l - 3] === 0x00 &&\n\t\t\t\tdecompressable[l - 2] === 0xff &&\n\t\t\t\tdecompressable[l - 1] === 0xff;\n\n\t\t\tconst zlib = (await getZlibSync())!;\n\t\t\tthis.inflate.push(Buffer.from(decompressable), flush ? zlib.Z_SYNC_FLUSH : zlib.Z_NO_FLUSH);\n\n\t\t\tif (this.inflate.err) {\n\t\t\t\tthis.emit('error', `${this.inflate.err}${this.inflate.msg ? `: ${this.inflate.msg}` : ''}`);\n\t\t\t}\n\n\t\t\tif (!flush) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst { result } = this.inflate;\n\t\t\tif (!result) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\treturn JSON.parse(typeof result === 'string' ? result : this.textDecoder.decode(result)) as GatewayReceivePayload;\n\t\t}\n\n\t\tthis.debug([\n\t\t\t'Received a message we were unable to decompress',\n\t\t\t`isBinary: ${isBinary.toString()}`,\n\t\t\t`useIdentifyCompress: ${this.useIdentifyCompress.toString()}`,\n\t\t\t`inflate: ${Boolean(this.inflate).toString()}`,\n\t\t]);\n\n\t\treturn null;\n\t}\n\n\tprivate async onMessage(data: RawData, isBinary: boolean) {\n\t\tconst payload = await this.unpackMessage(data as Buffer | ArrayBuffer, isBinary);\n\t\tif (!payload) {\n\t\t\treturn;\n\t\t}\n\n\t\tswitch (payload.op) {\n\t\t\tcase GatewayOpcodes.Dispatch: {\n\t\t\t\tif (this.status === WebSocketShardStatus.Ready || this.status === WebSocketShardStatus.Resuming) {\n\t\t\t\t\tthis.emit(WebSocketShardEvents.Dispatch, { data: payload });\n\t\t\t\t}\n\n\t\t\t\tif (this.status === WebSocketShardStatus.Resuming) {\n\t\t\t\t\tthis.replayedEvents++;\n\t\t\t\t}\n\n\t\t\t\tswitch (payload.t) {\n\t\t\t\t\tcase GatewayDispatchEvents.Ready: {\n\t\t\t\t\t\tthis.emit(WebSocketShardEvents.Ready);\n\n\t\t\t\t\t\tthis.session ??= {\n\t\t\t\t\t\t\tsequence: payload.s,\n\t\t\t\t\t\t\tsessionId: payload.d.session_id,\n\t\t\t\t\t\t\tshardId: this.id,\n\t\t\t\t\t\t\tshardCount: this.strategy.options.shardCount,\n\t\t\t\t\t\t\tresumeURL: payload.d.resume_gateway_url,\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\tawait this.strategy.updateSessionInfo(this.id, this.session);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tcase GatewayDispatchEvents.Resumed: {\n\t\t\t\t\t\tthis.status = WebSocketShardStatus.Ready;\n\t\t\t\t\t\tthis.debug([`Resumed and replayed ${this.replayedEvents} events`]);\n\t\t\t\t\t\tthis.emit(WebSocketShardEvents.Resumed);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tdefault: {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (this.session) {\n\t\t\t\t\tif (payload.s > this.session.sequence) {\n\t\t\t\t\t\tthis.session.sequence = payload.s;\n\t\t\t\t\t\tawait this.strategy.updateSessionInfo(this.id, this.session);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase GatewayOpcodes.Heartbeat: {\n\t\t\t\tawait this.heartbeat(true);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase GatewayOpcodes.Reconnect: {\n\t\t\t\tawait this.destroy({\n\t\t\t\t\treason: 'Told to reconnect by Discord',\n\t\t\t\t\trecover: WebSocketShardDestroyRecovery.Resume,\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase GatewayOpcodes.InvalidSession: {\n\t\t\t\tconst readyTimeout = this.timeouts.get(WebSocketShardEvents.Ready);\n\t\t\t\treadyTimeout?.refresh();\n\t\t\t\tthis.debug([`Invalid session; will attempt to resume: ${payload.d.toString()}`]);\n\t\t\t\tconst session = this.session ?? (await this.strategy.retrieveSessionInfo(this.id));\n\t\t\t\tif (payload.d && session) {\n\t\t\t\t\tawait this.resume(session);\n\t\t\t\t} else {\n\t\t\t\t\tawait this.destroy({\n\t\t\t\t\t\treason: 'Invalid session',\n\t\t\t\t\t\trecover: WebSocketShardDestroyRecovery.Reconnect,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase GatewayOpcodes.Hello: {\n\t\t\t\tthis.emit(WebSocketShardEvents.Hello);\n\t\t\t\tthis.debug([`Starting to heartbeat every ${payload.d.heartbeat_interval}ms`]);\n\t\t\t\tthis.heartbeatInterval = setInterval(() => void this.heartbeat(), payload.d.heartbeat_interval);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase GatewayOpcodes.HeartbeatAck: {\n\t\t\t\tthis.isAck = true;\n\t\t\t\tthis.debug([`Got heartbeat ack after ${Date.now() - this.lastHeartbeatAt}ms`]);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate onError(err: Error) {\n\t\tthis.emit('error', err);\n\t}\n\n\tprivate async onClose(code: number) {\n\t\tswitch (code) {\n\t\t\tcase CloseCodes.Normal: {\n\t\t\t\tthis.debug([`Disconnected normally from code ${code}`]);\n\t\t\t\treturn this.destroy({\n\t\t\t\t\tcode,\n\t\t\t\t\treason: 'Got disconnected by Discord',\n\t\t\t\t\trecover: WebSocketShardDestroyRecovery.Reconnect,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tcase CloseCodes.Resuming: {\n\t\t\t\tthis.debug([`Disconnected normally from code ${code}`]);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.UnknownError: {\n\t\t\t\tthis.debug([`An unknown error occured: ${code}`]);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Resume });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.UnknownOpcode: {\n\t\t\t\tthis.debug(['An invalid opcode was sent to Discord.']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Resume });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.DecodeError: {\n\t\t\t\tthis.debug(['An invalid payload was sent to Discord.']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Resume });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.NotAuthenticated: {\n\t\t\t\tthis.debug(['A request was somehow sent before the identify/resume payload.']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Reconnect });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.AuthenticationFailed: {\n\t\t\t\tthrow new Error('Authentication failed');\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.AlreadyAuthenticated: {\n\t\t\t\tthis.debug(['More than one auth payload was sent.']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Reconnect });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.InvalidSeq: {\n\t\t\t\tthis.debug(['An invalid sequence was sent.']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Reconnect });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.RateLimited: {\n\t\t\t\tthis.debug(['The WebSocket rate limit has been hit, this should never happen']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Reconnect });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.SessionTimedOut: {\n\t\t\t\tthis.debug(['Session timed out.']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Resume });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.InvalidShard: {\n\t\t\t\tthrow new Error('Invalid shard');\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.ShardingRequired: {\n\t\t\t\tthrow new Error('Sharding is required');\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.InvalidAPIVersion: {\n\t\t\t\tthrow new Error('Used an invalid API version');\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.InvalidIntents: {\n\t\t\t\tthrow new Error('Used invalid intents');\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.DisallowedIntents: {\n\t\t\t\tthrow new Error('Used disallowed intents');\n\t\t\t}\n\n\t\t\tdefault: {\n\t\t\t\tthis.debug([`The gateway closed with an unexpected code ${code}, attempting to resume.`]);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Resume });\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate debug(messages: [string, ...string[]]) {\n\t\tconst message = `${messages[0]}${\n\t\t\tmessages.length > 1\n\t\t\t\t? `\\n${messages\n\t\t\t\t\t\t.slice(1)\n\t\t\t\t\t\t.map((m) => `\t${m}`)\n\t\t\t\t\t\t.join('\\n')}`\n\t\t\t\t: ''\n\t\t}`;\n\n\t\tthis.emit(WebSocketShardEvents.Debug, { message });\n\t}\n}\n"],"names":["sleep"],"mappings":";;;;;;;;;;;;;AAgBA,MAAM,WAAW,GAAG,IAAI,CAAC,MAAM,OAAO,WAAW,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,MAAM,IAAI,CAAC,CAAC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AAiB,CAAC,iBAAiB,EAAE;AAChD,QAAQ,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;AACvD,OAAO;AACP,MAAM,KAAK,iBAAiB,CAAC,cAAc,EAAE;AAC7C,QAAQ,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;AAChD,OAAO;AACP,MAAM,KAAK,iBAAiB,CAAC,iBAAiB,EAAE;AAChD,QAAQ,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;AACnD,OAAO;AACP,MAAM,SAAS;AACf,QAAQ,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,2CAA2C,EAAE,IAAI,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC;AAClG,QAAQ,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,eAAe,CAAC,CAAC;AAC/D,OAAO;AACP,KAAK;AACL,GAAG;AACH,EAAE,KAAK,CAAC,QAAQ,EAAE;AAClB,IAAI,MAAM,OAAO,GAAG,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,MAAM,GAAG,CAAC,GAAG,CAAC;AAC5D,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;AAC5D,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,cAAc,EAAE,OAAO,EAAE,CAAC,CAAC;AAChD,GAAG;AACH;;;;"}
1
+ {"version":3,"file":"WebSocketShard.mjs","sources":["../../src/ws/WebSocketShard.ts"],"sourcesContent":["import { once } from 'node:events';\nimport { setTimeout } from 'node:timers';\nimport { setTimeout as sleep } from 'node:timers/promises';\nimport { TextDecoder } from 'node:util';\nimport { inflate } from 'node:zlib';\nimport { Collection } from '@discordjs/collection';\nimport { AsyncQueue } from '@sapphire/async-queue';\nimport { AsyncEventEmitter } from '@vladfrangu/async_event_emitter';\nimport {\n\tGatewayCloseCodes,\n\tGatewayDispatchEvents,\n\tGatewayDispatchPayload,\n\tGatewayIdentifyData,\n\tGatewayOpcodes,\n\tGatewayReceivePayload,\n\tGatewaySendPayload,\n} from 'discord-api-types/v10';\nimport { RawData, WebSocket } from 'ws';\nimport type { Inflate } from 'zlib-sync';\nimport type { SessionInfo } from './WebSocketManager';\nimport type { IContextFetchingStrategy } from '../strategies/context/IContextFetchingStrategy';\nimport { ImportantGatewayOpcodes } from '../utils/constants';\nimport { lazy } from '../utils/utils';\n\nconst getZlibSync = lazy(() => import('zlib-sync').then((mod) => mod.default).catch(() => null));\n\nexport enum WebSocketShardEvents {\n\tDebug = 'debug',\n\tHello = 'hello',\n\tReady = 'ready',\n\tResumed = 'resumed',\n\tDispatch = 'dispatch',\n}\n\nexport enum WebSocketShardStatus {\n\tIdle,\n\tConnecting,\n\tResuming,\n\tReady,\n}\n\nexport enum WebSocketShardDestroyRecovery {\n\tReconnect,\n\tResume,\n}\n\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport type WebSocketShardEventsMap = {\n\t[WebSocketShardEvents.Debug]: [payload: { message: string }];\n\t[WebSocketShardEvents.Hello]: [];\n\t[WebSocketShardEvents.Ready]: [];\n\t[WebSocketShardEvents.Resumed]: [];\n\t[WebSocketShardEvents.Dispatch]: [payload: { data: GatewayDispatchPayload }];\n};\n\nexport interface WebSocketShardDestroyOptions {\n\treason?: string;\n\tcode?: number;\n\trecover?: WebSocketShardDestroyRecovery;\n}\n\nexport enum CloseCodes {\n\tNormal = 1000,\n\tResuming = 4200,\n}\n\nexport class WebSocketShard extends AsyncEventEmitter<WebSocketShardEventsMap> {\n\tprivate connection: WebSocket | null = null;\n\n\tprivate readonly id: number;\n\n\tprivate useIdentifyCompress = false;\n\n\tprivate inflate: Inflate | null = null;\n\tprivate readonly textDecoder = new TextDecoder();\n\n\tprivate status: WebSocketShardStatus = WebSocketShardStatus.Idle;\n\n\tprivate replayedEvents = 0;\n\n\tprivate isAck = true;\n\n\tprivate sendRateLimitState = {\n\t\tremaining: 120,\n\t\tresetAt: Date.now(),\n\t};\n\n\tprivate heartbeatInterval: NodeJS.Timer | null = null;\n\tprivate lastHeartbeatAt = -1;\n\n\tprivate session: SessionInfo | null = null;\n\n\tprivate readonly sendQueue = new AsyncQueue();\n\n\tprivate readonly timeouts = new Collection<WebSocketShardEvents, NodeJS.Timeout>();\n\n\tpublic readonly strategy: IContextFetchingStrategy;\n\n\tpublic constructor(strategy: IContextFetchingStrategy, id: number) {\n\t\tsuper();\n\t\tthis.strategy = strategy;\n\t\tthis.id = id;\n\t}\n\n\tpublic async connect() {\n\t\tif (this.status !== WebSocketShardStatus.Idle) {\n\t\t\tthrow new Error(\"Tried to connect a shard that wasn't idle\");\n\t\t}\n\n\t\tconst { version, encoding, compression } = this.strategy.options;\n\t\tconst params = new URLSearchParams({ v: version, encoding });\n\t\tif (compression) {\n\t\t\tconst zlib = await getZlibSync();\n\t\t\tif (zlib) {\n\t\t\t\tparams.append('compress', compression);\n\t\t\t\tthis.inflate = new zlib.Inflate({\n\t\t\t\t\tchunkSize: 65535,\n\t\t\t\t\tto: 'string',\n\t\t\t\t});\n\t\t\t} else if (!this.useIdentifyCompress) {\n\t\t\t\tthis.useIdentifyCompress = true;\n\t\t\t\tconsole.warn(\n\t\t\t\t\t'WebSocketShard: Compression is enabled but zlib-sync is not installed, falling back to identify compress',\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tconst session = this.session ?? (await this.strategy.retrieveSessionInfo(this.id));\n\n\t\tconst url = `${session?.resumeURL ?? this.strategy.options.gatewayInformation.url}?${params.toString()}`;\n\t\tthis.debug([`Connecting to ${url}`]);\n\t\tconst connection = new WebSocket(url, { handshakeTimeout: this.strategy.options.handshakeTimeout ?? undefined })\n\t\t\t/* eslint-disable @typescript-eslint/no-misused-promises */\n\t\t\t.on('message', this.onMessage.bind(this))\n\t\t\t.on('error', this.onError.bind(this))\n\t\t\t.on('close', this.onClose.bind(this));\n\t\t/* eslint-enable @typescript-eslint/no-misused-promises */\n\n\t\tconnection.binaryType = 'arraybuffer';\n\t\tthis.connection = connection;\n\n\t\tthis.status = WebSocketShardStatus.Connecting;\n\n\t\tawait this.waitForEvent(WebSocketShardEvents.Hello, this.strategy.options.helloTimeout);\n\n\t\tif (session?.shardCount === this.strategy.options.shardCount) {\n\t\t\tthis.session = session;\n\t\t\tawait this.resume(session);\n\t\t} else {\n\t\t\tawait this.identify();\n\t\t}\n\t}\n\n\tpublic async destroy(options: WebSocketShardDestroyOptions = {}) {\n\t\tif (this.status === WebSocketShardStatus.Idle) {\n\t\t\tthis.debug(['Tried to destroy a shard that was idle']);\n\t\t\treturn;\n\t\t}\n\n\t\tif (!options.code) {\n\t\t\toptions.code = options.recover === WebSocketShardDestroyRecovery.Resume ? CloseCodes.Resuming : CloseCodes.Normal;\n\t\t}\n\n\t\tthis.debug([\n\t\t\t'Destroying shard',\n\t\t\t`Reason: ${options.reason ?? 'none'}`,\n\t\t\t`Code: ${options.code}`,\n\t\t\t`Recover: ${options.recover === undefined ? 'none' : WebSocketShardDestroyRecovery[options.recover]!}`,\n\t\t]);\n\n\t\t// Reset state\n\t\tthis.isAck = true;\n\t\tif (this.heartbeatInterval) {\n\t\t\tclearInterval(this.heartbeatInterval);\n\t\t}\n\t\tthis.lastHeartbeatAt = -1;\n\n\t\t// Clear session state if applicable\n\t\tif (options.recover !== WebSocketShardDestroyRecovery.Resume && this.session) {\n\t\t\tthis.session = null;\n\t\t\tawait this.strategy.updateSessionInfo(this.id, null);\n\t\t}\n\n\t\tif (\n\t\t\tthis.connection &&\n\t\t\t(this.connection.readyState === WebSocket.OPEN || this.connection.readyState === WebSocket.CONNECTING)\n\t\t) {\n\t\t\t// No longer need to listen to messages\n\t\t\tthis.connection.removeAllListeners('message');\n\t\t\t// Prevent a reconnection loop by unbinding the main close event\n\t\t\tthis.connection.removeAllListeners('close');\n\t\t\tthis.connection.close(options.code, options.reason);\n\n\t\t\t// Actually wait for the connection to close\n\t\t\tawait once(this.connection, 'close');\n\n\t\t\t// Lastly, remove the error event.\n\t\t\t// Doing this earlier would cause a hard crash in case an error event fired on our `close` call\n\t\t\tthis.connection.removeAllListeners('error');\n\t\t}\n\n\t\tthis.status = WebSocketShardStatus.Idle;\n\n\t\tif (options.recover !== undefined) {\n\t\t\treturn this.connect();\n\t\t}\n\t}\n\n\tprivate async waitForEvent(event: WebSocketShardEvents, timeoutDuration?: number | null) {\n\t\tthis.debug([`Waiting for event ${event} for ${timeoutDuration ? `${timeoutDuration}ms` : 'indefinitely'}`]);\n\t\tconst controller = new AbortController();\n\t\tconst timeout = timeoutDuration ? setTimeout(() => controller.abort(), timeoutDuration).unref() : null;\n\t\tif (timeout) {\n\t\t\tthis.timeouts.set(event, timeout);\n\t\t}\n\t\tawait once(this, event, { signal: controller.signal });\n\t\tif (timeout) {\n\t\t\tclearTimeout(timeout);\n\t\t\tthis.timeouts.delete(event);\n\t\t}\n\t}\n\n\tpublic async send(payload: GatewaySendPayload) {\n\t\tif (!this.connection) {\n\t\t\tthrow new Error(\"WebSocketShard wasn't connected\");\n\t\t}\n\n\t\tif (this.status !== WebSocketShardStatus.Ready && !ImportantGatewayOpcodes.has(payload.op)) {\n\t\t\tawait once(this, WebSocketShardEvents.Ready);\n\t\t}\n\n\t\tawait this.sendQueue.wait();\n\n\t\tif (--this.sendRateLimitState.remaining <= 0) {\n\t\t\tif (this.sendRateLimitState.resetAt < Date.now()) {\n\t\t\t\tawait sleep(Date.now() - this.sendRateLimitState.resetAt);\n\t\t\t}\n\n\t\t\tthis.sendRateLimitState = {\n\t\t\t\tremaining: 119,\n\t\t\t\tresetAt: Date.now() + 60_000,\n\t\t\t};\n\t\t}\n\n\t\tthis.sendQueue.shift();\n\t\tthis.connection.send(JSON.stringify(payload));\n\t}\n\n\tprivate async identify() {\n\t\tthis.debug([\n\t\t\t'Identifying',\n\t\t\t`shard id: ${this.id.toString()}`,\n\t\t\t`shard count: ${this.strategy.options.shardCount}`,\n\t\t\t`intents: ${this.strategy.options.intents}`,\n\t\t\t`compression: ${this.inflate ? 'zlib-stream' : this.useIdentifyCompress ? 'identify' : 'none'}`,\n\t\t]);\n\t\tconst d: GatewayIdentifyData = {\n\t\t\ttoken: this.strategy.options.token,\n\t\t\tproperties: this.strategy.options.identifyProperties,\n\t\t\tintents: this.strategy.options.intents,\n\t\t\tcompress: this.useIdentifyCompress,\n\t\t\tshard: [this.id, this.strategy.options.shardCount],\n\t\t};\n\n\t\tif (this.strategy.options.largeThreshold) {\n\t\t\td.large_threshold = this.strategy.options.largeThreshold;\n\t\t}\n\n\t\tif (this.strategy.options.initialPresence) {\n\t\t\td.presence = this.strategy.options.initialPresence;\n\t\t}\n\n\t\tawait this.send({\n\t\t\top: GatewayOpcodes.Identify,\n\t\t\td,\n\t\t});\n\n\t\tawait this.waitForEvent(WebSocketShardEvents.Ready, this.strategy.options.readyTimeout);\n\t\tthis.status = WebSocketShardStatus.Ready;\n\t}\n\n\tprivate resume(session: SessionInfo) {\n\t\tthis.debug(['Resuming session']);\n\t\tthis.status = WebSocketShardStatus.Resuming;\n\t\tthis.replayedEvents = 0;\n\t\treturn this.send({\n\t\t\top: GatewayOpcodes.Resume,\n\t\t\td: {\n\t\t\t\ttoken: this.strategy.options.token,\n\t\t\t\tseq: session.sequence,\n\t\t\t\tsession_id: session.sessionId,\n\t\t\t},\n\t\t});\n\t}\n\n\tprivate async heartbeat(requested = false) {\n\t\tif (!this.isAck && !requested) {\n\t\t\treturn this.destroy({ reason: 'Zombie connection', recover: WebSocketShardDestroyRecovery.Resume });\n\t\t}\n\n\t\tawait this.send({\n\t\t\top: GatewayOpcodes.Heartbeat,\n\t\t\td: this.session?.sequence ?? null,\n\t\t});\n\n\t\tthis.lastHeartbeatAt = Date.now();\n\t\tthis.isAck = false;\n\t}\n\n\tprivate async unpackMessage(data: Buffer | ArrayBuffer, isBinary: boolean): Promise<GatewayReceivePayload | null> {\n\t\tconst decompressable = new Uint8Array(data);\n\n\t\t// Deal with no compression\n\t\tif (!isBinary) {\n\t\t\treturn JSON.parse(this.textDecoder.decode(decompressable)) as GatewayReceivePayload;\n\t\t}\n\n\t\t// Deal with identify compress\n\t\tif (this.useIdentifyCompress) {\n\t\t\treturn new Promise((resolve, reject) => {\n\t\t\t\tinflate(decompressable, { chunkSize: 65535 }, (err, result) => {\n\t\t\t\t\tif (err) {\n\t\t\t\t\t\treturn reject(err);\n\t\t\t\t\t}\n\n\t\t\t\t\tresolve(JSON.parse(this.textDecoder.decode(result)) as GatewayReceivePayload);\n\t\t\t\t});\n\t\t\t});\n\t\t}\n\n\t\t// Deal with gw wide zlib-stream compression\n\t\tif (this.inflate) {\n\t\t\tconst l = decompressable.length;\n\t\t\tconst flush =\n\t\t\t\tl >= 4 &&\n\t\t\t\tdecompressable[l - 4] === 0x00 &&\n\t\t\t\tdecompressable[l - 3] === 0x00 &&\n\t\t\t\tdecompressable[l - 2] === 0xff &&\n\t\t\t\tdecompressable[l - 1] === 0xff;\n\n\t\t\tconst zlib = (await getZlibSync())!;\n\t\t\tthis.inflate.push(Buffer.from(decompressable), flush ? zlib.Z_SYNC_FLUSH : zlib.Z_NO_FLUSH);\n\n\t\t\tif (this.inflate.err) {\n\t\t\t\tthis.emit('error', `${this.inflate.err}${this.inflate.msg ? `: ${this.inflate.msg}` : ''}`);\n\t\t\t}\n\n\t\t\tif (!flush) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst { result } = this.inflate;\n\t\t\tif (!result) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\treturn JSON.parse(typeof result === 'string' ? result : this.textDecoder.decode(result)) as GatewayReceivePayload;\n\t\t}\n\n\t\tthis.debug([\n\t\t\t'Received a message we were unable to decompress',\n\t\t\t`isBinary: ${isBinary.toString()}`,\n\t\t\t`useIdentifyCompress: ${this.useIdentifyCompress.toString()}`,\n\t\t\t`inflate: ${Boolean(this.inflate).toString()}`,\n\t\t]);\n\n\t\treturn null;\n\t}\n\n\tprivate async onMessage(data: RawData, isBinary: boolean) {\n\t\tconst payload = await this.unpackMessage(data as Buffer | ArrayBuffer, isBinary);\n\t\tif (!payload) {\n\t\t\treturn;\n\t\t}\n\n\t\tswitch (payload.op) {\n\t\t\tcase GatewayOpcodes.Dispatch: {\n\t\t\t\tif (this.status === WebSocketShardStatus.Ready || this.status === WebSocketShardStatus.Resuming) {\n\t\t\t\t\tthis.emit(WebSocketShardEvents.Dispatch, { data: payload });\n\t\t\t\t}\n\n\t\t\t\tif (this.status === WebSocketShardStatus.Resuming) {\n\t\t\t\t\tthis.replayedEvents++;\n\t\t\t\t}\n\n\t\t\t\tswitch (payload.t) {\n\t\t\t\t\tcase GatewayDispatchEvents.Ready: {\n\t\t\t\t\t\tthis.emit(WebSocketShardEvents.Ready);\n\n\t\t\t\t\t\tthis.session ??= {\n\t\t\t\t\t\t\tsequence: payload.s,\n\t\t\t\t\t\t\tsessionId: payload.d.session_id,\n\t\t\t\t\t\t\tshardId: this.id,\n\t\t\t\t\t\t\tshardCount: this.strategy.options.shardCount,\n\t\t\t\t\t\t\tresumeURL: payload.d.resume_gateway_url,\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\tawait this.strategy.updateSessionInfo(this.id, this.session);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tcase GatewayDispatchEvents.Resumed: {\n\t\t\t\t\t\tthis.status = WebSocketShardStatus.Ready;\n\t\t\t\t\t\tthis.debug([`Resumed and replayed ${this.replayedEvents} events`]);\n\t\t\t\t\t\tthis.emit(WebSocketShardEvents.Resumed);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tdefault: {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (this.session) {\n\t\t\t\t\tif (payload.s > this.session.sequence) {\n\t\t\t\t\t\tthis.session.sequence = payload.s;\n\t\t\t\t\t\tawait this.strategy.updateSessionInfo(this.id, this.session);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase GatewayOpcodes.Heartbeat: {\n\t\t\t\tawait this.heartbeat(true);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase GatewayOpcodes.Reconnect: {\n\t\t\t\tawait this.destroy({\n\t\t\t\t\treason: 'Told to reconnect by Discord',\n\t\t\t\t\trecover: WebSocketShardDestroyRecovery.Resume,\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase GatewayOpcodes.InvalidSession: {\n\t\t\t\tconst readyTimeout = this.timeouts.get(WebSocketShardEvents.Ready);\n\t\t\t\treadyTimeout?.refresh();\n\t\t\t\tthis.debug([`Invalid session; will attempt to resume: ${payload.d.toString()}`]);\n\t\t\t\tconst session = this.session ?? (await this.strategy.retrieveSessionInfo(this.id));\n\t\t\t\tif (payload.d && session) {\n\t\t\t\t\tawait this.resume(session);\n\t\t\t\t} else {\n\t\t\t\t\tawait this.destroy({\n\t\t\t\t\t\treason: 'Invalid session',\n\t\t\t\t\t\trecover: WebSocketShardDestroyRecovery.Reconnect,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase GatewayOpcodes.Hello: {\n\t\t\t\tthis.emit(WebSocketShardEvents.Hello);\n\t\t\t\tthis.debug([`Starting to heartbeat every ${payload.d.heartbeat_interval}ms`]);\n\t\t\t\tthis.heartbeatInterval = setInterval(() => void this.heartbeat(), payload.d.heartbeat_interval);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase GatewayOpcodes.HeartbeatAck: {\n\t\t\t\tthis.isAck = true;\n\t\t\t\tthis.debug([`Got heartbeat ack after ${Date.now() - this.lastHeartbeatAt}ms`]);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate onError(err: Error) {\n\t\tthis.emit('error', err);\n\t}\n\n\tprivate async onClose(code: number) {\n\t\tswitch (code) {\n\t\t\tcase CloseCodes.Normal: {\n\t\t\t\tthis.debug([`Disconnected normally from code ${code}`]);\n\t\t\t\treturn this.destroy({\n\t\t\t\t\tcode,\n\t\t\t\t\treason: 'Got disconnected by Discord',\n\t\t\t\t\trecover: WebSocketShardDestroyRecovery.Reconnect,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tcase CloseCodes.Resuming: {\n\t\t\t\tthis.debug([`Disconnected normally from code ${code}`]);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.UnknownError: {\n\t\t\t\tthis.debug([`An unknown error occured: ${code}`]);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Resume });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.UnknownOpcode: {\n\t\t\t\tthis.debug(['An invalid opcode was sent to Discord.']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Resume });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.DecodeError: {\n\t\t\t\tthis.debug(['An invalid payload was sent to Discord.']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Resume });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.NotAuthenticated: {\n\t\t\t\tthis.debug(['A request was somehow sent before the identify/resume payload.']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Reconnect });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.AuthenticationFailed: {\n\t\t\t\tthrow new Error('Authentication failed');\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.AlreadyAuthenticated: {\n\t\t\t\tthis.debug(['More than one auth payload was sent.']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Reconnect });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.InvalidSeq: {\n\t\t\t\tthis.debug(['An invalid sequence was sent.']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Reconnect });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.RateLimited: {\n\t\t\t\tthis.debug(['The WebSocket rate limit has been hit, this should never happen']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Reconnect });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.SessionTimedOut: {\n\t\t\t\tthis.debug(['Session timed out.']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Resume });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.InvalidShard: {\n\t\t\t\tthrow new Error('Invalid shard');\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.ShardingRequired: {\n\t\t\t\tthrow new Error('Sharding is required');\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.InvalidAPIVersion: {\n\t\t\t\tthrow new Error('Used an invalid API version');\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.InvalidIntents: {\n\t\t\t\tthrow new Error('Used invalid intents');\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.DisallowedIntents: {\n\t\t\t\tthrow new Error('Used disallowed intents');\n\t\t\t}\n\n\t\t\tdefault: {\n\t\t\t\tthis.debug([`The gateway closed with an unexpected code ${code}, attempting to resume.`]);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Resume });\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate debug(messages: [string, ...string[]]) {\n\t\tconst message = `${messages[0]}${\n\t\t\tmessages.length > 1\n\t\t\t\t? `\\n${messages\n\t\t\t\t\t\t.slice(1)\n\t\t\t\t\t\t.map((m) => `\t${m}`)\n\t\t\t\t\t\t.join('\\n')}`\n\t\t\t\t: ''\n\t\t}`;\n\n\t\tthis.emit(WebSocketShardEvents.Debug, { message });\n\t}\n}\n"],"names":["sleep"],"mappings":";;;;;;;;;;;;;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,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;AAC5D,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,cAAc,EAAE,OAAO,EAAE,CAAC,CAAC;AAChD,GAAG;AACH;;;;"}
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@discordjs/ws",
3
- "version": "0.3.0-dev.1660478713-bc06cc6.0",
3
+ "version": "0.3.0-dev.1660910640-e475b63.0",
4
4
  "description": "Wrapper around Discord's gateway",
5
5
  "scripts": {
6
6
  "test": "vitest run",
7
7
  "build": "unbuild",
8
- "lint": "prettier --check . && eslint src __tests__ --ext mjs,js,ts",
9
- "format": "prettier --write . && eslint src __tests__ --ext mjs,js,ts --fix",
8
+ "lint": "prettier --check . && TIMING=1 eslint src __tests__ --ext mjs,js,ts",
9
+ "format": "prettier --write . && TIMING=1 eslint src __tests__ --ext mjs,js,ts --fix",
10
10
  "docs": "docgen -i src/index.ts -c docs/index.json -o docs/docs.json --typescript && api-extractor run --local",
11
11
  "prepack": "yarn build && yarn lint",
12
12
  "changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/ws/*'",
@@ -62,19 +62,25 @@
62
62
  "ws": "^8.8.1"
63
63
  },
64
64
  "devDependencies": {
65
- "@discordjs/docgen": "^0.12.0",
65
+ "@discordjs/docgen": "^0.12.1",
66
66
  "@favware/cliff-jumper": "^1.8.6",
67
67
  "@microsoft/api-extractor": "^7.29.2",
68
- "@types/node": "^16.11.47",
69
- "c8": "^7.12.0",
70
- "eslint": "^8.21.0",
68
+ "@types/node": "^16.11.48",
69
+ "@typescript-eslint/eslint-plugin": "^5.33.0",
70
+ "@typescript-eslint/parser": "^5.33.0",
71
+ "@vitest/coverage-c8": "^0.22.0",
72
+ "eslint": "^8.22.0",
73
+ "eslint-config-marine": "^9.4.1",
74
+ "eslint-config-prettier": "^8.5.0",
75
+ "eslint-import-resolver-typescript": "^3.4.1",
76
+ "eslint-plugin-import": "^2.26.0",
71
77
  "mock-socket": "^9.1.5",
72
78
  "prettier": "^2.7.1",
73
79
  "rollup-plugin-typescript2": "0.32.1",
74
80
  "typescript": "^4.7.4",
75
- "unbuild": "^0.8.4",
81
+ "unbuild": "^0.8.8",
76
82
  "undici": "^5.8.2",
77
- "vitest": "^0.21.1",
83
+ "vitest": "^0.22.0",
78
84
  "zlib-sync": "^0.1.7"
79
85
  },
80
86
  "engines": {