mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 00:23:30 +01:00
feat: add ws option support for "buildIdentifyThrottler" (#9728)
* feat: add option support for "buildIdentifyThrottler" * docs: add documentation for buildIdentifyThrottler * docs: fix example code
This commit is contained in:
@@ -155,6 +155,7 @@ class WebSocketManager extends EventEmitter {
|
||||
},
|
||||
compression: zlib ? CompressionMethod.ZlibStream : null,
|
||||
};
|
||||
if (ws.buildIdentifyThrottler) wsOptions.buildIdentifyThrottler = ws.buildIdentifyThrottler;
|
||||
if (ws.buildStrategy) wsOptions.buildStrategy = ws.buildStrategy;
|
||||
this._ws = new WSWebSocketManager(wsOptions);
|
||||
this.attachEvents();
|
||||
|
||||
@@ -67,6 +67,19 @@ const { version } = require('../../package.json');
|
||||
* @returns {IShardingStrategy} The strategy to use for sharding
|
||||
*/
|
||||
|
||||
/**
|
||||
* A function to change the concurrency handling for shard identifies of this manager
|
||||
* ```js
|
||||
* async (manager) => {
|
||||
* const gateway = await manager.fetchGatewayInformation();
|
||||
* return new SimpleIdentifyThrottler(gateway.session_start_limit.max_concurrency);
|
||||
* }
|
||||
* ```
|
||||
* @typedef {Function} IdentifyThrottlerFunction
|
||||
* @param {WSWebSocketManager} manager The WebSocketManager that is going to initiate the sharding
|
||||
* @returns {Awaitable<IIdentifyThrottler>} The identify throttler that this ws manager will use
|
||||
*/
|
||||
|
||||
/**
|
||||
* WebSocket options (these are left as snake_case to match the API)
|
||||
* @typedef {Object} WebsocketOptions
|
||||
@@ -75,6 +88,7 @@ const { version } = require('../../package.json');
|
||||
* @property {number} [version=10] The Discord gateway version to use <warn>Changing this can break the library;
|
||||
* only set this if you know what you are doing</warn>
|
||||
* @property {BuildStrategyFunction} [buildStrategy] Builds the strategy to use for sharding
|
||||
* @property {IdentifyThrottlerFunction} [buildIdentifyThrottler] Builds the identify throttler to use for sharding
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -214,3 +228,8 @@ module.exports = Options;
|
||||
* @external IShardingStrategy
|
||||
* @see {@link https://discord.js.org/docs/packages/ws/stable/IShardingStrategy:Interface}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @external IIdentifyThrottler
|
||||
* @see {@link https://discord.js.org/docs/packages/ws/stable/IIdentifyThrottler:Interface}
|
||||
*/
|
||||
|
||||
8
packages/discord.js/typings/index.d.ts
vendored
8
packages/discord.js/typings/index.d.ts
vendored
@@ -40,7 +40,12 @@ import {
|
||||
import { Awaitable, JSONEncodable } from '@discordjs/util';
|
||||
import { Collection } from '@discordjs/collection';
|
||||
import { BaseImageURLOptions, ImageURLOptions, RawFile, REST, RESTOptions } from '@discordjs/rest';
|
||||
import { WebSocketManager as WSWebSocketManager, IShardingStrategy, SessionInfo } from '@discordjs/ws';
|
||||
import {
|
||||
WebSocketManager as WSWebSocketManager,
|
||||
IShardingStrategy,
|
||||
IIdentifyThrottler,
|
||||
SessionInfo,
|
||||
} from '@discordjs/ws';
|
||||
import {
|
||||
APIActionRowComponent,
|
||||
APIApplicationCommandInteractionData,
|
||||
@@ -6388,6 +6393,7 @@ export interface WebSocketOptions {
|
||||
large_threshold?: number;
|
||||
version?: number;
|
||||
buildStrategy?(manager: WSWebSocketManager): IShardingStrategy;
|
||||
buildIdentifyThrottler?(manager: WSWebSocketManager): Awaitable<IIdentifyThrottler>;
|
||||
}
|
||||
|
||||
export interface WidgetActivity {
|
||||
|
||||
Reference in New Issue
Block a user