@discordjs/ws
Advanced tools
Comparing version 3.0.0-dev.1736727181-101bef1c5 to 3.0.0-dev.1736769931-18ab0cf62
import * as _discordjs_util from '@discordjs/util'; | ||
import { Awaitable } from '@discordjs/util'; | ||
import { GatewayDispatchPayload, GatewayReadyDispatchData, GatewaySendPayload, GatewayOpcodes, GatewayIntentBits, GatewayIdentifyProperties, GatewayPresenceUpdateData, APIGatewayBotInfo } from 'discord-api-types/v10'; | ||
import { GatewayDispatchPayload, GatewayReadyDispatchData, GatewaySendPayload, GatewayOpcodes, GatewayIntentBits, RESTGetAPIGatewayBotResult, GatewayIdentifyProperties, GatewayPresenceUpdateData, APIGatewayBotInfo } from 'discord-api-types/v10'; | ||
import * as _discordjs_collection from '@discordjs/collection'; | ||
@@ -282,6 +282,2 @@ import { Collection } from '@discordjs/collection'; | ||
intents: GatewayIntentBits | 0; | ||
/** | ||
* The REST instance to use for fetching gateway information | ||
*/ | ||
rest: REST; | ||
} | ||
@@ -323,2 +319,17 @@ /** | ||
/** | ||
* Fetches the initial gateway URL used to connect to Discord. When missing, this will default to the gateway URL | ||
* that Discord returns from the `/gateway/bot` route. | ||
* | ||
* @example | ||
* ```ts | ||
* const manager = new WebSocketManager({ | ||
* token: process.env.DISCORD_TOKEN, | ||
* fetchGatewayInformation() { | ||
* return rest.get(Routes.gatewayBot()); | ||
* }, | ||
* }) | ||
* ``` | ||
*/ | ||
fetchGatewayInformation(): Awaitable<RESTGetAPIGatewayBotResult>; | ||
/** | ||
* How long to wait for a shard to connect before giving up | ||
@@ -348,2 +359,8 @@ */ | ||
/** | ||
* The REST instance to use for fetching gateway information | ||
* | ||
* @deprecated Providing a REST instance is deprecated. Provide the `fetchGatewayInformation` function instead. | ||
*/ | ||
rest?: REST; | ||
/** | ||
* Function used to retrieve session information (and attempt to resume) for a given shard | ||
@@ -350,0 +367,0 @@ * |
@@ -523,3 +523,3 @@ "use strict"; | ||
})(CompressionMethod || {}); | ||
var DefaultDeviceProperty = `@discordjs/ws 3.0.0-dev.1736727181-101bef1c5`; | ||
var DefaultDeviceProperty = `@discordjs/ws 3.0.0-dev.1736769931-18ab0cf62`; | ||
var getDefaultSessionStore = (0, import_util.lazy)(() => new import_collection4.Collection()); | ||
@@ -1485,4 +1485,16 @@ var CompressionParameterMap = { | ||
constructor(options) { | ||
if (!options.rest && !options.fetchGatewayInformation) { | ||
throw new RangeError("Either a REST instance or a fetchGatewayInformation function must be provided"); | ||
} | ||
super(); | ||
this.options = { ...DefaultWebSocketManagerOptions, ...options }; | ||
this.options = { | ||
...DefaultWebSocketManagerOptions, | ||
fetchGatewayInformation: options.fetchGatewayInformation ?? (async () => { | ||
if (!options.rest) { | ||
throw new RangeError("A REST instance must be provided if no fetchGatewayInformation function is provided"); | ||
} | ||
return options.rest.get(import_v103.Routes.gatewayBot()); | ||
}), | ||
...options | ||
}; | ||
this.strategy = this.options.buildStrategy(this); | ||
@@ -1504,3 +1516,3 @@ this.#token = options.token ?? null; | ||
} | ||
const data = await this.options.rest.get(import_v103.Routes.gatewayBot()); | ||
const data = await this.options.fetchGatewayInformation(); | ||
this.gatewayInformation = { data, expiresAt: Date.now() + (data.session_start_limit.reset_after || 5e3) }; | ||
@@ -1586,3 +1598,3 @@ return this.gatewayInformation.data; | ||
// src/index.ts | ||
var version = "3.0.0-dev.1736727181-101bef1c5"; | ||
var version = "3.0.0-dev.1736769931-18ab0cf62"; | ||
// Annotate the CommonJS export names for ESM import in node: | ||
@@ -1589,0 +1601,0 @@ 0 && (module.exports = { |
{ | ||
"$schema": "https://json.schemastore.org/package.json", | ||
"name": "@discordjs/ws", | ||
"version": "3.0.0-dev.1736727181-101bef1c5", | ||
"version": "3.0.0-dev.1736769931-18ab0cf62", | ||
"description": "Wrapper around Discord's gateway", | ||
@@ -71,5 +71,5 @@ "exports": { | ||
"ws": "^8.18.0", | ||
"@discordjs/rest": "^2.4.0", | ||
"@discordjs/util": "^1.1.1", | ||
"@discordjs/collection": "^2.1.1", | ||
"@discordjs/rest": "^2.4.0" | ||
"@discordjs/collection": "^2.1.1" | ||
}, | ||
@@ -76,0 +76,0 @@ "devDependencies": { |
@@ -45,2 +45,3 @@ <div align="center"> | ||
import { REST } from '@discordjs/rest'; | ||
import type { RESTGetAPIGatewayBotResult } from 'discord-api-types/v10'; | ||
@@ -52,3 +53,5 @@ const rest = new REST().setToken(process.env.DISCORD_TOKEN); | ||
intents: 0, // for no intents | ||
rest, | ||
fetchGatewayInformation() { | ||
return rest.get(Routes.gatewayBot()) as Promise<RESTGetAPIGatewayBotResult>; | ||
}, | ||
// uncomment if you have zlib-sync installed and want to use compression | ||
@@ -75,4 +78,6 @@ // compression: CompressionMethod.ZlibSync, | ||
intents: 0, | ||
rest, | ||
shardCount: 4, | ||
fetchGatewayInformation() { | ||
return rest.get(Routes.gatewayBot()) as Promise<RESTGetAPIGatewayBotResult>; | ||
}, | ||
}); | ||
@@ -87,5 +92,7 @@ | ||
intents: 0, | ||
rest, | ||
shardCount: 8, | ||
shardIds: [0, 2, 4, 6], | ||
fetchGatewayInformation() { | ||
return rest.get(Routes.gatewayBot()) as Promise<RESTGetAPIGatewayBotResult>; | ||
}, | ||
}); | ||
@@ -97,3 +104,2 @@ | ||
intents: 0, | ||
rest, | ||
shardCount: 8, | ||
@@ -104,2 +110,5 @@ shardIds: { | ||
}, | ||
fetchGatewayInformation() { | ||
return rest.get(Routes.gatewayBot()) as Promise<RESTGetAPIGatewayBotResult>; | ||
}, | ||
}); | ||
@@ -120,4 +129,6 @@ ``` | ||
intents: 0, | ||
rest, | ||
shardCount: 6, | ||
fetchGatewayInformation() { | ||
return rest.get(Routes.gatewayBot()) as Promise<RESTGetAPIGatewayBotResult>; | ||
}, | ||
// This will cause 3 workers to spawn, 2 shards per each | ||
@@ -140,3 +151,5 @@ buildStrategy: (manager) => new WorkerShardingStrategy(manager, { shardsPerWorker: 2 }), | ||
intents: 0, | ||
rest, | ||
fetchGatewayInformation() { | ||
return rest.get(Routes.gatewayBot()) as Promise<RESTGetAPIGatewayBotResult>; | ||
}, | ||
buildStrategy: (manager) => | ||
@@ -143,0 +156,0 @@ new WorkerShardingStrategy(manager, { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
656319
6135
221