-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
constants.ts
70 lines (63 loc) · 1.72 KB
/
constants.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import process from 'node:process';
import { Collection } from '@discordjs/collection';
import { lazy } from '@discordjs/util';
import { APIVersion, GatewayOpcodes } from 'discord-api-types/v10';
import type { SessionInfo, OptionalWebSocketManagerOptions } from '../ws/WebSocketManager.js';
import type { SendRateLimitState } from '../ws/WebSocketShard.js';
/**
* Valid encoding types
*/
export enum Encoding {
JSON = 'json',
}
/**
* Valid compression methods
*/
export enum CompressionMethod {
ZlibStream = 'zlib-stream',
}
export const DefaultDeviceProperty = `@discordjs/ws [VI]{{inject}}[/VI]`;
const getDefaultSessionStore = lazy(() => new Collection<number, SessionInfo | null>());
/**
* Default options used by the manager
*/
export const DefaultWebSocketManagerOptions = {
shardCount: null,
shardIds: null,
largeThreshold: null,
initialPresence: null,
identifyProperties: {
browser: DefaultDeviceProperty,
device: DefaultDeviceProperty,
os: process.platform,
},
version: APIVersion,
encoding: Encoding.JSON,
compression: null,
retrieveSessionInfo(shardId) {
const store = getDefaultSessionStore();
return store.get(shardId) ?? null;
},
updateSessionInfo(shardId: number, info: SessionInfo | null) {
const store = getDefaultSessionStore();
if (info) {
store.set(shardId, info);
} else {
store.delete(shardId);
}
},
handshakeTimeout: 30_000,
helloTimeout: 60_000,
readyTimeout: 15_000,
} as const satisfies OptionalWebSocketManagerOptions;
export const ImportantGatewayOpcodes = new Set([
GatewayOpcodes.Heartbeat,
GatewayOpcodes.Identify,
GatewayOpcodes.Resume,
]);
export function getInitialSendRateLimitState(): SendRateLimitState {
return {
remaining: 120,
resetAt: Date.now() + 60_000,
};
}