@discordjs/voice 0.5.4 → 0.7.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.
- package/LICENSE +190 -21
- package/README.md +41 -18
- package/dist/index.d.ts +357 -216
- package/dist/index.js +10 -26
- package/dist/index.js.map +7 -1
- package/dist/index.mjs +10 -0
- package/dist/index.mjs.map +7 -0
- package/package.json +67 -93
- package/dist/DataStore.js +0 -151
- package/dist/DataStore.js.map +0 -1
- package/dist/VoiceConnection.js +0 -494
- package/dist/VoiceConnection.js.map +0 -1
- package/dist/audio/AudioPlayer.js +0 -449
- package/dist/audio/AudioPlayer.js.map +0 -1
- package/dist/audio/AudioPlayerError.js +0 -17
- package/dist/audio/AudioPlayerError.js.map +0 -1
- package/dist/audio/AudioResource.js +0 -164
- package/dist/audio/AudioResource.js.map +0 -1
- package/dist/audio/PlayerSubscription.js +0 -23
- package/dist/audio/PlayerSubscription.js.map +0 -1
- package/dist/audio/TransformerGraph.js +0 -233
- package/dist/audio/TransformerGraph.js.map +0 -1
- package/dist/audio/index.js +0 -18
- package/dist/audio/index.js.map +0 -1
- package/dist/joinVoiceChannel.js +0 -24
- package/dist/joinVoiceChannel.js.map +0 -1
- package/dist/networking/Networking.js +0 -457
- package/dist/networking/Networking.js.map +0 -1
- package/dist/networking/VoiceUDPSocket.js +0 -145
- package/dist/networking/VoiceUDPSocket.js.map +0 -1
- package/dist/networking/VoiceWebSocket.js +0 -129
- package/dist/networking/VoiceWebSocket.js.map +0 -1
- package/dist/networking/index.js +0 -16
- package/dist/networking/index.js.map +0 -1
- package/dist/receive/AudioReceiveStream.js +0 -20
- package/dist/receive/AudioReceiveStream.js.map +0 -1
- package/dist/receive/SSRCMap.js +0 -67
- package/dist/receive/SSRCMap.js.map +0 -1
- package/dist/receive/VoiceReceiver.js +0 -215
- package/dist/receive/VoiceReceiver.js.map +0 -1
- package/dist/receive/index.js +0 -16
- package/dist/receive/index.js.map +0 -1
- package/dist/util/Secretbox.js +0 -50
- package/dist/util/Secretbox.js.map +0 -1
- package/dist/util/adapter.js +0 -3
- package/dist/util/adapter.js.map +0 -1
- package/dist/util/demuxProbe.js +0 -90
- package/dist/util/demuxProbe.js.map +0 -1
- package/dist/util/entersState.js +0 -30
- package/dist/util/entersState.js.map +0 -1
- package/dist/util/generateDependencyReport.js +0 -82
- package/dist/util/generateDependencyReport.js.map +0 -1
- package/dist/util/index.js +0 -17
- package/dist/util/index.js.map +0 -1
- package/dist/util/util.js +0 -7
- package/dist/util/util.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,24 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
import { Readable, ReadableOptions } from 'stream';
|
|
1
|
+
import { Readable, ReadableOptions } from 'node:stream';
|
|
3
2
|
import { VolumeTransformer, opus } from 'prism-media';
|
|
4
3
|
import { TypedEmitter } from 'tiny-typed-emitter';
|
|
5
|
-
import { GatewayVoiceServerUpdateDispatchData, GatewayVoiceStateUpdateDispatchData } from 'discord-api-types/
|
|
4
|
+
import { GatewayVoiceServerUpdateDispatchData, GatewayVoiceStateUpdateDispatchData } from 'discord-api-types/v9';
|
|
6
5
|
import WebSocket, { MessageEvent } from 'ws';
|
|
7
6
|
|
|
8
7
|
declare type Awaited<T> = T | Promise<T>;
|
|
9
8
|
|
|
10
9
|
/**
|
|
11
|
-
* The different types of stream that can exist within the pipeline
|
|
10
|
+
* The different types of stream that can exist within the pipeline.
|
|
12
11
|
*
|
|
13
12
|
* @remarks
|
|
14
13
|
* - `Arbitrary` - the type of the stream at this point is unknown.
|
|
15
|
-
*
|
|
16
14
|
* - `Raw` - the stream at this point is s16le PCM.
|
|
17
|
-
*
|
|
18
15
|
* - `OggOpus` - the stream at this point is Opus audio encoded in an Ogg wrapper.
|
|
19
|
-
*
|
|
20
16
|
* - `WebmOpus` - the stream at this point is Opus audio encoded in a WebM wrapper.
|
|
21
|
-
*
|
|
22
17
|
* - `Opus` - the stream at this point is Opus audio, and the stream is in object-mode. This is ready to play.
|
|
23
18
|
*/
|
|
24
19
|
declare enum StreamType {
|
|
@@ -29,7 +24,7 @@ declare enum StreamType {
|
|
|
29
24
|
Opus = "opus"
|
|
30
25
|
}
|
|
31
26
|
/**
|
|
32
|
-
* The different types of transformers that can exist within the pipeline
|
|
27
|
+
* The different types of transformers that can exist within the pipeline.
|
|
33
28
|
*/
|
|
34
29
|
declare enum TransformerType {
|
|
35
30
|
FFmpegPCM = "ffmpeg pcm",
|
|
@@ -41,7 +36,7 @@ declare enum TransformerType {
|
|
|
41
36
|
InlineVolume = "volume transformer"
|
|
42
37
|
}
|
|
43
38
|
/**
|
|
44
|
-
* Represents a pathway from one stream type to another using a transformer
|
|
39
|
+
* Represents a pathway from one stream type to another using a transformer.
|
|
45
40
|
*/
|
|
46
41
|
interface Edge {
|
|
47
42
|
from: Node;
|
|
@@ -55,16 +50,16 @@ interface Edge {
|
|
|
55
50
|
*/
|
|
56
51
|
declare class Node {
|
|
57
52
|
/**
|
|
58
|
-
* The outbound edges from this node
|
|
53
|
+
* The outbound edges from this node.
|
|
59
54
|
*/
|
|
60
55
|
readonly edges: Edge[];
|
|
61
56
|
/**
|
|
62
|
-
* The type of stream for this node
|
|
57
|
+
* The type of stream for this node.
|
|
63
58
|
*/
|
|
64
59
|
readonly type: StreamType;
|
|
65
60
|
constructor(type: StreamType);
|
|
66
61
|
/**
|
|
67
|
-
* Creates an outbound edge from this node
|
|
62
|
+
* Creates an outbound edge from this node.
|
|
68
63
|
*
|
|
69
64
|
* @param edge - The edge to create
|
|
70
65
|
*/
|
|
@@ -74,7 +69,7 @@ declare class Node {
|
|
|
74
69
|
/**
|
|
75
70
|
* Options that are set when creating a new audio resource.
|
|
76
71
|
*
|
|
77
|
-
* @template T - the type for the metadata (if any) of the audio resource
|
|
72
|
+
* @template T - the type for the metadata (if any) of the audio resource
|
|
78
73
|
*/
|
|
79
74
|
interface CreateAudioResourceOptions<T> {
|
|
80
75
|
/**
|
|
@@ -82,7 +77,7 @@ interface CreateAudioResourceOptions<T> {
|
|
|
82
77
|
*/
|
|
83
78
|
inputType?: StreamType;
|
|
84
79
|
/**
|
|
85
|
-
* Optional metadata that can be attached to the resource (e.g. track title, random
|
|
80
|
+
* Optional metadata that can be attached to the resource (e.g. track title, random id).
|
|
86
81
|
* This is useful for identification purposes when the resource is passed around in events.
|
|
87
82
|
* See {@link AudioResource.metadata}
|
|
88
83
|
*/
|
|
@@ -101,7 +96,7 @@ interface CreateAudioResourceOptions<T> {
|
|
|
101
96
|
/**
|
|
102
97
|
* Represents an audio resource that can be played by an audio player.
|
|
103
98
|
*
|
|
104
|
-
* @template T - the type for the metadata (if any) of the audio resource
|
|
99
|
+
* @template T - the type for the metadata (if any) of the audio resource
|
|
105
100
|
*/
|
|
106
101
|
declare class AudioResource<T = unknown> {
|
|
107
102
|
/**
|
|
@@ -161,15 +156,47 @@ declare class AudioResource<T = unknown> {
|
|
|
161
156
|
/**
|
|
162
157
|
* Attempts to read an Opus packet from the audio resource. If a packet is available, the playbackDuration
|
|
163
158
|
* is incremented.
|
|
164
|
-
*
|
|
159
|
+
*
|
|
165
160
|
* @remarks
|
|
166
161
|
* It is advisable to check that the playStream is readable before calling this method. While no runtime
|
|
167
162
|
* errors will be thrown, you should check that the resource is still available before attempting to
|
|
168
163
|
* read from it.
|
|
164
|
+
*
|
|
165
|
+
* @internal
|
|
169
166
|
*/
|
|
170
167
|
read(): Buffer | null;
|
|
171
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* Creates an audio resource that can be played by audio players.
|
|
171
|
+
*
|
|
172
|
+
* @remarks
|
|
173
|
+
* If the input is given as a string, then the inputType option will be overridden and FFmpeg will be used.
|
|
174
|
+
*
|
|
175
|
+
* If the input is not in the correct format, then a pipeline of transcoders and transformers will be created
|
|
176
|
+
* to ensure that the resultant stream is in the correct format for playback. This could involve using FFmpeg,
|
|
177
|
+
* Opus transcoders, and Ogg/WebM demuxers.
|
|
178
|
+
*
|
|
179
|
+
* @param input - The resource to play
|
|
180
|
+
* @param options - Configurable options for creating the resource
|
|
181
|
+
*
|
|
182
|
+
* @template T - the type for the metadata (if any) of the audio resource
|
|
183
|
+
*/
|
|
172
184
|
declare function createAudioResource<T>(input: string | Readable, options: CreateAudioResourceOptions<T> & Pick<T extends null | undefined ? CreateAudioResourceOptions<T> : Required<CreateAudioResourceOptions<T>>, 'metadata'>): AudioResource<T extends null | undefined ? null : T>;
|
|
185
|
+
/**
|
|
186
|
+
* Creates an audio resource that can be played by audio players.
|
|
187
|
+
*
|
|
188
|
+
* @remarks
|
|
189
|
+
* If the input is given as a string, then the inputType option will be overridden and FFmpeg will be used.
|
|
190
|
+
*
|
|
191
|
+
* If the input is not in the correct format, then a pipeline of transcoders and transformers will be created
|
|
192
|
+
* to ensure that the resultant stream is in the correct format for playback. This could involve using FFmpeg,
|
|
193
|
+
* Opus transcoders, and Ogg/WebM demuxers.
|
|
194
|
+
*
|
|
195
|
+
* @param input - The resource to play
|
|
196
|
+
* @param options - Configurable options for creating the resource
|
|
197
|
+
*
|
|
198
|
+
* @template T - the type for the metadata (if any) of the audio resource
|
|
199
|
+
*/
|
|
173
200
|
declare function createAudioResource<T extends null | undefined>(input: string | Readable, options?: Omit<CreateAudioResourceOptions<T>, 'metadata'>): AudioResource<null>;
|
|
174
201
|
|
|
175
202
|
/**
|
|
@@ -190,11 +217,11 @@ declare class AudioPlayerError extends Error {
|
|
|
190
217
|
*/
|
|
191
218
|
declare class PlayerSubscription {
|
|
192
219
|
/**
|
|
193
|
-
* The voice connection of this subscription
|
|
220
|
+
* The voice connection of this subscription.
|
|
194
221
|
*/
|
|
195
222
|
readonly connection: VoiceConnection;
|
|
196
223
|
/**
|
|
197
|
-
* The audio player of this subscription
|
|
224
|
+
* The audio player of this subscription.
|
|
198
225
|
*/
|
|
199
226
|
readonly player: AudioPlayer;
|
|
200
227
|
constructor(connection: VoiceConnection, player: AudioPlayer);
|
|
@@ -211,33 +238,33 @@ declare class PlayerSubscription {
|
|
|
211
238
|
*/
|
|
212
239
|
declare enum NoSubscriberBehavior {
|
|
213
240
|
/**
|
|
214
|
-
* Pauses playing the stream until a voice connection becomes available
|
|
241
|
+
* Pauses playing the stream until a voice connection becomes available.
|
|
215
242
|
*/
|
|
216
243
|
Pause = "pause",
|
|
217
244
|
/**
|
|
218
|
-
* Continues to play through the resource regardless
|
|
245
|
+
* Continues to play through the resource regardless.
|
|
219
246
|
*/
|
|
220
247
|
Play = "play",
|
|
221
248
|
/**
|
|
222
|
-
* The player stops and enters the Idle state
|
|
249
|
+
* The player stops and enters the Idle state.
|
|
223
250
|
*/
|
|
224
251
|
Stop = "stop"
|
|
225
252
|
}
|
|
226
253
|
declare enum AudioPlayerStatus {
|
|
227
254
|
/**
|
|
228
|
-
* When there is currently no resource for the player to be playing
|
|
255
|
+
* When there is currently no resource for the player to be playing.
|
|
229
256
|
*/
|
|
230
257
|
Idle = "idle",
|
|
231
258
|
/**
|
|
232
|
-
* When the player is waiting for an audio resource to become readable before transitioning to Playing
|
|
259
|
+
* When the player is waiting for an audio resource to become readable before transitioning to Playing.
|
|
233
260
|
*/
|
|
234
261
|
Buffering = "buffering",
|
|
235
262
|
/**
|
|
236
|
-
* When the player has been manually paused
|
|
263
|
+
* When the player has been manually paused.
|
|
237
264
|
*/
|
|
238
265
|
Paused = "paused",
|
|
239
266
|
/**
|
|
240
|
-
* When the player is actively playing an audio resource
|
|
267
|
+
* When the player is actively playing an audio resource.
|
|
241
268
|
*/
|
|
242
269
|
Playing = "playing",
|
|
243
270
|
/**
|
|
@@ -292,7 +319,7 @@ interface AudioPlayerPlayingState {
|
|
|
292
319
|
*/
|
|
293
320
|
playbackDuration: number;
|
|
294
321
|
/**
|
|
295
|
-
* The resource that is being played
|
|
322
|
+
* The resource that is being played.
|
|
296
323
|
*/
|
|
297
324
|
resource: AudioResource;
|
|
298
325
|
onStreamError: (error: Error) => void;
|
|
@@ -304,7 +331,7 @@ interface AudioPlayerPlayingState {
|
|
|
304
331
|
interface AudioPlayerPausedState {
|
|
305
332
|
status: AudioPlayerStatus.Paused | AudioPlayerStatus.AutoPaused;
|
|
306
333
|
/**
|
|
307
|
-
* How many silence packets still need to be played to avoid audio interpolation due to the stream suddenly pausing
|
|
334
|
+
* How many silence packets still need to be played to avoid audio interpolation due to the stream suddenly pausing.
|
|
308
335
|
*/
|
|
309
336
|
silencePacketsRemaining: number;
|
|
310
337
|
/**
|
|
@@ -313,7 +340,7 @@ interface AudioPlayerPausedState {
|
|
|
313
340
|
*/
|
|
314
341
|
playbackDuration: number;
|
|
315
342
|
/**
|
|
316
|
-
* The current resource of the audio player
|
|
343
|
+
* The current resource of the audio player.
|
|
317
344
|
*/
|
|
318
345
|
resource: AudioResource;
|
|
319
346
|
onStreamError: (error: Error) => void;
|
|
@@ -345,7 +372,7 @@ declare type AudioPlayerEvents = {
|
|
|
345
372
|
*/
|
|
346
373
|
declare class AudioPlayer extends TypedEmitter<AudioPlayerEvents> {
|
|
347
374
|
/**
|
|
348
|
-
* The state that the AudioPlayer is in
|
|
375
|
+
* The state that the AudioPlayer is in.
|
|
349
376
|
*/
|
|
350
377
|
private _state;
|
|
351
378
|
/**
|
|
@@ -362,11 +389,11 @@ declare class AudioPlayer extends TypedEmitter<AudioPlayerEvents> {
|
|
|
362
389
|
*/
|
|
363
390
|
private readonly debug;
|
|
364
391
|
/**
|
|
365
|
-
* Creates a new AudioPlayer
|
|
392
|
+
* Creates a new AudioPlayer.
|
|
366
393
|
*/
|
|
367
394
|
constructor(options?: CreateAudioPlayerOptions);
|
|
368
395
|
/**
|
|
369
|
-
* A list of subscribed voice connections that can currently receive audio to play
|
|
396
|
+
* A list of subscribed voice connections that can currently receive audio to play.
|
|
370
397
|
*/
|
|
371
398
|
get playable(): VoiceConnection[];
|
|
372
399
|
/**
|
|
@@ -377,7 +404,8 @@ declare class AudioPlayer extends TypedEmitter<AudioPlayerEvents> {
|
|
|
377
404
|
* This method should not be directly called. Instead, use VoiceConnection#subscribe.
|
|
378
405
|
*
|
|
379
406
|
* @param connection - The connection to subscribe
|
|
380
|
-
*
|
|
407
|
+
*
|
|
408
|
+
* @returns The new subscription if the voice connection is not yet subscribed, otherwise the existing subscription
|
|
381
409
|
*/
|
|
382
410
|
private subscribe;
|
|
383
411
|
/**
|
|
@@ -387,7 +415,8 @@ declare class AudioPlayer extends TypedEmitter<AudioPlayerEvents> {
|
|
|
387
415
|
* This method should not be directly called. Instead, use PlayerSubscription#unsubscribe.
|
|
388
416
|
*
|
|
389
417
|
* @param subscription - The subscription to remove
|
|
390
|
-
*
|
|
418
|
+
*
|
|
419
|
+
* @returns Whether or not the subscription existed on the player and was removed
|
|
391
420
|
*/
|
|
392
421
|
private unsubscribe;
|
|
393
422
|
/**
|
|
@@ -410,34 +439,37 @@ declare class AudioPlayer extends TypedEmitter<AudioPlayerEvents> {
|
|
|
410
439
|
* Idle state during the swap over.
|
|
411
440
|
*
|
|
412
441
|
* @param resource - The resource to play
|
|
413
|
-
*
|
|
442
|
+
*
|
|
443
|
+
* @throws Will throw if attempting to play an audio resource that has already ended, or is being played by another player
|
|
414
444
|
*/
|
|
415
445
|
play<T>(resource: AudioResource<T>): void;
|
|
416
446
|
/**
|
|
417
447
|
* Pauses playback of the current resource, if any.
|
|
418
448
|
*
|
|
419
|
-
* @param interpolateSilence - If true, the player will play 5 packets of silence after pausing to prevent audio glitches
|
|
420
|
-
*
|
|
449
|
+
* @param interpolateSilence - If true, the player will play 5 packets of silence after pausing to prevent audio glitches
|
|
450
|
+
*
|
|
451
|
+
* @returns `true` if the player was successfully paused, otherwise `false`
|
|
421
452
|
*/
|
|
422
453
|
pause(interpolateSilence?: boolean): boolean;
|
|
423
454
|
/**
|
|
424
455
|
* Unpauses playback of the current resource, if any.
|
|
425
456
|
*
|
|
426
|
-
* @returns true if the player was successfully unpaused, otherwise false
|
|
457
|
+
* @returns `true` if the player was successfully unpaused, otherwise `false`
|
|
427
458
|
*/
|
|
428
459
|
unpause(): boolean;
|
|
429
460
|
/**
|
|
430
461
|
* Stops playback of the current resource and destroys the resource. The player will either transition to the Idle state,
|
|
431
462
|
* or remain in its current state until the silence padding frames of the resource have been played.
|
|
432
463
|
*
|
|
433
|
-
* @param force - If true, will force the player to enter the Idle state even if the resource has silence padding frames
|
|
434
|
-
*
|
|
464
|
+
* @param force - If true, will force the player to enter the Idle state even if the resource has silence padding frames
|
|
465
|
+
*
|
|
466
|
+
* @returns `true` if the player will come to a stop, otherwise `false`
|
|
435
467
|
*/
|
|
436
468
|
stop(force?: boolean): boolean;
|
|
437
469
|
/**
|
|
438
|
-
* Checks whether the underlying resource (if any) is playable (readable)
|
|
470
|
+
* Checks whether the underlying resource (if any) is playable (readable)
|
|
439
471
|
*
|
|
440
|
-
* @returns true if the resource is playable, false
|
|
472
|
+
* @returns `true` if the resource is playable, otherwise `false`
|
|
441
473
|
*/
|
|
442
474
|
checkPlayable(): boolean;
|
|
443
475
|
/**
|
|
@@ -466,7 +498,7 @@ declare class AudioPlayer extends TypedEmitter<AudioPlayerEvents> {
|
|
|
466
498
|
private _preparePacket;
|
|
467
499
|
}
|
|
468
500
|
/**
|
|
469
|
-
* Creates a new AudioPlayer to be used
|
|
501
|
+
* Creates a new AudioPlayer to be used.
|
|
470
502
|
*/
|
|
471
503
|
declare function createAudioPlayer(options?: CreateAudioPlayerOptions): AudioPlayer;
|
|
472
504
|
|
|
@@ -480,15 +512,32 @@ interface JoinConfig {
|
|
|
480
512
|
/**
|
|
481
513
|
* Retrieves the map of group names to maps of voice connections. By default, all voice connections
|
|
482
514
|
* are created under the 'default' group.
|
|
515
|
+
*
|
|
483
516
|
* @returns The group map
|
|
484
517
|
*/
|
|
485
518
|
declare function getGroups(): Map<string, Map<string, VoiceConnection>>;
|
|
519
|
+
/**
|
|
520
|
+
* Retrieves all the voice connections under the 'default' group.
|
|
521
|
+
*
|
|
522
|
+
* @param group - The group to look up
|
|
523
|
+
*
|
|
524
|
+
* @returns The map of voice connections
|
|
525
|
+
*/
|
|
486
526
|
declare function getVoiceConnections(group?: 'default'): Map<string, VoiceConnection>;
|
|
527
|
+
/**
|
|
528
|
+
* Retrieves all the voice connections under the given group name.
|
|
529
|
+
*
|
|
530
|
+
* @param group - The group to look up
|
|
531
|
+
*
|
|
532
|
+
* @returns The map of voice connections
|
|
533
|
+
*/
|
|
487
534
|
declare function getVoiceConnections(group: string): Map<string, VoiceConnection> | undefined;
|
|
488
535
|
/**
|
|
489
|
-
* Finds a voice connection with the given guild
|
|
490
|
-
*
|
|
536
|
+
* Finds a voice connection with the given guild id and group. Defaults to the 'default' group.
|
|
537
|
+
*
|
|
538
|
+
* @param guildId - The guild id of the voice connection
|
|
491
539
|
* @param group - the group that the voice connection was registered with
|
|
540
|
+
*
|
|
492
541
|
* @returns The voice connection, if it exists
|
|
493
542
|
*/
|
|
494
543
|
declare function getVoiceConnection(guildId: string, group?: string): VoiceConnection | undefined;
|
|
@@ -523,7 +572,8 @@ interface DiscordGatewayAdapterImplementerMethods {
|
|
|
523
572
|
* Implement this method such that the given payload is sent to the main Discord gateway connection.
|
|
524
573
|
*
|
|
525
574
|
* @param payload - The payload to send to the main Discord gateway connection
|
|
526
|
-
*
|
|
575
|
+
*
|
|
576
|
+
* @returns `false` if the payload definitely failed to send - in this case, the voice connection disconnects
|
|
527
577
|
*/
|
|
528
578
|
sendPayload(payload: any): boolean;
|
|
529
579
|
/**
|
|
@@ -563,7 +613,7 @@ declare class VoiceUDPSocket extends TypedEmitter<VoiceUDPSocketEvents> {
|
|
|
563
613
|
*/
|
|
564
614
|
private readonly socket;
|
|
565
615
|
/**
|
|
566
|
-
* The socket details for Discord (remote)
|
|
616
|
+
* The socket details for Discord (remote)
|
|
567
617
|
*/
|
|
568
618
|
private readonly remote;
|
|
569
619
|
/**
|
|
@@ -571,19 +621,19 @@ declare class VoiceUDPSocket extends TypedEmitter<VoiceUDPSocketEvents> {
|
|
|
571
621
|
*/
|
|
572
622
|
private readonly keepAlives;
|
|
573
623
|
/**
|
|
574
|
-
* The counter used in the keep alive mechanism
|
|
624
|
+
* The counter used in the keep alive mechanism.
|
|
575
625
|
*/
|
|
576
626
|
private keepAliveCounter;
|
|
577
627
|
/**
|
|
578
|
-
* The buffer used to write the keep alive counter into
|
|
628
|
+
* The buffer used to write the keep alive counter into.
|
|
579
629
|
*/
|
|
580
630
|
private readonly keepAliveBuffer;
|
|
581
631
|
/**
|
|
582
|
-
* The Node.js interval for the keep-alive mechanism
|
|
632
|
+
* The Node.js interval for the keep-alive mechanism.
|
|
583
633
|
*/
|
|
584
634
|
private readonly keepAliveInterval;
|
|
585
635
|
/**
|
|
586
|
-
* The time taken to receive a response to keep alive messages
|
|
636
|
+
* The time taken to receive a response to keep alive messages.
|
|
587
637
|
*/
|
|
588
638
|
ping?: number;
|
|
589
639
|
/**
|
|
@@ -597,12 +647,13 @@ declare class VoiceUDPSocket extends TypedEmitter<VoiceUDPSocketEvents> {
|
|
|
597
647
|
*/
|
|
598
648
|
constructor(remote: SocketConfig, debug?: boolean);
|
|
599
649
|
/**
|
|
600
|
-
* Called when a message is received on the UDP socket
|
|
650
|
+
* Called when a message is received on the UDP socket.
|
|
651
|
+
*
|
|
601
652
|
* @param buffer The received buffer
|
|
602
653
|
*/
|
|
603
654
|
private onMessage;
|
|
604
655
|
/**
|
|
605
|
-
* Called at a regular interval to check whether we are still able to send datagrams to Discord
|
|
656
|
+
* Called at a regular interval to check whether we are still able to send datagrams to Discord.
|
|
606
657
|
*/
|
|
607
658
|
private keepAlive;
|
|
608
659
|
/**
|
|
@@ -631,7 +682,7 @@ declare class VoiceUDPSocket extends TypedEmitter<VoiceUDPSocketEvents> {
|
|
|
631
682
|
*/
|
|
632
683
|
interface VoiceWebSocketEvents {
|
|
633
684
|
error: (error: Error) => Awaited<void>;
|
|
634
|
-
open: (event: WebSocket.
|
|
685
|
+
open: (event: WebSocket.Event) => Awaited<void>;
|
|
635
686
|
close: (event: WebSocket.CloseEvent) => Awaited<void>;
|
|
636
687
|
debug: (message: string) => Awaited<void>;
|
|
637
688
|
packet: (packet: any) => Awaited<void>;
|
|
@@ -642,7 +693,7 @@ interface VoiceWebSocketEvents {
|
|
|
642
693
|
*/
|
|
643
694
|
declare class VoiceWebSocket extends TypedEmitter<VoiceWebSocketEvents> {
|
|
644
695
|
/**
|
|
645
|
-
* The current heartbeat interval, if any
|
|
696
|
+
* The current heartbeat interval, if any.
|
|
646
697
|
*/
|
|
647
698
|
private heartbeatInterval?;
|
|
648
699
|
/**
|
|
@@ -668,11 +719,11 @@ declare class VoiceWebSocket extends TypedEmitter<VoiceWebSocketEvents> {
|
|
|
668
719
|
*/
|
|
669
720
|
private readonly debug;
|
|
670
721
|
/**
|
|
671
|
-
* The underlying WebSocket of this wrapper
|
|
722
|
+
* The underlying WebSocket of this wrapper.
|
|
672
723
|
*/
|
|
673
724
|
private readonly ws;
|
|
674
725
|
/**
|
|
675
|
-
* Creates a new VoiceWebSocket
|
|
726
|
+
* Creates a new VoiceWebSocket.
|
|
676
727
|
*
|
|
677
728
|
* @param address - The address to connect to
|
|
678
729
|
*/
|
|
@@ -689,19 +740,19 @@ declare class VoiceWebSocket extends TypedEmitter<VoiceWebSocketEvents> {
|
|
|
689
740
|
*/
|
|
690
741
|
onMessage(event: MessageEvent): void;
|
|
691
742
|
/**
|
|
692
|
-
* Sends a JSON-stringifiable packet over the WebSocket
|
|
743
|
+
* Sends a JSON-stringifiable packet over the WebSocket.
|
|
693
744
|
*
|
|
694
745
|
* @param packet - The packet to send
|
|
695
746
|
*/
|
|
696
747
|
sendPacket(packet: any): void;
|
|
697
748
|
/**
|
|
698
|
-
* Sends a heartbeat over the WebSocket
|
|
749
|
+
* Sends a heartbeat over the WebSocket.
|
|
699
750
|
*/
|
|
700
751
|
private sendHeartbeat;
|
|
701
752
|
/**
|
|
702
|
-
* Sets/clears an interval to send heartbeats over the WebSocket
|
|
753
|
+
* Sets/clears an interval to send heartbeats over the WebSocket.
|
|
703
754
|
*
|
|
704
|
-
* @param ms - The interval in milliseconds. If negative, the interval will be unset
|
|
755
|
+
* @param ms - The interval in milliseconds. If negative, the interval will be unset
|
|
705
756
|
*/
|
|
706
757
|
setHeartbeatInterval(ms: number): void;
|
|
707
758
|
}
|
|
@@ -799,9 +850,9 @@ declare type NetworkingState = NetworkingOpeningWsState | NetworkingIdentifyingS
|
|
|
799
850
|
* and VOICE_STATE_UPDATE packets.
|
|
800
851
|
*/
|
|
801
852
|
interface ConnectionOptions {
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
853
|
+
serverId: string;
|
|
854
|
+
userId: string;
|
|
855
|
+
sessionId: string;
|
|
805
856
|
token: string;
|
|
806
857
|
endpoint: string;
|
|
807
858
|
}
|
|
@@ -878,11 +929,12 @@ declare class Networking extends TypedEmitter<NetworkingEvents> {
|
|
|
878
929
|
*/
|
|
879
930
|
private onWsClose;
|
|
880
931
|
/**
|
|
881
|
-
* Called when the UDP socket has closed itself if it has stopped receiving replies from Discord
|
|
932
|
+
* Called when the UDP socket has closed itself if it has stopped receiving replies from Discord.
|
|
882
933
|
*/
|
|
883
934
|
private onUdpClose;
|
|
884
935
|
/**
|
|
885
|
-
* Called when a packet is received on the connection's WebSocket
|
|
936
|
+
* Called when a packet is received on the connection's WebSocket.
|
|
937
|
+
*
|
|
886
938
|
* @param packet - The received packet
|
|
887
939
|
*/
|
|
888
940
|
private onWsPacket;
|
|
@@ -900,7 +952,7 @@ declare class Networking extends TypedEmitter<NetworkingEvents> {
|
|
|
900
952
|
private onUdpDebug;
|
|
901
953
|
/**
|
|
902
954
|
* Prepares an Opus packet for playback. This includes attaching metadata to it and encrypting it.
|
|
903
|
-
* It will be stored within the instance, and can be played by dispatchAudio()
|
|
955
|
+
* It will be stored within the instance, and can be played by dispatchAudio()
|
|
904
956
|
*
|
|
905
957
|
* @remarks
|
|
906
958
|
* Calling this method while there is already a prepared audio packet that has not yet been dispatched
|
|
@@ -908,7 +960,7 @@ declare class Networking extends TypedEmitter<NetworkingEvents> {
|
|
|
908
960
|
*
|
|
909
961
|
* @param opusPacket - The Opus packet to encrypt
|
|
910
962
|
*
|
|
911
|
-
* @returns The audio packet that was prepared
|
|
963
|
+
* @returns The audio packet that was prepared
|
|
912
964
|
*/
|
|
913
965
|
prepareAudioPacket(opusPacket: Buffer): Buffer | undefined;
|
|
914
966
|
/**
|
|
@@ -946,6 +998,205 @@ declare class Networking extends TypedEmitter<NetworkingEvents> {
|
|
|
946
998
|
private encryptOpusPacket;
|
|
947
999
|
}
|
|
948
1000
|
|
|
1001
|
+
/**
|
|
1002
|
+
* The different behaviors an audio receive stream can have for deciding when to end.
|
|
1003
|
+
*/
|
|
1004
|
+
declare enum EndBehaviorType {
|
|
1005
|
+
/**
|
|
1006
|
+
* The stream will only end when manually destroyed.
|
|
1007
|
+
*/
|
|
1008
|
+
Manual = 0,
|
|
1009
|
+
/**
|
|
1010
|
+
* The stream will end after a given time period of silence/no audio packets.
|
|
1011
|
+
*/
|
|
1012
|
+
AfterSilence = 1,
|
|
1013
|
+
/**
|
|
1014
|
+
* The stream will end after a given time period of no audio packets.
|
|
1015
|
+
*/
|
|
1016
|
+
AfterInactivity = 2
|
|
1017
|
+
}
|
|
1018
|
+
declare type EndBehavior = {
|
|
1019
|
+
behavior: EndBehaviorType.Manual;
|
|
1020
|
+
} | {
|
|
1021
|
+
behavior: EndBehaviorType.AfterSilence | EndBehaviorType.AfterInactivity;
|
|
1022
|
+
duration: number;
|
|
1023
|
+
};
|
|
1024
|
+
interface AudioReceiveStreamOptions extends ReadableOptions {
|
|
1025
|
+
end: EndBehavior;
|
|
1026
|
+
}
|
|
1027
|
+
declare function createDefaultAudioReceiveStreamOptions(): AudioReceiveStreamOptions;
|
|
1028
|
+
/**
|
|
1029
|
+
* A readable stream of Opus packets received from a specific entity
|
|
1030
|
+
* in a Discord voice connection.
|
|
1031
|
+
*/
|
|
1032
|
+
declare class AudioReceiveStream extends Readable {
|
|
1033
|
+
/**
|
|
1034
|
+
* The end behavior of the receive stream.
|
|
1035
|
+
*/
|
|
1036
|
+
readonly end: EndBehavior;
|
|
1037
|
+
private endTimeout?;
|
|
1038
|
+
constructor({ end, ...options }: AudioReceiveStreamOptions);
|
|
1039
|
+
push(buffer: Buffer | null): boolean;
|
|
1040
|
+
private renewEndTimeout;
|
|
1041
|
+
_read(): void;
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
/**
|
|
1045
|
+
* The events that a SpeakingMap can emit.
|
|
1046
|
+
*/
|
|
1047
|
+
interface SpeakingMapEvents {
|
|
1048
|
+
/**
|
|
1049
|
+
* Emitted when a user starts speaking.
|
|
1050
|
+
*/
|
|
1051
|
+
start: (userId: string) => Awaited<void>;
|
|
1052
|
+
/**
|
|
1053
|
+
* Emitted when a user stops speaking.
|
|
1054
|
+
*/
|
|
1055
|
+
end: (userId: string) => Awaited<void>;
|
|
1056
|
+
}
|
|
1057
|
+
/**
|
|
1058
|
+
* Tracks the speaking states of users in a voice channel.
|
|
1059
|
+
*/
|
|
1060
|
+
declare class SpeakingMap extends TypedEmitter<SpeakingMapEvents> {
|
|
1061
|
+
/**
|
|
1062
|
+
* The delay after a packet is received from a user until they're marked as not speaking anymore.
|
|
1063
|
+
*/
|
|
1064
|
+
static readonly DELAY = 100;
|
|
1065
|
+
/**
|
|
1066
|
+
* The currently speaking users, mapped to the milliseconds since UNIX epoch at which they started speaking.
|
|
1067
|
+
*/
|
|
1068
|
+
readonly users: Map<string, number>;
|
|
1069
|
+
private readonly speakingTimeouts;
|
|
1070
|
+
constructor();
|
|
1071
|
+
onPacket(userId: string): void;
|
|
1072
|
+
private startTimeout;
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
/**
|
|
1076
|
+
* The known data for a user in a Discord voice connection.
|
|
1077
|
+
*/
|
|
1078
|
+
interface VoiceUserData {
|
|
1079
|
+
/**
|
|
1080
|
+
* The SSRC of the user's audio stream.
|
|
1081
|
+
*/
|
|
1082
|
+
audioSSRC: number;
|
|
1083
|
+
/**
|
|
1084
|
+
* The SSRC of the user's video stream (if one exists)
|
|
1085
|
+
* Cannot be 0. If undefined, the user has no video stream.
|
|
1086
|
+
*/
|
|
1087
|
+
videoSSRC?: number;
|
|
1088
|
+
/**
|
|
1089
|
+
* The Discord user id of the user.
|
|
1090
|
+
*/
|
|
1091
|
+
userId: string;
|
|
1092
|
+
}
|
|
1093
|
+
/**
|
|
1094
|
+
* The events that an SSRCMap may emit.
|
|
1095
|
+
*/
|
|
1096
|
+
interface SSRCMapEvents {
|
|
1097
|
+
create: (newData: VoiceUserData) => Awaited<void>;
|
|
1098
|
+
update: (oldData: VoiceUserData | undefined, newData: VoiceUserData) => Awaited<void>;
|
|
1099
|
+
delete: (deletedData: VoiceUserData) => Awaited<void>;
|
|
1100
|
+
}
|
|
1101
|
+
/**
|
|
1102
|
+
* Maps audio SSRCs to data of users in voice connections.
|
|
1103
|
+
*/
|
|
1104
|
+
declare class SSRCMap extends TypedEmitter<SSRCMapEvents> {
|
|
1105
|
+
/**
|
|
1106
|
+
* The underlying map.
|
|
1107
|
+
*/
|
|
1108
|
+
private readonly map;
|
|
1109
|
+
constructor();
|
|
1110
|
+
/**
|
|
1111
|
+
* Updates the map with new user data
|
|
1112
|
+
*
|
|
1113
|
+
* @param data The data to update with
|
|
1114
|
+
*/
|
|
1115
|
+
update(data: VoiceUserData): void;
|
|
1116
|
+
/**
|
|
1117
|
+
* Gets the stored voice data of a user.
|
|
1118
|
+
*
|
|
1119
|
+
* @param target The target, either their user id or audio SSRC
|
|
1120
|
+
*/
|
|
1121
|
+
get(target: number | string): VoiceUserData | undefined;
|
|
1122
|
+
/**
|
|
1123
|
+
* Deletes the stored voice data about a user.
|
|
1124
|
+
*
|
|
1125
|
+
* @param target The target of the delete operation, either their audio SSRC or user id
|
|
1126
|
+
*
|
|
1127
|
+
* @returns The data that was deleted, if any
|
|
1128
|
+
*/
|
|
1129
|
+
delete(target: number | string): VoiceUserData | undefined;
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
/**
|
|
1133
|
+
* Attaches to a VoiceConnection, allowing you to receive audio packets from other
|
|
1134
|
+
* users that are speaking.
|
|
1135
|
+
*
|
|
1136
|
+
* @beta
|
|
1137
|
+
*/
|
|
1138
|
+
declare class VoiceReceiver {
|
|
1139
|
+
/**
|
|
1140
|
+
* The attached connection of this receiver.
|
|
1141
|
+
*/
|
|
1142
|
+
readonly voiceConnection: VoiceConnection;
|
|
1143
|
+
/**
|
|
1144
|
+
* Maps SSRCs to Discord user ids.
|
|
1145
|
+
*/
|
|
1146
|
+
readonly ssrcMap: SSRCMap;
|
|
1147
|
+
/**
|
|
1148
|
+
* The current audio subscriptions of this receiver.
|
|
1149
|
+
*/
|
|
1150
|
+
readonly subscriptions: Map<string, AudioReceiveStream>;
|
|
1151
|
+
/**
|
|
1152
|
+
* The connection data of the receiver.
|
|
1153
|
+
*
|
|
1154
|
+
* @internal
|
|
1155
|
+
*/
|
|
1156
|
+
connectionData: Partial<ConnectionData>;
|
|
1157
|
+
/**
|
|
1158
|
+
* The speaking map of the receiver.
|
|
1159
|
+
*/
|
|
1160
|
+
readonly speaking: SpeakingMap;
|
|
1161
|
+
constructor(voiceConnection: VoiceConnection);
|
|
1162
|
+
/**
|
|
1163
|
+
* Called when a packet is received on the attached connection's WebSocket.
|
|
1164
|
+
*
|
|
1165
|
+
* @param packet The received packet
|
|
1166
|
+
*
|
|
1167
|
+
* @internal
|
|
1168
|
+
*/
|
|
1169
|
+
onWsPacket(packet: any): void;
|
|
1170
|
+
private decrypt;
|
|
1171
|
+
/**
|
|
1172
|
+
* Parses an audio packet, decrypting it to yield an Opus packet.
|
|
1173
|
+
*
|
|
1174
|
+
* @param buffer The buffer to parse
|
|
1175
|
+
* @param mode The encryption mode
|
|
1176
|
+
* @param nonce The nonce buffer used by the connection for encryption
|
|
1177
|
+
* @param secretKey The secret key used by the connection for encryption
|
|
1178
|
+
*
|
|
1179
|
+
* @returns The parsed Opus packet
|
|
1180
|
+
*/
|
|
1181
|
+
private parsePacket;
|
|
1182
|
+
/**
|
|
1183
|
+
* Called when the UDP socket of the attached connection receives a message.
|
|
1184
|
+
*
|
|
1185
|
+
* @param msg The received message
|
|
1186
|
+
*
|
|
1187
|
+
* @internal
|
|
1188
|
+
*/
|
|
1189
|
+
onUdpMessage(msg: Buffer): void;
|
|
1190
|
+
/**
|
|
1191
|
+
* Creates a subscription for the given user id.
|
|
1192
|
+
*
|
|
1193
|
+
* @param target The id of the user to subscribe to
|
|
1194
|
+
*
|
|
1195
|
+
* @returns A readable stream of Opus packets received from the target
|
|
1196
|
+
*/
|
|
1197
|
+
subscribe(userId: string, options?: Partial<AudioReceiveStreamOptions>): AudioReceiveStream;
|
|
1198
|
+
}
|
|
1199
|
+
|
|
949
1200
|
/**
|
|
950
1201
|
* The various status codes a voice connection can hold at any one time.
|
|
951
1202
|
*/
|
|
@@ -959,7 +1210,7 @@ declare enum VoiceConnectionStatus {
|
|
|
959
1210
|
*/
|
|
960
1211
|
Connecting = "connecting",
|
|
961
1212
|
/**
|
|
962
|
-
* A voice connection has been established, and is ready to be used
|
|
1213
|
+
* A voice connection has been established, and is ready to be used.
|
|
963
1214
|
*/
|
|
964
1215
|
Ready = "ready",
|
|
965
1216
|
/**
|
|
@@ -1084,11 +1335,12 @@ declare class VoiceConnection extends TypedEmitter<VoiceConnectionEvents> {
|
|
|
1084
1335
|
*/
|
|
1085
1336
|
rejoinAttempts: number;
|
|
1086
1337
|
/**
|
|
1087
|
-
* The state of the voice connection
|
|
1338
|
+
* The state of the voice connection.
|
|
1088
1339
|
*/
|
|
1089
1340
|
private _state;
|
|
1090
1341
|
/**
|
|
1091
1342
|
* A configuration storing all the data needed to reconnect to a Guild's voice server.
|
|
1343
|
+
*
|
|
1092
1344
|
* @internal
|
|
1093
1345
|
*/
|
|
1094
1346
|
readonly joinConfig: JoinConfig;
|
|
@@ -1097,6 +1349,11 @@ declare class VoiceConnection extends TypedEmitter<VoiceConnectionEvents> {
|
|
|
1097
1349
|
* from the main Discord gateway after signalling to change the voice state.
|
|
1098
1350
|
*/
|
|
1099
1351
|
private readonly packets;
|
|
1352
|
+
/**
|
|
1353
|
+
* The receiver of this voice connection. You should join the voice channel with `selfDeaf` set
|
|
1354
|
+
* to false for this feature to work properly.
|
|
1355
|
+
*/
|
|
1356
|
+
readonly receiver: VoiceReceiver;
|
|
1100
1357
|
/**
|
|
1101
1358
|
* The debug logger function, if debugging is enabled.
|
|
1102
1359
|
*/
|
|
@@ -1109,7 +1366,7 @@ declare class VoiceConnection extends TypedEmitter<VoiceConnectionEvents> {
|
|
|
1109
1366
|
*/
|
|
1110
1367
|
constructor(joinConfig: JoinConfig, { debug, adapterCreator }: CreateVoiceConnectionOptions);
|
|
1111
1368
|
/**
|
|
1112
|
-
* The current state of the voice connection
|
|
1369
|
+
* The current state of the voice connection.
|
|
1113
1370
|
*/
|
|
1114
1371
|
get state(): VoiceConnectionState;
|
|
1115
1372
|
/**
|
|
@@ -1124,12 +1381,19 @@ declare class VoiceConnection extends TypedEmitter<VoiceConnectionEvents> {
|
|
|
1124
1381
|
*/
|
|
1125
1382
|
private addServerPacket;
|
|
1126
1383
|
/**
|
|
1127
|
-
* Registers a `VOICE_STATE_UPDATE` packet to the voice connection. Most importantly, it stores the
|
|
1384
|
+
* Registers a `VOICE_STATE_UPDATE` packet to the voice connection. Most importantly, it stores the id of the
|
|
1128
1385
|
* channel that the client is connected to.
|
|
1129
1386
|
*
|
|
1130
1387
|
* @param packet - The received `VOICE_STATE_UPDATE` packet
|
|
1131
1388
|
*/
|
|
1132
1389
|
private addStatePacket;
|
|
1390
|
+
/**
|
|
1391
|
+
* Called when the networking state changes, and the new ws/udp packet/message handlers need to be rebound
|
|
1392
|
+
* to the new instances.
|
|
1393
|
+
* @param newState - The new networking state
|
|
1394
|
+
* @param oldState - The old networking state, if there is one
|
|
1395
|
+
*/
|
|
1396
|
+
private updateReceiveBindings;
|
|
1133
1397
|
/**
|
|
1134
1398
|
* Attempts to configure a networking instance for this voice connection using the received packets.
|
|
1135
1399
|
* Both packets are required, and any existing networking instance will be destroyed.
|
|
@@ -1175,7 +1439,7 @@ declare class VoiceConnection extends TypedEmitter<VoiceConnectionEvents> {
|
|
|
1175
1439
|
*/
|
|
1176
1440
|
private onNetworkingDebug;
|
|
1177
1441
|
/**
|
|
1178
|
-
* Prepares an audio packet for dispatch
|
|
1442
|
+
* Prepares an audio packet for dispatch.
|
|
1179
1443
|
*
|
|
1180
1444
|
* @param buffer - The Opus packet to prepare
|
|
1181
1445
|
*/
|
|
@@ -1185,7 +1449,7 @@ declare class VoiceConnection extends TypedEmitter<VoiceConnectionEvents> {
|
|
|
1185
1449
|
*/
|
|
1186
1450
|
dispatchAudio(): boolean | undefined;
|
|
1187
1451
|
/**
|
|
1188
|
-
* Prepares an audio packet and dispatches it immediately
|
|
1452
|
+
* Prepares an audio packet and dispatches it immediately.
|
|
1189
1453
|
*
|
|
1190
1454
|
* @param buffer - The Opus packet to play
|
|
1191
1455
|
*/
|
|
@@ -1194,12 +1458,14 @@ declare class VoiceConnection extends TypedEmitter<VoiceConnectionEvents> {
|
|
|
1194
1458
|
* Destroys the VoiceConnection, preventing it from connecting to voice again.
|
|
1195
1459
|
* This method should be called when you no longer require the VoiceConnection to
|
|
1196
1460
|
* prevent memory leaks.
|
|
1461
|
+
*
|
|
1197
1462
|
* @param adapterAvailable - Whether the adapter can be used
|
|
1198
1463
|
*/
|
|
1199
1464
|
destroy(adapterAvailable?: boolean): void;
|
|
1200
1465
|
/**
|
|
1201
1466
|
* Disconnects the VoiceConnection, allowing the possibility of rejoining later on.
|
|
1202
|
-
*
|
|
1467
|
+
*
|
|
1468
|
+
* @returns `true` if the connection was successfully disconnected
|
|
1203
1469
|
*/
|
|
1204
1470
|
disconnect(): boolean;
|
|
1205
1471
|
/**
|
|
@@ -1219,11 +1485,12 @@ declare class VoiceConnection extends TypedEmitter<VoiceConnectionEvents> {
|
|
|
1219
1485
|
*
|
|
1220
1486
|
* @param enabled - Whether or not to show as speaking
|
|
1221
1487
|
*/
|
|
1222
|
-
setSpeaking(enabled: boolean): false |
|
|
1488
|
+
setSpeaking(enabled: boolean): false | void;
|
|
1223
1489
|
/**
|
|
1224
1490
|
* Subscribes to an audio player, allowing the player to play audio on this voice connection.
|
|
1225
1491
|
*
|
|
1226
1492
|
* @param player - The audio player to subscribe to
|
|
1493
|
+
*
|
|
1227
1494
|
* @returns The created subscription
|
|
1228
1495
|
*/
|
|
1229
1496
|
subscribe(player: AudioPlayer): PlayerSubscription | undefined;
|
|
@@ -1263,11 +1530,11 @@ interface CreateVoiceConnectionOptions {
|
|
|
1263
1530
|
*/
|
|
1264
1531
|
interface JoinVoiceChannelOptions {
|
|
1265
1532
|
/**
|
|
1266
|
-
* The
|
|
1533
|
+
* The id of the Discord voice channel to join.
|
|
1267
1534
|
*/
|
|
1268
1535
|
channelId: string;
|
|
1269
1536
|
/**
|
|
1270
|
-
* The
|
|
1537
|
+
* The id of the guild that the voice channel belongs to.
|
|
1271
1538
|
*/
|
|
1272
1539
|
guildId: string;
|
|
1273
1540
|
/**
|
|
@@ -1279,7 +1546,7 @@ interface JoinVoiceChannelOptions {
|
|
|
1279
1546
|
*/
|
|
1280
1547
|
selfMute?: boolean;
|
|
1281
1548
|
/**
|
|
1282
|
-
* An optional group identifier for the voice connection
|
|
1549
|
+
* An optional group identifier for the voice connection.
|
|
1283
1550
|
*/
|
|
1284
1551
|
group?: string;
|
|
1285
1552
|
}
|
|
@@ -1302,22 +1569,24 @@ declare function generateDependencyReport(): string;
|
|
|
1302
1569
|
*
|
|
1303
1570
|
* @param target - The voice connection that we want to observe the state change for
|
|
1304
1571
|
* @param status - The status that the voice connection should be in
|
|
1305
|
-
* @param
|
|
1572
|
+
* @param timeoutOrSignal - The maximum time we are allowing for this to occur, or a signal that will abort the operation
|
|
1306
1573
|
*/
|
|
1307
|
-
declare function entersState(target: VoiceConnection, status: VoiceConnectionStatus,
|
|
1574
|
+
declare function entersState(target: VoiceConnection, status: VoiceConnectionStatus, timeoutOrSignal: number | AbortSignal): Promise<VoiceConnection>;
|
|
1308
1575
|
/**
|
|
1309
1576
|
* Allows an audio player a specified amount of time to enter a given state, otherwise rejects with an error.
|
|
1310
1577
|
*
|
|
1311
1578
|
* @param target - The audio player that we want to observe the state change for
|
|
1312
1579
|
* @param status - The status that the audio player should be in
|
|
1313
|
-
* @param
|
|
1580
|
+
* @param timeoutOrSignal - The maximum time we are allowing for this to occur, or a signal that will abort the operation
|
|
1314
1581
|
*/
|
|
1315
|
-
declare function entersState(target: AudioPlayer, status: AudioPlayerStatus,
|
|
1582
|
+
declare function entersState(target: AudioPlayer, status: AudioPlayerStatus, timeoutOrSignal: number | AbortSignal): Promise<AudioPlayer>;
|
|
1316
1583
|
|
|
1317
1584
|
/**
|
|
1318
1585
|
* Takes an Opus Head, and verifies whether the associated Opus audio is suitable to play in a Discord voice channel.
|
|
1586
|
+
*
|
|
1319
1587
|
* @param opusHead The Opus Head to validate
|
|
1320
|
-
*
|
|
1588
|
+
*
|
|
1589
|
+
* @returns `true` if suitable to play in a Discord voice channel, otherwise `false`
|
|
1321
1590
|
*/
|
|
1322
1591
|
declare function validateDiscordOpusHead(opusHead: Buffer): boolean;
|
|
1323
1592
|
/**
|
|
@@ -1330,147 +1599,19 @@ interface ProbeInfo {
|
|
|
1330
1599
|
*/
|
|
1331
1600
|
stream: Readable;
|
|
1332
1601
|
/**
|
|
1333
|
-
* The recommended stream type for this audio stream
|
|
1602
|
+
* The recommended stream type for this audio stream.
|
|
1334
1603
|
*/
|
|
1335
1604
|
type: StreamType;
|
|
1336
1605
|
}
|
|
1337
1606
|
/**
|
|
1338
1607
|
* Attempt to probe a readable stream to figure out whether it can be demuxed using an Ogg or WebM Opus demuxer.
|
|
1608
|
+
*
|
|
1339
1609
|
* @param stream The readable stream to probe
|
|
1340
1610
|
* @param probeSize The number of bytes to attempt to read before giving up on the probe
|
|
1341
1611
|
* @param validator The Opus Head validator function
|
|
1612
|
+
*
|
|
1342
1613
|
* @experimental
|
|
1343
1614
|
*/
|
|
1344
1615
|
declare function demuxProbe(stream: Readable, probeSize?: number, validator?: typeof validateDiscordOpusHead): Promise<ProbeInfo>;
|
|
1345
1616
|
|
|
1346
|
-
|
|
1347
|
-
* A readable stream of Opus packets received from a specific entity
|
|
1348
|
-
* in a Discord voice connection.
|
|
1349
|
-
*/
|
|
1350
|
-
declare class AudioReceiveStream extends Readable {
|
|
1351
|
-
constructor(options?: ReadableOptions);
|
|
1352
|
-
_read(): void;
|
|
1353
|
-
}
|
|
1354
|
-
|
|
1355
|
-
/**
|
|
1356
|
-
* The known data for a user in a Discord voice connection
|
|
1357
|
-
*/
|
|
1358
|
-
interface VoiceUserData {
|
|
1359
|
-
/**
|
|
1360
|
-
* The SSRC of the user's audio stream
|
|
1361
|
-
*/
|
|
1362
|
-
audioSSRC: number;
|
|
1363
|
-
/**
|
|
1364
|
-
* The SSRC of the user's video stream (if one exists).
|
|
1365
|
-
* Cannot be 0. If undefined, the user has no video stream.
|
|
1366
|
-
*/
|
|
1367
|
-
videoSSRC?: number;
|
|
1368
|
-
/**
|
|
1369
|
-
* The Discord user ID of the user
|
|
1370
|
-
*/
|
|
1371
|
-
userId: string;
|
|
1372
|
-
}
|
|
1373
|
-
/**
|
|
1374
|
-
* The events that an SSRCMap may emit.
|
|
1375
|
-
*/
|
|
1376
|
-
interface SSRCMapEvents {
|
|
1377
|
-
update: (oldData: VoiceUserData | undefined, newData: VoiceUserData) => Awaited<void>;
|
|
1378
|
-
delete: (deletedData: VoiceUserData) => Awaited<void>;
|
|
1379
|
-
}
|
|
1380
|
-
/**
|
|
1381
|
-
* Maps audio SSRCs to data of users in voice connections.
|
|
1382
|
-
*/
|
|
1383
|
-
declare class SSRCMap extends TypedEmitter<SSRCMapEvents> {
|
|
1384
|
-
/**
|
|
1385
|
-
* The underlying map
|
|
1386
|
-
*/
|
|
1387
|
-
private readonly map;
|
|
1388
|
-
constructor();
|
|
1389
|
-
/**
|
|
1390
|
-
* Updates the map with new user data
|
|
1391
|
-
*
|
|
1392
|
-
* @param data The data to update with
|
|
1393
|
-
*/
|
|
1394
|
-
update(data: VoiceUserData): void;
|
|
1395
|
-
/**
|
|
1396
|
-
* Gets the stored voice data of a user.
|
|
1397
|
-
*
|
|
1398
|
-
* @param target The target, either their user ID or audio SSRC
|
|
1399
|
-
*/
|
|
1400
|
-
get(target: number | string): VoiceUserData | undefined;
|
|
1401
|
-
/**
|
|
1402
|
-
* Deletes the stored voice data about a user.
|
|
1403
|
-
*
|
|
1404
|
-
* @param target The target of the delete operation, either their audio SSRC or user ID
|
|
1405
|
-
* @returns The data that was deleted, if any
|
|
1406
|
-
*/
|
|
1407
|
-
delete(target: number | string): VoiceUserData | undefined;
|
|
1408
|
-
}
|
|
1409
|
-
|
|
1410
|
-
/**
|
|
1411
|
-
* Attaches to a VoiceConnection, allowing you to receive audio packets from other
|
|
1412
|
-
* users that are speaking.
|
|
1413
|
-
*
|
|
1414
|
-
* @beta
|
|
1415
|
-
*/
|
|
1416
|
-
declare class VoiceReceiver {
|
|
1417
|
-
/**
|
|
1418
|
-
* The attached connection of this receiver.
|
|
1419
|
-
*/
|
|
1420
|
-
readonly voiceConnection: VoiceConnection;
|
|
1421
|
-
/**
|
|
1422
|
-
* Maps SSRCs to Discord user IDs.
|
|
1423
|
-
*/
|
|
1424
|
-
readonly ssrcMap: SSRCMap;
|
|
1425
|
-
/**
|
|
1426
|
-
* The current audio subscriptions of this receiver.
|
|
1427
|
-
*/
|
|
1428
|
-
readonly subscriptions: Map<number, AudioReceiveStream>;
|
|
1429
|
-
/**
|
|
1430
|
-
* The connection information for this receiver. Used to decrypt incoming packets.
|
|
1431
|
-
*/
|
|
1432
|
-
private connectionData;
|
|
1433
|
-
constructor(voiceConnection: VoiceConnection);
|
|
1434
|
-
/**
|
|
1435
|
-
* Called when a packet is received on the attached connection's WebSocket.
|
|
1436
|
-
*
|
|
1437
|
-
* @param packet The received packet
|
|
1438
|
-
*/
|
|
1439
|
-
private onWsPacket;
|
|
1440
|
-
private decrypt;
|
|
1441
|
-
/**
|
|
1442
|
-
* Parses an audio packet, decrypting it to yield an Opus packet.
|
|
1443
|
-
*
|
|
1444
|
-
* @param buffer The buffer to parse
|
|
1445
|
-
* @param mode The encryption mode
|
|
1446
|
-
* @param nonce The nonce buffer used by the connection for encryption
|
|
1447
|
-
* @param secretKey The secret key used by the connection for encryption
|
|
1448
|
-
* @returns The parsed Opus packet
|
|
1449
|
-
*/
|
|
1450
|
-
private parsePacket;
|
|
1451
|
-
/**
|
|
1452
|
-
* Called when the UDP socket of the attached connection receives a message.
|
|
1453
|
-
*
|
|
1454
|
-
* @param msg The received message
|
|
1455
|
-
*/
|
|
1456
|
-
private onUdpMessage;
|
|
1457
|
-
/**
|
|
1458
|
-
* Creates a subscription for the given target, specified either by their SSRC or user ID.
|
|
1459
|
-
*
|
|
1460
|
-
* @param target The audio SSRC or user ID to subscribe to
|
|
1461
|
-
* @returns A readable stream of Opus packets received from the target
|
|
1462
|
-
*/
|
|
1463
|
-
subscribe(target: string | number): AudioReceiveStream;
|
|
1464
|
-
}
|
|
1465
|
-
/**
|
|
1466
|
-
* Creates a new voice receiver for the given voice connection.
|
|
1467
|
-
*
|
|
1468
|
-
* @param voiceConnection The voice connection to attach to
|
|
1469
|
-
* @beta
|
|
1470
|
-
* @remarks
|
|
1471
|
-
* Voice receive is an undocumented part of the Discord API - voice receive is not guaranteed
|
|
1472
|
-
* to be stable and may break without notice.
|
|
1473
|
-
*/
|
|
1474
|
-
declare function createVoiceReceiver(voiceConnection: VoiceConnection): VoiceReceiver;
|
|
1475
|
-
|
|
1476
|
-
export { AudioPlayer, AudioPlayerBufferingState, AudioPlayerError, AudioPlayerEvents, AudioPlayerIdleState, AudioPlayerPausedState, AudioPlayerPlayingState, AudioPlayerState, AudioPlayerStatus, AudioReceiveStream, AudioResource, CreateAudioPlayerOptions, CreateVoiceConnectionOptions, DiscordGatewayAdapterCreator, DiscordGatewayAdapterImplementerMethods, DiscordGatewayAdapterLibraryMethods, JoinVoiceChannelOptions, NoSubscriberBehavior, PlayerSubscription, ProbeInfo, SSRCMap, SSRCMapEvents, StreamType, VoiceConnection, VoiceConnectionConnectingState, VoiceConnectionDestroyedState, VoiceConnectionDisconnectReason, VoiceConnectionDisconnectedBaseState, VoiceConnectionDisconnectedOtherState, VoiceConnectionDisconnectedState, VoiceConnectionDisconnectedWebSocketState, VoiceConnectionEvents, VoiceConnectionReadyState, VoiceConnectionSignallingState, VoiceConnectionState, VoiceConnectionStatus, VoiceReceiver, VoiceUserData, createAudioPlayer, createAudioResource, createVoiceReceiver, demuxProbe, entersState, generateDependencyReport, getGroups, getVoiceConnection, getVoiceConnections, joinVoiceChannel, validateDiscordOpusHead };
|
|
1617
|
+
export { AudioPlayer, AudioPlayerBufferingState, AudioPlayerError, AudioPlayerEvents, AudioPlayerIdleState, AudioPlayerPausedState, AudioPlayerPlayingState, AudioPlayerState, AudioPlayerStatus, AudioReceiveStream, AudioReceiveStreamOptions, AudioResource, CreateAudioPlayerOptions, CreateAudioResourceOptions, CreateVoiceConnectionOptions, DiscordGatewayAdapterCreator, DiscordGatewayAdapterImplementerMethods, DiscordGatewayAdapterLibraryMethods, EndBehavior, EndBehaviorType, JoinConfig, JoinVoiceChannelOptions, NoSubscriberBehavior, PlayerSubscription, ProbeInfo, SSRCMap, SSRCMapEvents, SpeakingMap, SpeakingMapEvents, StreamType, VoiceConnection, VoiceConnectionConnectingState, VoiceConnectionDestroyedState, VoiceConnectionDisconnectReason, VoiceConnectionDisconnectedBaseState, VoiceConnectionDisconnectedOtherState, VoiceConnectionDisconnectedState, VoiceConnectionDisconnectedWebSocketState, VoiceConnectionEvents, VoiceConnectionReadyState, VoiceConnectionSignallingState, VoiceConnectionState, VoiceConnectionStatus, VoiceReceiver, VoiceUserData, createAudioPlayer, createAudioResource, createDefaultAudioReceiveStreamOptions, demuxProbe, entersState, generateDependencyReport, getGroups, getVoiceConnection, getVoiceConnections, joinVoiceChannel, validateDiscordOpusHead };
|