@discordjs/voice 0.12.1-dev.1662077413-8a91d7c.0 → 0.12.1-dev.1662336792-4ffdada.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.
Files changed (145) hide show
  1. package/dist/index.d.ts +1636 -7
  2. package/dist/index.js +2149 -0
  3. package/dist/index.js.map +1 -0
  4. package/dist/index.mjs +2101 -16
  5. package/dist/index.mjs.map +1 -1
  6. package/package.json +10 -11
  7. package/dist/DataStore.cjs +0 -102
  8. package/dist/DataStore.cjs.map +0 -1
  9. package/dist/DataStore.d.ts +0 -74
  10. package/dist/DataStore.d.ts.map +0 -1
  11. package/dist/DataStore.mjs +0 -90
  12. package/dist/DataStore.mjs.map +0 -1
  13. package/dist/VoiceConnection.cjs +0 -351
  14. package/dist/VoiceConnection.cjs.map +0 -1
  15. package/dist/VoiceConnection.d.ts +0 -353
  16. package/dist/VoiceConnection.d.ts.map +0 -1
  17. package/dist/VoiceConnection.mjs +0 -344
  18. package/dist/VoiceConnection.mjs.map +0 -1
  19. package/dist/audio/AudioPlayer.cjs +0 -289
  20. package/dist/audio/AudioPlayer.cjs.map +0 -1
  21. package/dist/audio/AudioPlayer.d.ts +0 -294
  22. package/dist/audio/AudioPlayer.d.ts.map +0 -1
  23. package/dist/audio/AudioPlayer.mjs +0 -281
  24. package/dist/audio/AudioPlayer.mjs.map +0 -1
  25. package/dist/audio/AudioPlayerError.cjs +0 -15
  26. package/dist/audio/AudioPlayerError.cjs.map +0 -1
  27. package/dist/audio/AudioPlayerError.d.ts +0 -13
  28. package/dist/audio/AudioPlayerError.d.ts.map +0 -1
  29. package/dist/audio/AudioPlayerError.mjs +0 -11
  30. package/dist/audio/AudioPlayerError.mjs.map +0 -1
  31. package/dist/audio/AudioResource.cjs +0 -109
  32. package/dist/audio/AudioResource.cjs.map +0 -1
  33. package/dist/audio/AudioResource.d.ts +0 -151
  34. package/dist/audio/AudioResource.d.ts.map +0 -1
  35. package/dist/audio/AudioResource.mjs +0 -97
  36. package/dist/audio/AudioResource.mjs.map +0 -1
  37. package/dist/audio/PlayerSubscription.cjs +0 -17
  38. package/dist/audio/PlayerSubscription.cjs.map +0 -1
  39. package/dist/audio/PlayerSubscription.d.ts +0 -23
  40. package/dist/audio/PlayerSubscription.d.ts.map +0 -1
  41. package/dist/audio/PlayerSubscription.mjs +0 -13
  42. package/dist/audio/PlayerSubscription.mjs.map +0 -1
  43. package/dist/audio/TransformerGraph.cjs +0 -160
  44. package/dist/audio/TransformerGraph.cjs.map +0 -1
  45. package/dist/audio/TransformerGraph.d.ts +0 -75
  46. package/dist/audio/TransformerGraph.d.ts.map +0 -1
  47. package/dist/audio/TransformerGraph.mjs +0 -148
  48. package/dist/audio/TransformerGraph.mjs.map +0 -1
  49. package/dist/audio/index.d.ts +0 -6
  50. package/dist/audio/index.d.ts.map +0 -1
  51. package/dist/index.cjs +0 -49
  52. package/dist/index.cjs.map +0 -1
  53. package/dist/index.d.ts.map +0 -1
  54. package/dist/joinVoiceChannel.cjs +0 -21
  55. package/dist/joinVoiceChannel.cjs.map +0 -1
  56. package/dist/joinVoiceChannel.d.ts +0 -44
  57. package/dist/joinVoiceChannel.d.ts.map +0 -1
  58. package/dist/joinVoiceChannel.mjs +0 -17
  59. package/dist/joinVoiceChannel.mjs.map +0 -1
  60. package/dist/networking/Networking.cjs +0 -309
  61. package/dist/networking/Networking.cjs.map +0 -1
  62. package/dist/networking/Networking.d.ts +0 -251
  63. package/dist/networking/Networking.d.ts.map +0 -1
  64. package/dist/networking/Networking.mjs +0 -303
  65. package/dist/networking/Networking.mjs.map +0 -1
  66. package/dist/networking/VoiceUDPSocket.cjs +0 -100
  67. package/dist/networking/VoiceUDPSocket.cjs.map +0 -1
  68. package/dist/networking/VoiceUDPSocket.d.ts +0 -94
  69. package/dist/networking/VoiceUDPSocket.d.ts.map +0 -1
  70. package/dist/networking/VoiceUDPSocket.mjs +0 -95
  71. package/dist/networking/VoiceUDPSocket.mjs.map +0 -1
  72. package/dist/networking/VoiceWebSocket.cjs +0 -91
  73. package/dist/networking/VoiceWebSocket.cjs.map +0 -1
  74. package/dist/networking/VoiceWebSocket.d.ts +0 -90
  75. package/dist/networking/VoiceWebSocket.d.ts.map +0 -1
  76. package/dist/networking/VoiceWebSocket.mjs +0 -83
  77. package/dist/networking/VoiceWebSocket.mjs.map +0 -1
  78. package/dist/networking/index.d.ts +0 -4
  79. package/dist/networking/index.d.ts.map +0 -1
  80. package/dist/receive/AudioReceiveStream.cjs +0 -48
  81. package/dist/receive/AudioReceiveStream.cjs.map +0 -1
  82. package/dist/receive/AudioReceiveStream.d.ts +0 -47
  83. package/dist/receive/AudioReceiveStream.d.ts.map +0 -1
  84. package/dist/receive/AudioReceiveStream.mjs +0 -42
  85. package/dist/receive/AudioReceiveStream.mjs.map +0 -1
  86. package/dist/receive/SSRCMap.cjs +0 -55
  87. package/dist/receive/SSRCMap.cjs.map +0 -1
  88. package/dist/receive/SSRCMap.d.ts +0 -55
  89. package/dist/receive/SSRCMap.d.ts.map +0 -1
  90. package/dist/receive/SSRCMap.mjs +0 -51
  91. package/dist/receive/SSRCMap.mjs.map +0 -1
  92. package/dist/receive/SpeakingMap.cjs +0 -38
  93. package/dist/receive/SpeakingMap.cjs.map +0 -1
  94. package/dist/receive/SpeakingMap.d.ts +0 -34
  95. package/dist/receive/SpeakingMap.d.ts.map +0 -1
  96. package/dist/receive/SpeakingMap.mjs +0 -34
  97. package/dist/receive/SpeakingMap.mjs.map +0 -1
  98. package/dist/receive/VoiceReceiver.cjs +0 -101
  99. package/dist/receive/VoiceReceiver.cjs.map +0 -1
  100. package/dist/receive/VoiceReceiver.d.ts +0 -71
  101. package/dist/receive/VoiceReceiver.d.ts.map +0 -1
  102. package/dist/receive/VoiceReceiver.mjs +0 -97
  103. package/dist/receive/VoiceReceiver.mjs.map +0 -1
  104. package/dist/receive/index.d.ts +0 -5
  105. package/dist/receive/index.d.ts.map +0 -1
  106. package/dist/util/Secretbox.cjs +0 -73
  107. package/dist/util/Secretbox.cjs.map +0 -1
  108. package/dist/util/Secretbox.d.ts +0 -10
  109. package/dist/util/Secretbox.d.ts.map +0 -1
  110. package/dist/util/Secretbox.mjs +0 -78
  111. package/dist/util/Secretbox.mjs.map +0 -1
  112. package/dist/util/abortAfter.cjs +0 -13
  113. package/dist/util/abortAfter.cjs.map +0 -1
  114. package/dist/util/abortAfter.d.ts +0 -8
  115. package/dist/util/abortAfter.d.ts.map +0 -1
  116. package/dist/util/abortAfter.mjs +0 -9
  117. package/dist/util/abortAfter.mjs.map +0 -1
  118. package/dist/util/adapter.d.ts +0 -48
  119. package/dist/util/adapter.d.ts.map +0 -1
  120. package/dist/util/demuxProbe.cjs +0 -98
  121. package/dist/util/demuxProbe.cjs.map +0 -1
  122. package/dist/util/demuxProbe.d.ts +0 -36
  123. package/dist/util/demuxProbe.d.ts.map +0 -1
  124. package/dist/util/demuxProbe.mjs +0 -88
  125. package/dist/util/demuxProbe.mjs.map +0 -1
  126. package/dist/util/entersState.cjs +0 -21
  127. package/dist/util/entersState.cjs.map +0 -1
  128. package/dist/util/entersState.d.ts +0 -20
  129. package/dist/util/entersState.d.ts.map +0 -1
  130. package/dist/util/entersState.mjs +0 -17
  131. package/dist/util/entersState.mjs.map +0 -1
  132. package/dist/util/generateDependencyReport.cjs +0 -62
  133. package/dist/util/generateDependencyReport.cjs.map +0 -1
  134. package/dist/util/generateDependencyReport.d.ts +0 -6
  135. package/dist/util/generateDependencyReport.d.ts.map +0 -1
  136. package/dist/util/generateDependencyReport.mjs +0 -63
  137. package/dist/util/generateDependencyReport.mjs.map +0 -1
  138. package/dist/util/index.d.ts +0 -5
  139. package/dist/util/index.d.ts.map +0 -1
  140. package/dist/util/util.cjs +0 -9
  141. package/dist/util/util.cjs.map +0 -1
  142. package/dist/util/util.d.ts +0 -2
  143. package/dist/util/util.d.ts.map +0 -1
  144. package/dist/util/util.mjs +0 -5
  145. package/dist/util/util.mjs.map +0 -1
package/dist/index.d.ts CHANGED
@@ -1,7 +1,1636 @@
1
- export * from './joinVoiceChannel';
2
- export * from './audio/index';
3
- export * from './util/index';
4
- export * from './receive/index';
5
- export { VoiceConnection, type VoiceConnectionState, VoiceConnectionStatus, type VoiceConnectionConnectingState, type VoiceConnectionDestroyedState, type VoiceConnectionDisconnectedState, type VoiceConnectionDisconnectedBaseState, type VoiceConnectionDisconnectedOtherState, type VoiceConnectionDisconnectedWebSocketState, VoiceConnectionDisconnectReason, type VoiceConnectionReadyState, type VoiceConnectionSignallingState, } from './VoiceConnection';
6
- export { type JoinConfig, getVoiceConnection, getVoiceConnections, getGroups } from './DataStore';
7
- //# sourceMappingURL=index.d.ts.map
1
+ import { Buffer } from 'node:buffer';
2
+ import { EventEmitter } from 'node:events';
3
+ import { Readable, ReadableOptions } from 'node:stream';
4
+ import prism from 'prism-media';
5
+ import WebSocket, { MessageEvent } from 'ws';
6
+ import { GatewayVoiceServerUpdateDispatchData, GatewayVoiceStateUpdateDispatchData } from 'discord-api-types/v10';
7
+
8
+ /**
9
+ * The different types of stream that can exist within the pipeline.
10
+ *
11
+ * @remarks
12
+ * - `Arbitrary` - the type of the stream at this point is unknown.
13
+ * - `Raw` - the stream at this point is s16le PCM.
14
+ * - `OggOpus` - the stream at this point is Opus audio encoded in an Ogg wrapper.
15
+ * - `WebmOpus` - the stream at this point is Opus audio encoded in a WebM wrapper.
16
+ * - `Opus` - the stream at this point is Opus audio, and the stream is in object-mode. This is ready to play.
17
+ */
18
+ declare enum StreamType {
19
+ Arbitrary = "arbitrary",
20
+ OggOpus = "ogg/opus",
21
+ Opus = "opus",
22
+ Raw = "raw",
23
+ WebmOpus = "webm/opus"
24
+ }
25
+ /**
26
+ * The different types of transformers that can exist within the pipeline.
27
+ */
28
+ declare enum TransformerType {
29
+ FFmpegOgg = "ffmpeg ogg",
30
+ FFmpegPCM = "ffmpeg pcm",
31
+ InlineVolume = "volume transformer",
32
+ OggOpusDemuxer = "ogg/opus demuxer",
33
+ OpusDecoder = "opus decoder",
34
+ OpusEncoder = "opus encoder",
35
+ WebmOpusDemuxer = "webm/opus demuxer"
36
+ }
37
+ /**
38
+ * Represents a pathway from one stream type to another using a transformer.
39
+ */
40
+ interface Edge {
41
+ cost: number;
42
+ from: Node;
43
+ to: Node;
44
+ transformer(input: Readable | string): Readable;
45
+ type: TransformerType;
46
+ }
47
+ /**
48
+ * Represents a type of stream within the graph, e.g. an Opus stream, or a stream of raw audio.
49
+ */
50
+ declare class Node {
51
+ /**
52
+ * The outbound edges from this node.
53
+ */
54
+ readonly edges: Edge[];
55
+ /**
56
+ * The type of stream for this node.
57
+ */
58
+ readonly type: StreamType;
59
+ constructor(type: StreamType);
60
+ /**
61
+ * Creates an outbound edge from this node.
62
+ *
63
+ * @param edge - The edge to create
64
+ */
65
+ addEdge(edge: Omit<Edge, 'from'>): void;
66
+ }
67
+
68
+ /**
69
+ * Options that are set when creating a new audio resource.
70
+ *
71
+ * @typeParam T - the type for the metadata (if any) of the audio resource
72
+ */
73
+ interface CreateAudioResourceOptions<T> {
74
+ /**
75
+ * Whether or not inline volume should be enabled. If enabled, you will be able to change the volume
76
+ * of the stream on-the-fly. However, this also increases the performance cost of playback. Defaults to `false`.
77
+ */
78
+ inlineVolume?: boolean;
79
+ /**
80
+ * The type of the input stream. Defaults to `StreamType.Arbitrary`.
81
+ */
82
+ inputType?: StreamType;
83
+ /**
84
+ * Optional metadata that can be attached to the resource (e.g. track title, random id).
85
+ * This is useful for identification purposes when the resource is passed around in events.
86
+ * See {@link AudioResource.metadata}
87
+ */
88
+ metadata?: T;
89
+ /**
90
+ * The number of silence frames to append to the end of the resource's audio stream, to prevent interpolation glitches.
91
+ * Defaults to 5.
92
+ */
93
+ silencePaddingFrames?: number;
94
+ }
95
+ /**
96
+ * Represents an audio resource that can be played by an audio player.
97
+ *
98
+ * @typeParam T - the type for the metadata (if any) of the audio resource
99
+ */
100
+ declare class AudioResource<T = unknown> {
101
+ /**
102
+ * An object-mode Readable stream that emits Opus packets. This is what is played by audio players.
103
+ */
104
+ readonly playStream: Readable;
105
+ /**
106
+ * The pipeline used to convert the input stream into a playable format. For example, this may
107
+ * contain an FFmpeg component for arbitrary inputs, and it may contain a VolumeTransformer component
108
+ * for resources with inline volume transformation enabled.
109
+ */
110
+ readonly edges: readonly Edge[];
111
+ /**
112
+ * Optional metadata that can be used to identify the resource.
113
+ */
114
+ metadata: T;
115
+ /**
116
+ * If the resource was created with inline volume transformation enabled, then this will be a
117
+ * prism-media VolumeTransformer. You can use this to alter the volume of the stream.
118
+ */
119
+ readonly volume?: prism.VolumeTransformer;
120
+ /**
121
+ * If using an Opus encoder to create this audio resource, then this will be a prism-media opus.Encoder.
122
+ * You can use this to control settings such as bitrate, FEC, PLP.
123
+ */
124
+ readonly encoder?: prism.opus.Encoder;
125
+ /**
126
+ * The audio player that the resource is subscribed to, if any.
127
+ */
128
+ audioPlayer?: AudioPlayer | undefined;
129
+ /**
130
+ * The playback duration of this audio resource, given in milliseconds.
131
+ */
132
+ playbackDuration: number;
133
+ /**
134
+ * Whether or not the stream for this resource has started (data has become readable)
135
+ */
136
+ started: boolean;
137
+ /**
138
+ * The number of silence frames to append to the end of the resource's audio stream, to prevent interpolation glitches.
139
+ */
140
+ readonly silencePaddingFrames: number;
141
+ /**
142
+ * The number of remaining silence frames to play. If -1, the frames have not yet started playing.
143
+ */
144
+ silenceRemaining: number;
145
+ constructor(edges: readonly Edge[], streams: readonly Readable[], metadata: T, silencePaddingFrames: number);
146
+ /**
147
+ * Whether this resource is readable. If the underlying resource is no longer readable, this will still return true
148
+ * while there are silence padding frames left to play.
149
+ */
150
+ get readable(): boolean;
151
+ /**
152
+ * Whether this resource has ended or not.
153
+ */
154
+ get ended(): boolean;
155
+ /**
156
+ * Attempts to read an Opus packet from the audio resource. If a packet is available, the playbackDuration
157
+ * is incremented.
158
+ *
159
+ * @remarks
160
+ * It is advisable to check that the playStream is readable before calling this method. While no runtime
161
+ * errors will be thrown, you should check that the resource is still available before attempting to
162
+ * read from it.
163
+ * @internal
164
+ */
165
+ read(): Buffer | null;
166
+ }
167
+ /**
168
+ * Creates an audio resource that can be played by audio players.
169
+ *
170
+ * @remarks
171
+ * If the input is given as a string, then the inputType option will be overridden and FFmpeg will be used.
172
+ *
173
+ * If the input is not in the correct format, then a pipeline of transcoders and transformers will be created
174
+ * to ensure that the resultant stream is in the correct format for playback. This could involve using FFmpeg,
175
+ * Opus transcoders, and Ogg/WebM demuxers.
176
+ * @param input - The resource to play
177
+ * @param options - Configurable options for creating the resource
178
+ * @typeParam T - the type for the metadata (if any) of the audio resource
179
+ */
180
+ declare function createAudioResource<T>(input: Readable | string, options: CreateAudioResourceOptions<T> & Pick<T extends null | undefined ? CreateAudioResourceOptions<T> : Required<CreateAudioResourceOptions<T>>, 'metadata'>): AudioResource<T extends null | undefined ? null : T>;
181
+ /**
182
+ * Creates an audio resource that can be played by audio players.
183
+ *
184
+ * @remarks
185
+ * If the input is given as a string, then the inputType option will be overridden and FFmpeg will be used.
186
+ *
187
+ * If the input is not in the correct format, then a pipeline of transcoders and transformers will be created
188
+ * to ensure that the resultant stream is in the correct format for playback. This could involve using FFmpeg,
189
+ * Opus transcoders, and Ogg/WebM demuxers.
190
+ * @param input - The resource to play
191
+ * @param options - Configurable options for creating the resource
192
+ * @typeParam T - the type for the metadata (if any) of the audio resource
193
+ */
194
+ declare function createAudioResource<T extends null | undefined>(input: Readable | string, options?: Omit<CreateAudioResourceOptions<T>, 'metadata'>): AudioResource<null>;
195
+
196
+ /**
197
+ * An error emitted by an AudioPlayer. Contains an attached resource to aid with
198
+ * debugging and identifying where the error came from.
199
+ */
200
+ declare class AudioPlayerError extends Error {
201
+ /**
202
+ * The resource associated with the audio player at the time the error was thrown.
203
+ */
204
+ readonly resource: AudioResource;
205
+ constructor(error: Error, resource: AudioResource);
206
+ }
207
+
208
+ /**
209
+ * Represents a subscription of a voice connection to an audio player, allowing
210
+ * the audio player to play audio on the voice connection.
211
+ */
212
+ declare class PlayerSubscription {
213
+ /**
214
+ * The voice connection of this subscription.
215
+ */
216
+ readonly connection: VoiceConnection;
217
+ /**
218
+ * The audio player of this subscription.
219
+ */
220
+ readonly player: AudioPlayer;
221
+ constructor(connection: VoiceConnection, player: AudioPlayer);
222
+ /**
223
+ * Unsubscribes the connection from the audio player, meaning that the
224
+ * audio player cannot stream audio to it until a new subscription is made.
225
+ */
226
+ unsubscribe(): void;
227
+ }
228
+
229
+ /**
230
+ * Describes the behavior of the player when an audio packet is played but there are no available
231
+ * voice connections to play to.
232
+ */
233
+ declare enum NoSubscriberBehavior {
234
+ /**
235
+ * Pauses playing the stream until a voice connection becomes available.
236
+ */
237
+ Pause = "pause",
238
+ /**
239
+ * Continues to play through the resource regardless.
240
+ */
241
+ Play = "play",
242
+ /**
243
+ * The player stops and enters the Idle state.
244
+ */
245
+ Stop = "stop"
246
+ }
247
+ declare enum AudioPlayerStatus {
248
+ /**
249
+ * When the player has paused itself. Only possible with the "pause" no subscriber behavior.
250
+ */
251
+ AutoPaused = "autopaused",
252
+ /**
253
+ * When the player is waiting for an audio resource to become readable before transitioning to Playing.
254
+ */
255
+ Buffering = "buffering",
256
+ /**
257
+ * When there is currently no resource for the player to be playing.
258
+ */
259
+ Idle = "idle",
260
+ /**
261
+ * When the player has been manually paused.
262
+ */
263
+ Paused = "paused",
264
+ /**
265
+ * When the player is actively playing an audio resource.
266
+ */
267
+ Playing = "playing"
268
+ }
269
+ /**
270
+ * Options that can be passed when creating an audio player, used to specify its behavior.
271
+ */
272
+ interface CreateAudioPlayerOptions {
273
+ behaviors?: {
274
+ maxMissedFrames?: number;
275
+ noSubscriber?: NoSubscriberBehavior;
276
+ };
277
+ debug?: boolean;
278
+ }
279
+ /**
280
+ * The state that an AudioPlayer is in when it has no resource to play. This is the starting state.
281
+ */
282
+ interface AudioPlayerIdleState {
283
+ status: AudioPlayerStatus.Idle;
284
+ }
285
+ /**
286
+ * The state that an AudioPlayer is in when it is waiting for a resource to become readable. Once this
287
+ * happens, the AudioPlayer will enter the Playing state. If the resource ends/errors before this, then
288
+ * it will re-enter the Idle state.
289
+ */
290
+ interface AudioPlayerBufferingState {
291
+ onFailureCallback: () => void;
292
+ onReadableCallback: () => void;
293
+ onStreamError: (error: Error) => void;
294
+ /**
295
+ * The resource that the AudioPlayer is waiting for
296
+ */
297
+ resource: AudioResource;
298
+ status: AudioPlayerStatus.Buffering;
299
+ }
300
+ /**
301
+ * The state that an AudioPlayer is in when it is actively playing an AudioResource. When playback ends,
302
+ * it will enter the Idle state.
303
+ */
304
+ interface AudioPlayerPlayingState {
305
+ /**
306
+ * The number of consecutive times that the audio resource has been unable to provide an Opus frame.
307
+ */
308
+ missedFrames: number;
309
+ onStreamError: (error: Error) => void;
310
+ /**
311
+ * The playback duration in milliseconds of the current audio resource. This includes filler silence packets
312
+ * that have been played when the resource was buffering.
313
+ */
314
+ playbackDuration: number;
315
+ /**
316
+ * The resource that is being played.
317
+ */
318
+ resource: AudioResource;
319
+ status: AudioPlayerStatus.Playing;
320
+ }
321
+ /**
322
+ * The state that an AudioPlayer is in when it has either been explicitly paused by the user, or done
323
+ * automatically by the AudioPlayer itself if there are no available subscribers.
324
+ */
325
+ interface AudioPlayerPausedState {
326
+ onStreamError: (error: Error) => void;
327
+ /**
328
+ * The playback duration in milliseconds of the current audio resource. This includes filler silence packets
329
+ * that have been played when the resource was buffering.
330
+ */
331
+ playbackDuration: number;
332
+ /**
333
+ * The current resource of the audio player.
334
+ */
335
+ resource: AudioResource;
336
+ /**
337
+ * How many silence packets still need to be played to avoid audio interpolation due to the stream suddenly pausing.
338
+ */
339
+ silencePacketsRemaining: number;
340
+ status: AudioPlayerStatus.AutoPaused | AudioPlayerStatus.Paused;
341
+ }
342
+ /**
343
+ * The various states that the player can be in.
344
+ */
345
+ declare type AudioPlayerState = AudioPlayerBufferingState | AudioPlayerIdleState | AudioPlayerPausedState | AudioPlayerPlayingState;
346
+ interface AudioPlayer extends EventEmitter {
347
+ /**
348
+ * Emitted when there is an error emitted from the audio resource played by the audio player
349
+ *
350
+ * @eventProperty
351
+ */
352
+ on(event: 'error', listener: (error: AudioPlayerError) => void): this;
353
+ /**
354
+ * Emitted debugging information about the audio player
355
+ *
356
+ * @eventProperty
357
+ */
358
+ on(event: 'debug', listener: (message: string) => void): this;
359
+ /**
360
+ * Emitted when the state of the audio player changes
361
+ *
362
+ * @eventProperty
363
+ */
364
+ on(event: 'stateChange', listener: (oldState: AudioPlayerState, newState: AudioPlayerState) => void): this;
365
+ /**
366
+ * Emitted when the audio player is subscribed to a voice connection
367
+ *
368
+ * @eventProperty
369
+ */
370
+ on(event: 'subscribe' | 'unsubscribe', listener: (subscription: PlayerSubscription) => void): this;
371
+ /**
372
+ * Emitted when the status of state changes to a specific status
373
+ *
374
+ * @eventProperty
375
+ */
376
+ on<T extends AudioPlayerStatus>(event: T, listener: (oldState: AudioPlayerState, newState: AudioPlayerState & {
377
+ status: T;
378
+ }) => void): this;
379
+ }
380
+ /**
381
+ * Used to play audio resources (i.e. tracks, streams) to voice connections.
382
+ *
383
+ * @remarks
384
+ * Audio players are designed to be re-used - even if a resource has finished playing, the player itself
385
+ * can still be used.
386
+ *
387
+ * The AudioPlayer drives the timing of playback, and therefore is unaffected by voice connections
388
+ * becoming unavailable. Its behavior in these scenarios can be configured.
389
+ */
390
+ declare class AudioPlayer extends EventEmitter {
391
+ /**
392
+ * The state that the AudioPlayer is in.
393
+ */
394
+ private _state;
395
+ /**
396
+ * A list of VoiceConnections that are registered to this AudioPlayer. The player will attempt to play audio
397
+ * to the streams in this list.
398
+ */
399
+ private readonly subscribers;
400
+ /**
401
+ * The behavior that the player should follow when it enters certain situations.
402
+ */
403
+ private readonly behaviors;
404
+ /**
405
+ * The debug logger function, if debugging is enabled.
406
+ */
407
+ private readonly debug;
408
+ /**
409
+ * Creates a new AudioPlayer.
410
+ */
411
+ constructor(options?: CreateAudioPlayerOptions);
412
+ /**
413
+ * A list of subscribed voice connections that can currently receive audio to play.
414
+ */
415
+ get playable(): VoiceConnection[];
416
+ /**
417
+ * Subscribes a VoiceConnection to the audio player's play list. If the VoiceConnection is already subscribed,
418
+ * then the existing subscription is used.
419
+ *
420
+ * @remarks
421
+ * This method should not be directly called. Instead, use VoiceConnection#subscribe.
422
+ * @param connection - The connection to subscribe
423
+ * @returns The new subscription if the voice connection is not yet subscribed, otherwise the existing subscription
424
+ */
425
+ private subscribe;
426
+ /**
427
+ * Unsubscribes a subscription - i.e. removes a voice connection from the play list of the audio player.
428
+ *
429
+ * @remarks
430
+ * This method should not be directly called. Instead, use PlayerSubscription#unsubscribe.
431
+ * @param subscription - The subscription to remove
432
+ * @returns Whether or not the subscription existed on the player and was removed
433
+ */
434
+ private unsubscribe;
435
+ /**
436
+ * The state that the player is in.
437
+ */
438
+ get state(): AudioPlayerState;
439
+ /**
440
+ * Sets a new state for the player, performing clean-up operations where necessary.
441
+ */
442
+ set state(newState: AudioPlayerState);
443
+ /**
444
+ * Plays a new resource on the player. If the player is already playing a resource, the existing resource is destroyed
445
+ * (it cannot be reused, even in another player) and is replaced with the new resource.
446
+ *
447
+ * @remarks
448
+ * The player will transition to the Playing state once playback begins, and will return to the Idle state once
449
+ * playback is ended.
450
+ *
451
+ * If the player was previously playing a resource and this method is called, the player will not transition to the
452
+ * Idle state during the swap over.
453
+ * @param resource - The resource to play
454
+ * @throws Will throw if attempting to play an audio resource that has already ended, or is being played by another player
455
+ */
456
+ play<T>(resource: AudioResource<T>): void;
457
+ /**
458
+ * Pauses playback of the current resource, if any.
459
+ *
460
+ * @param interpolateSilence - If true, the player will play 5 packets of silence after pausing to prevent audio glitches
461
+ * @returns `true` if the player was successfully paused, otherwise `false`
462
+ */
463
+ pause(interpolateSilence?: boolean): boolean;
464
+ /**
465
+ * Unpauses playback of the current resource, if any.
466
+ *
467
+ * @returns `true` if the player was successfully unpaused, otherwise `false`
468
+ */
469
+ unpause(): boolean;
470
+ /**
471
+ * Stops playback of the current resource and destroys the resource. The player will either transition to the Idle state,
472
+ * or remain in its current state until the silence padding frames of the resource have been played.
473
+ *
474
+ * @param force - If true, will force the player to enter the Idle state even if the resource has silence padding frames
475
+ * @returns `true` if the player will come to a stop, otherwise `false`
476
+ */
477
+ stop(force?: boolean): boolean;
478
+ /**
479
+ * Checks whether the underlying resource (if any) is playable (readable)
480
+ *
481
+ * @returns `true` if the resource is playable, otherwise `false`
482
+ */
483
+ checkPlayable(): boolean;
484
+ /**
485
+ * Called roughly every 20ms by the global audio player timer. Dispatches any audio packets that are buffered
486
+ * by the active connections of this audio player.
487
+ */
488
+ private _stepDispatch;
489
+ /**
490
+ * Called roughly every 20ms by the global audio player timer. Attempts to read an audio packet from the
491
+ * underlying resource of the stream, and then has all the active connections of the audio player prepare it
492
+ * (encrypt it, append header data) so that it is ready to play at the start of the next cycle.
493
+ */
494
+ private _stepPrepare;
495
+ /**
496
+ * Signals to all the subscribed connections that they should send a packet to Discord indicating
497
+ * they are no longer speaking. Called once playback of a resource ends.
498
+ */
499
+ private _signalStopSpeaking;
500
+ /**
501
+ * Instructs the given connections to each prepare this packet to be played at the start of the
502
+ * next cycle.
503
+ *
504
+ * @param packet - The Opus packet to be prepared by each receiver
505
+ * @param receivers - The connections that should play this packet
506
+ */
507
+ private _preparePacket;
508
+ }
509
+ /**
510
+ * Creates a new AudioPlayer to be used.
511
+ */
512
+ declare function createAudioPlayer(options?: CreateAudioPlayerOptions): AudioPlayer;
513
+
514
+ interface JoinConfig {
515
+ channelId: string | null;
516
+ group: string;
517
+ guildId: string;
518
+ selfDeaf: boolean;
519
+ selfMute: boolean;
520
+ }
521
+ /**
522
+ * Retrieves the map of group names to maps of voice connections. By default, all voice connections
523
+ * are created under the 'default' group.
524
+ *
525
+ * @returns The group map
526
+ */
527
+ declare function getGroups(): Map<string, Map<string, VoiceConnection>>;
528
+ /**
529
+ * Retrieves all the voice connections under the 'default' group.
530
+ *
531
+ * @param group - The group to look up
532
+ * @returns The map of voice connections
533
+ */
534
+ declare function getVoiceConnections(group?: 'default'): Map<string, VoiceConnection>;
535
+ /**
536
+ * Retrieves all the voice connections under the given group name.
537
+ *
538
+ * @param group - The group to look up
539
+ * @returns The map of voice connections
540
+ */
541
+ declare function getVoiceConnections(group: string): Map<string, VoiceConnection> | undefined;
542
+ /**
543
+ * Finds a voice connection with the given guild id and group. Defaults to the 'default' group.
544
+ *
545
+ * @param guildId - The guild id of the voice connection
546
+ * @param group - the group that the voice connection was registered with
547
+ * @returns The voice connection, if it exists
548
+ */
549
+ declare function getVoiceConnection(guildId: string, group?: string): VoiceConnection | undefined;
550
+
551
+ /**
552
+ * Stores an IP address and port. Used to store socket details for the local client as well as
553
+ * for Discord.
554
+ */
555
+ interface SocketConfig {
556
+ ip: string;
557
+ port: number;
558
+ }
559
+ interface VoiceUDPSocket extends EventEmitter {
560
+ on(event: 'error', listener: (error: Error) => void): this;
561
+ on(event: 'close', listener: () => void): this;
562
+ on(event: 'debug', listener: (message: string) => void): this;
563
+ on(event: 'message', listener: (message: Buffer) => void): this;
564
+ }
565
+ /**
566
+ * Manages the UDP networking for a voice connection.
567
+ */
568
+ declare class VoiceUDPSocket extends EventEmitter {
569
+ /**
570
+ * The underlying network Socket for the VoiceUDPSocket.
571
+ */
572
+ private readonly socket;
573
+ /**
574
+ * The socket details for Discord (remote)
575
+ */
576
+ private readonly remote;
577
+ /**
578
+ * A list of keep alives that are waiting to be acknowledged.
579
+ */
580
+ private readonly keepAlives;
581
+ /**
582
+ * The counter used in the keep alive mechanism.
583
+ */
584
+ private keepAliveCounter;
585
+ /**
586
+ * The buffer used to write the keep alive counter into.
587
+ */
588
+ private readonly keepAliveBuffer;
589
+ /**
590
+ * The Node.js interval for the keep-alive mechanism.
591
+ */
592
+ private readonly keepAliveInterval;
593
+ /**
594
+ * The time taken to receive a response to keep alive messages.
595
+ */
596
+ ping?: number;
597
+ /**
598
+ * The debug logger function, if debugging is enabled.
599
+ */
600
+ private readonly debug;
601
+ /**
602
+ * Creates a new VoiceUDPSocket.
603
+ *
604
+ * @param remote - Details of the remote socket
605
+ */
606
+ constructor(remote: SocketConfig, debug?: boolean);
607
+ /**
608
+ * Called when a message is received on the UDP socket.
609
+ *
610
+ * @param buffer - The received buffer
611
+ */
612
+ private onMessage;
613
+ /**
614
+ * Called at a regular interval to check whether we are still able to send datagrams to Discord.
615
+ */
616
+ private keepAlive;
617
+ /**
618
+ * Sends a buffer to Discord.
619
+ *
620
+ * @param buffer - The buffer to send
621
+ */
622
+ send(buffer: Buffer): void;
623
+ /**
624
+ * Closes the socket, the instance will not be able to be reused.
625
+ */
626
+ destroy(): void;
627
+ /**
628
+ * Performs IP discovery to discover the local address and port to be used for the voice connection.
629
+ *
630
+ * @param ssrc - The SSRC received from Discord
631
+ */
632
+ performIPDiscovery(ssrc: number): Promise<SocketConfig>;
633
+ }
634
+
635
+ interface VoiceWebSocket extends EventEmitter {
636
+ on(event: 'error', listener: (error: Error) => void): this;
637
+ on(event: 'open', listener: (event: WebSocket.Event) => void): this;
638
+ on(event: 'close', listener: (event: WebSocket.CloseEvent) => void): this;
639
+ /**
640
+ * Debug event for VoiceWebSocket.
641
+ *
642
+ * @eventProperty
643
+ */
644
+ on(event: 'debug', listener: (message: string) => void): this;
645
+ /**
646
+ * Packet event.
647
+ *
648
+ * @eventProperty
649
+ */
650
+ on(event: 'packet', listener: (packet: any) => void): this;
651
+ }
652
+ /**
653
+ * An extension of the WebSocket class to provide helper functionality when interacting
654
+ * with the Discord Voice gateway.
655
+ */
656
+ declare class VoiceWebSocket extends EventEmitter {
657
+ /**
658
+ * The current heartbeat interval, if any.
659
+ */
660
+ private heartbeatInterval?;
661
+ /**
662
+ * The time (milliseconds since UNIX epoch) that the last heartbeat acknowledgement packet was received.
663
+ * This is set to 0 if an acknowledgement packet hasn't been received yet.
664
+ */
665
+ private lastHeartbeatAck;
666
+ /**
667
+ * The time (milliseconds since UNIX epoch) that the last heartbeat was sent. This is set to 0 if a heartbeat
668
+ * hasn't been sent yet.
669
+ */
670
+ private lastHeartbeatSend;
671
+ /**
672
+ * The number of consecutively missed heartbeats.
673
+ */
674
+ private missedHeartbeats;
675
+ /**
676
+ * The last recorded ping.
677
+ */
678
+ ping?: number;
679
+ /**
680
+ * The debug logger function, if debugging is enabled.
681
+ */
682
+ private readonly debug;
683
+ /**
684
+ * The underlying WebSocket of this wrapper.
685
+ */
686
+ private readonly ws;
687
+ /**
688
+ * Creates a new VoiceWebSocket.
689
+ *
690
+ * @param address - The address to connect to
691
+ */
692
+ constructor(address: string, debug: boolean);
693
+ /**
694
+ * Destroys the VoiceWebSocket. The heartbeat interval is cleared, and the connection is closed.
695
+ */
696
+ destroy(): void;
697
+ /**
698
+ * Handles message events on the WebSocket. Attempts to JSON parse the messages and emit them
699
+ * as packets.
700
+ *
701
+ * @param event - The message event
702
+ */
703
+ onMessage(event: MessageEvent): void;
704
+ /**
705
+ * Sends a JSON-stringifiable packet over the WebSocket.
706
+ *
707
+ * @param packet - The packet to send
708
+ */
709
+ sendPacket(packet: any): void;
710
+ /**
711
+ * Sends a heartbeat over the WebSocket.
712
+ */
713
+ private sendHeartbeat;
714
+ /**
715
+ * Sets/clears an interval to send heartbeats over the WebSocket.
716
+ *
717
+ * @param ms - The interval in milliseconds. If negative, the interval will be unset
718
+ */
719
+ setHeartbeatInterval(ms: number): void;
720
+ }
721
+
722
+ /**
723
+ * The different statuses that a networking instance can hold. The order
724
+ * of the states between OpeningWs and Ready is chronological (first the
725
+ * instance enters OpeningWs, then it enters Identifying etc.)
726
+ */
727
+ declare enum NetworkingStatusCode {
728
+ OpeningWs = 0,
729
+ Identifying = 1,
730
+ UdpHandshaking = 2,
731
+ SelectingProtocol = 3,
732
+ Ready = 4,
733
+ Resuming = 5,
734
+ Closed = 6
735
+ }
736
+ /**
737
+ * The initial Networking state. Instances will be in this state when a WebSocket connection to a Discord
738
+ * voice gateway is being opened.
739
+ */
740
+ interface NetworkingOpeningWsState {
741
+ code: NetworkingStatusCode.OpeningWs;
742
+ connectionOptions: ConnectionOptions;
743
+ ws: VoiceWebSocket;
744
+ }
745
+ /**
746
+ * The state that a Networking instance will be in when it is attempting to authorize itself.
747
+ */
748
+ interface NetworkingIdentifyingState {
749
+ code: NetworkingStatusCode.Identifying;
750
+ connectionOptions: ConnectionOptions;
751
+ ws: VoiceWebSocket;
752
+ }
753
+ /**
754
+ * The state that a Networking instance will be in when opening a UDP connection to the IP and port provided
755
+ * by Discord, as well as performing IP discovery.
756
+ */
757
+ interface NetworkingUdpHandshakingState {
758
+ code: NetworkingStatusCode.UdpHandshaking;
759
+ connectionData: Pick<ConnectionData, 'ssrc'>;
760
+ connectionOptions: ConnectionOptions;
761
+ udp: VoiceUDPSocket;
762
+ ws: VoiceWebSocket;
763
+ }
764
+ /**
765
+ * The state that a Networking instance will be in when selecting an encryption protocol for audio packets.
766
+ */
767
+ interface NetworkingSelectingProtocolState {
768
+ code: NetworkingStatusCode.SelectingProtocol;
769
+ connectionData: Pick<ConnectionData, 'ssrc'>;
770
+ connectionOptions: ConnectionOptions;
771
+ udp: VoiceUDPSocket;
772
+ ws: VoiceWebSocket;
773
+ }
774
+ /**
775
+ * The state that a Networking instance will be in when it has a fully established connection to a Discord
776
+ * voice server.
777
+ */
778
+ interface NetworkingReadyState {
779
+ code: NetworkingStatusCode.Ready;
780
+ connectionData: ConnectionData;
781
+ connectionOptions: ConnectionOptions;
782
+ preparedPacket?: Buffer | undefined;
783
+ udp: VoiceUDPSocket;
784
+ ws: VoiceWebSocket;
785
+ }
786
+ /**
787
+ * The state that a Networking instance will be in when its connection has been dropped unexpectedly, and it
788
+ * is attempting to resume an existing session.
789
+ */
790
+ interface NetworkingResumingState {
791
+ code: NetworkingStatusCode.Resuming;
792
+ connectionData: ConnectionData;
793
+ connectionOptions: ConnectionOptions;
794
+ preparedPacket?: Buffer | undefined;
795
+ udp: VoiceUDPSocket;
796
+ ws: VoiceWebSocket;
797
+ }
798
+ /**
799
+ * The state that a Networking instance will be in when it has been destroyed. It cannot be recovered from this
800
+ * state.
801
+ */
802
+ interface NetworkingClosedState {
803
+ code: NetworkingStatusCode.Closed;
804
+ }
805
+ /**
806
+ * The various states that a networking instance can be in.
807
+ */
808
+ declare type NetworkingState = NetworkingClosedState | NetworkingIdentifyingState | NetworkingOpeningWsState | NetworkingReadyState | NetworkingResumingState | NetworkingSelectingProtocolState | NetworkingUdpHandshakingState;
809
+ /**
810
+ * Details required to connect to the Discord voice gateway. These details
811
+ * are first received on the main bot gateway, in the form of VOICE_SERVER_UPDATE
812
+ * and VOICE_STATE_UPDATE packets.
813
+ */
814
+ interface ConnectionOptions {
815
+ endpoint: string;
816
+ serverId: string;
817
+ sessionId: string;
818
+ token: string;
819
+ userId: string;
820
+ }
821
+ /**
822
+ * Information about the current connection, e.g. which encryption mode is to be used on
823
+ * the connection, timing information for playback of streams.
824
+ */
825
+ interface ConnectionData {
826
+ encryptionMode: string;
827
+ nonce: number;
828
+ nonceBuffer: Buffer;
829
+ packetsPlayed: number;
830
+ secretKey: Uint8Array;
831
+ sequence: number;
832
+ speaking: boolean;
833
+ ssrc: number;
834
+ timestamp: number;
835
+ }
836
+ interface Networking extends EventEmitter {
837
+ /**
838
+ * Debug event for Networking.
839
+ *
840
+ * @eventProperty
841
+ */
842
+ on(event: 'debug', listener: (message: string) => void): this;
843
+ on(event: 'error', listener: (error: Error) => void): this;
844
+ on(event: 'stateChange', listener: (oldState: NetworkingState, newState: NetworkingState) => void): this;
845
+ on(event: 'close', listener: (code: number) => void): this;
846
+ }
847
+ /**
848
+ * Manages the networking required to maintain a voice connection and dispatch audio packets
849
+ */
850
+ declare class Networking extends EventEmitter {
851
+ private _state;
852
+ /**
853
+ * The debug logger function, if debugging is enabled.
854
+ */
855
+ private readonly debug;
856
+ /**
857
+ * Creates a new Networking instance.
858
+ */
859
+ constructor(options: ConnectionOptions, debug: boolean);
860
+ /**
861
+ * Destroys the Networking instance, transitioning it into the Closed state.
862
+ */
863
+ destroy(): void;
864
+ /**
865
+ * The current state of the networking instance.
866
+ */
867
+ get state(): NetworkingState;
868
+ /**
869
+ * Sets a new state for the networking instance, performing clean-up operations where necessary.
870
+ */
871
+ set state(newState: NetworkingState);
872
+ /**
873
+ * Creates a new WebSocket to a Discord Voice gateway.
874
+ *
875
+ * @param endpoint - The endpoint to connect to
876
+ */
877
+ private createWebSocket;
878
+ /**
879
+ * Propagates errors from the children VoiceWebSocket and VoiceUDPSocket.
880
+ *
881
+ * @param error - The error that was emitted by a child
882
+ */
883
+ private onChildError;
884
+ /**
885
+ * Called when the WebSocket opens. Depending on the state that the instance is in,
886
+ * it will either identify with a new session, or it will attempt to resume an existing session.
887
+ */
888
+ private onWsOpen;
889
+ /**
890
+ * Called when the WebSocket closes. Based on the reason for closing (given by the code parameter),
891
+ * the instance will either attempt to resume, or enter the closed state and emit a 'close' event
892
+ * with the close code, allowing the user to decide whether or not they would like to reconnect.
893
+ *
894
+ * @param code - The close code
895
+ */
896
+ private onWsClose;
897
+ /**
898
+ * Called when the UDP socket has closed itself if it has stopped receiving replies from Discord.
899
+ */
900
+ private onUdpClose;
901
+ /**
902
+ * Called when a packet is received on the connection's WebSocket.
903
+ *
904
+ * @param packet - The received packet
905
+ */
906
+ private onWsPacket;
907
+ /**
908
+ * Propagates debug messages from the child WebSocket.
909
+ *
910
+ * @param message - The emitted debug message
911
+ */
912
+ private onWsDebug;
913
+ /**
914
+ * Propagates debug messages from the child UDPSocket.
915
+ *
916
+ * @param message - The emitted debug message
917
+ */
918
+ private onUdpDebug;
919
+ /**
920
+ * Prepares an Opus packet for playback. This includes attaching metadata to it and encrypting it.
921
+ * It will be stored within the instance, and can be played by dispatchAudio()
922
+ *
923
+ * @remarks
924
+ * Calling this method while there is already a prepared audio packet that has not yet been dispatched
925
+ * will overwrite the existing audio packet. This should be avoided.
926
+ * @param opusPacket - The Opus packet to encrypt
927
+ * @returns The audio packet that was prepared
928
+ */
929
+ prepareAudioPacket(opusPacket: Buffer): Buffer | undefined;
930
+ /**
931
+ * Dispatches the audio packet previously prepared by prepareAudioPacket(opusPacket). The audio packet
932
+ * is consumed and cannot be dispatched again.
933
+ */
934
+ dispatchAudio(): boolean;
935
+ /**
936
+ * Plays an audio packet, updating timing metadata used for playback.
937
+ *
938
+ * @param audioPacket - The audio packet to play
939
+ */
940
+ private playAudioPacket;
941
+ /**
942
+ * Sends a packet to the voice gateway indicating that the client has start/stopped sending
943
+ * audio.
944
+ *
945
+ * @param speaking - Whether or not the client should be shown as speaking
946
+ */
947
+ setSpeaking(speaking: boolean): void;
948
+ /**
949
+ * Creates a new audio packet from an Opus packet. This involves encrypting the packet,
950
+ * then prepending a header that includes metadata.
951
+ *
952
+ * @param opusPacket - The Opus packet to prepare
953
+ * @param connectionData - The current connection data of the instance
954
+ */
955
+ private createAudioPacket;
956
+ /**
957
+ * Encrypts an Opus packet using the format agreed upon by the instance and Discord.
958
+ *
959
+ * @param opusPacket - The Opus packet to encrypt
960
+ * @param connectionData - The current connection data of the instance
961
+ */
962
+ private encryptOpusPacket;
963
+ }
964
+
965
+ /**
966
+ * The different behaviors an audio receive stream can have for deciding when to end.
967
+ */
968
+ declare enum EndBehaviorType {
969
+ /**
970
+ * The stream will only end when manually destroyed.
971
+ */
972
+ Manual = 0,
973
+ /**
974
+ * The stream will end after a given time period of silence/no audio packets.
975
+ */
976
+ AfterSilence = 1,
977
+ /**
978
+ * The stream will end after a given time period of no audio packets.
979
+ */
980
+ AfterInactivity = 2
981
+ }
982
+ declare type EndBehavior = {
983
+ behavior: EndBehaviorType.AfterInactivity | EndBehaviorType.AfterSilence;
984
+ duration: number;
985
+ } | {
986
+ behavior: EndBehaviorType.Manual;
987
+ };
988
+ interface AudioReceiveStreamOptions extends ReadableOptions {
989
+ end: EndBehavior;
990
+ }
991
+ declare function createDefaultAudioReceiveStreamOptions(): AudioReceiveStreamOptions;
992
+ /**
993
+ * A readable stream of Opus packets received from a specific entity
994
+ * in a Discord voice connection.
995
+ */
996
+ declare class AudioReceiveStream extends Readable {
997
+ /**
998
+ * The end behavior of the receive stream.
999
+ */
1000
+ readonly end: EndBehavior;
1001
+ private endTimeout?;
1002
+ constructor({ end, ...options }: AudioReceiveStreamOptions);
1003
+ push(buffer: Buffer | null): boolean;
1004
+ private renewEndTimeout;
1005
+ _read(): void;
1006
+ }
1007
+
1008
+ /**
1009
+ * The known data for a user in a Discord voice connection.
1010
+ */
1011
+ interface VoiceUserData {
1012
+ /**
1013
+ * The SSRC of the user's audio stream.
1014
+ */
1015
+ audioSSRC: number;
1016
+ /**
1017
+ * The Discord user id of the user.
1018
+ */
1019
+ userId: string;
1020
+ /**
1021
+ * The SSRC of the user's video stream (if one exists)
1022
+ * Cannot be 0. If undefined, the user has no video stream.
1023
+ */
1024
+ videoSSRC?: number;
1025
+ }
1026
+ interface SSRCMap extends EventEmitter {
1027
+ on(event: 'create', listener: (newData: VoiceUserData) => void): this;
1028
+ on(event: 'update', listener: (oldData: VoiceUserData | undefined, newData: VoiceUserData) => void): this;
1029
+ on(event: 'delete', listener: (deletedData: VoiceUserData) => void): this;
1030
+ }
1031
+ /**
1032
+ * Maps audio SSRCs to data of users in voice connections.
1033
+ */
1034
+ declare class SSRCMap extends EventEmitter {
1035
+ /**
1036
+ * The underlying map.
1037
+ */
1038
+ private readonly map;
1039
+ constructor();
1040
+ /**
1041
+ * Updates the map with new user data
1042
+ *
1043
+ * @param data - The data to update with
1044
+ */
1045
+ update(data: VoiceUserData): void;
1046
+ /**
1047
+ * Gets the stored voice data of a user.
1048
+ *
1049
+ * @param target - The target, either their user id or audio SSRC
1050
+ */
1051
+ get(target: number | string): VoiceUserData | undefined;
1052
+ /**
1053
+ * Deletes the stored voice data about a user.
1054
+ *
1055
+ * @param target - The target of the delete operation, either their audio SSRC or user id
1056
+ * @returns The data that was deleted, if any
1057
+ */
1058
+ delete(target: number | string): VoiceUserData | undefined;
1059
+ }
1060
+
1061
+ interface SpeakingMap extends EventEmitter {
1062
+ /**
1063
+ * Emitted when a user starts speaking.
1064
+ *
1065
+ * @eventProperty
1066
+ */
1067
+ on(event: 'start', listener: (userId: string) => void): this;
1068
+ /**
1069
+ * Emitted when a user ends speaking.
1070
+ *
1071
+ * @eventProperty
1072
+ */
1073
+ on(event: 'end', listener: (userId: string) => void): this;
1074
+ }
1075
+ /**
1076
+ * Tracks the speaking states of users in a voice channel.
1077
+ */
1078
+ declare class SpeakingMap extends EventEmitter {
1079
+ /**
1080
+ * The delay after a packet is received from a user until they're marked as not speaking anymore.
1081
+ */
1082
+ static readonly DELAY = 100;
1083
+ /**
1084
+ * The currently speaking users, mapped to the milliseconds since UNIX epoch at which they started speaking.
1085
+ */
1086
+ readonly users: Map<string, number>;
1087
+ private readonly speakingTimeouts;
1088
+ constructor();
1089
+ onPacket(userId: string): void;
1090
+ private startTimeout;
1091
+ }
1092
+
1093
+ /**
1094
+ * Attaches to a VoiceConnection, allowing you to receive audio packets from other
1095
+ * users that are speaking.
1096
+ *
1097
+ * @beta
1098
+ */
1099
+ declare class VoiceReceiver {
1100
+ /**
1101
+ * The attached connection of this receiver.
1102
+ */
1103
+ readonly voiceConnection: VoiceConnection;
1104
+ /**
1105
+ * Maps SSRCs to Discord user ids.
1106
+ */
1107
+ readonly ssrcMap: SSRCMap;
1108
+ /**
1109
+ * The current audio subscriptions of this receiver.
1110
+ */
1111
+ readonly subscriptions: Map<string, AudioReceiveStream>;
1112
+ /**
1113
+ * The connection data of the receiver.
1114
+ *
1115
+ * @internal
1116
+ */
1117
+ connectionData: Partial<ConnectionData>;
1118
+ /**
1119
+ * The speaking map of the receiver.
1120
+ */
1121
+ readonly speaking: SpeakingMap;
1122
+ constructor(voiceConnection: VoiceConnection);
1123
+ /**
1124
+ * Called when a packet is received on the attached connection's WebSocket.
1125
+ *
1126
+ * @param packet - The received packet
1127
+ * @internal
1128
+ */
1129
+ onWsPacket(packet: any): void;
1130
+ private decrypt;
1131
+ /**
1132
+ * Parses an audio packet, decrypting it to yield an Opus packet.
1133
+ *
1134
+ * @param buffer - The buffer to parse
1135
+ * @param mode - The encryption mode
1136
+ * @param nonce - The nonce buffer used by the connection for encryption
1137
+ * @param secretKey - The secret key used by the connection for encryption
1138
+ * @returns The parsed Opus packet
1139
+ */
1140
+ private parsePacket;
1141
+ /**
1142
+ * Called when the UDP socket of the attached connection receives a message.
1143
+ *
1144
+ * @param msg - The received message
1145
+ * @internal
1146
+ */
1147
+ onUdpMessage(msg: Buffer): void;
1148
+ /**
1149
+ * Creates a subscription for the given user id.
1150
+ *
1151
+ * @param target - The id of the user to subscribe to
1152
+ * @returns A readable stream of Opus packets received from the target
1153
+ */
1154
+ subscribe(userId: string, options?: Partial<AudioReceiveStreamOptions>): AudioReceiveStream;
1155
+ }
1156
+
1157
+ /**
1158
+ * Methods that are provided by the \@discordjs/voice library to implementations of
1159
+ * Discord gateway DiscordGatewayAdapters.
1160
+ */
1161
+ interface DiscordGatewayAdapterLibraryMethods {
1162
+ /**
1163
+ * Call this when the adapter can no longer be used (e.g. due to a disconnect from the main gateway)
1164
+ */
1165
+ destroy(): void;
1166
+ /**
1167
+ * Call this when you receive a VOICE_SERVER_UPDATE payload that is relevant to the adapter.
1168
+ *
1169
+ * @param data - The inner data of the VOICE_SERVER_UPDATE payload
1170
+ */
1171
+ onVoiceServerUpdate(data: GatewayVoiceServerUpdateDispatchData): void;
1172
+ /**
1173
+ * Call this when you receive a VOICE_STATE_UPDATE payload that is relevant to the adapter.
1174
+ *
1175
+ * @param data - The inner data of the VOICE_STATE_UPDATE payload
1176
+ */
1177
+ onVoiceStateUpdate(data: GatewayVoiceStateUpdateDispatchData): void;
1178
+ }
1179
+ /**
1180
+ * Methods that are provided by the implementer of a Discord gateway DiscordGatewayAdapter.
1181
+ */
1182
+ interface DiscordGatewayAdapterImplementerMethods {
1183
+ /**
1184
+ * This will be called by \@discordjs/voice when the adapter can safely be destroyed as it will no
1185
+ * longer be used.
1186
+ */
1187
+ destroy(): void;
1188
+ /**
1189
+ * Implement this method such that the given payload is sent to the main Discord gateway connection.
1190
+ *
1191
+ * @param payload - The payload to send to the main Discord gateway connection
1192
+ * @returns `false` if the payload definitely failed to send - in this case, the voice connection disconnects
1193
+ */
1194
+ sendPayload(payload: any): boolean;
1195
+ }
1196
+ /**
1197
+ * A function used to build adapters. It accepts a methods parameter that contains functions that
1198
+ * can be called by the implementer when new data is received on its gateway connection. In return,
1199
+ * the implementer will return some methods that the library can call - e.g. to send messages on
1200
+ * the gateway, or to signal that the adapter can be removed.
1201
+ */
1202
+ declare type DiscordGatewayAdapterCreator = (methods: DiscordGatewayAdapterLibraryMethods) => DiscordGatewayAdapterImplementerMethods;
1203
+
1204
+ /**
1205
+ * The various status codes a voice connection can hold at any one time.
1206
+ */
1207
+ declare enum VoiceConnectionStatus {
1208
+ /**
1209
+ * The `VOICE_SERVER_UPDATE` and `VOICE_STATE_UPDATE` packets have been received, now attempting to establish a voice connection.
1210
+ */
1211
+ Connecting = "connecting",
1212
+ /**
1213
+ * The voice connection has been destroyed and untracked, it cannot be reused.
1214
+ */
1215
+ Destroyed = "destroyed",
1216
+ /**
1217
+ * The voice connection has either been severed or not established.
1218
+ */
1219
+ Disconnected = "disconnected",
1220
+ /**
1221
+ * A voice connection has been established, and is ready to be used.
1222
+ */
1223
+ Ready = "ready",
1224
+ /**
1225
+ * Sending a packet to the main Discord gateway to indicate we want to change our voice state.
1226
+ */
1227
+ Signalling = "signalling"
1228
+ }
1229
+ /**
1230
+ * The state that a VoiceConnection will be in when it is waiting to receive a VOICE_SERVER_UPDATE and
1231
+ * VOICE_STATE_UPDATE packet from Discord, provided by the adapter.
1232
+ */
1233
+ interface VoiceConnectionSignallingState {
1234
+ adapter: DiscordGatewayAdapterImplementerMethods;
1235
+ status: VoiceConnectionStatus.Signalling;
1236
+ subscription?: PlayerSubscription | undefined;
1237
+ }
1238
+ /**
1239
+ * The reasons a voice connection can be in the disconnected state.
1240
+ */
1241
+ declare enum VoiceConnectionDisconnectReason {
1242
+ /**
1243
+ * When the WebSocket connection has been closed.
1244
+ */
1245
+ WebSocketClose = 0,
1246
+ /**
1247
+ * When the adapter was unable to send a message requested by the VoiceConnection.
1248
+ */
1249
+ AdapterUnavailable = 1,
1250
+ /**
1251
+ * When a VOICE_SERVER_UPDATE packet is received with a null endpoint, causing the connection to be severed.
1252
+ */
1253
+ EndpointRemoved = 2,
1254
+ /**
1255
+ * When a manual disconnect was requested.
1256
+ */
1257
+ Manual = 3
1258
+ }
1259
+ /**
1260
+ * The state that a VoiceConnection will be in when it is not connected to a Discord voice server nor is
1261
+ * it attempting to connect. You can manually attempt to reconnect using VoiceConnection#reconnect.
1262
+ */
1263
+ interface VoiceConnectionDisconnectedBaseState {
1264
+ adapter: DiscordGatewayAdapterImplementerMethods;
1265
+ status: VoiceConnectionStatus.Disconnected;
1266
+ subscription?: PlayerSubscription | undefined;
1267
+ }
1268
+ /**
1269
+ * The state that a VoiceConnection will be in when it is not connected to a Discord voice server nor is
1270
+ * it attempting to connect. You can manually attempt to reconnect using VoiceConnection#reconnect.
1271
+ */
1272
+ interface VoiceConnectionDisconnectedOtherState extends VoiceConnectionDisconnectedBaseState {
1273
+ reason: Exclude<VoiceConnectionDisconnectReason, VoiceConnectionDisconnectReason.WebSocketClose>;
1274
+ }
1275
+ /**
1276
+ * The state that a VoiceConnection will be in when its WebSocket connection was closed.
1277
+ * You can manually attempt to reconnect using VoiceConnection#reconnect.
1278
+ */
1279
+ interface VoiceConnectionDisconnectedWebSocketState extends VoiceConnectionDisconnectedBaseState {
1280
+ /**
1281
+ * The close code of the WebSocket connection to the Discord voice server.
1282
+ */
1283
+ closeCode: number;
1284
+ reason: VoiceConnectionDisconnectReason.WebSocketClose;
1285
+ }
1286
+ /**
1287
+ * The states that a VoiceConnection can be in when it is not connected to a Discord voice server nor is
1288
+ * it attempting to connect. You can manually attempt to connect using VoiceConnection#reconnect.
1289
+ */
1290
+ declare type VoiceConnectionDisconnectedState = VoiceConnectionDisconnectedOtherState | VoiceConnectionDisconnectedWebSocketState;
1291
+ /**
1292
+ * The state that a VoiceConnection will be in when it is establishing a connection to a Discord
1293
+ * voice server.
1294
+ */
1295
+ interface VoiceConnectionConnectingState {
1296
+ adapter: DiscordGatewayAdapterImplementerMethods;
1297
+ networking: Networking;
1298
+ status: VoiceConnectionStatus.Connecting;
1299
+ subscription?: PlayerSubscription | undefined;
1300
+ }
1301
+ /**
1302
+ * The state that a VoiceConnection will be in when it has an active connection to a Discord
1303
+ * voice server.
1304
+ */
1305
+ interface VoiceConnectionReadyState {
1306
+ adapter: DiscordGatewayAdapterImplementerMethods;
1307
+ networking: Networking;
1308
+ status: VoiceConnectionStatus.Ready;
1309
+ subscription?: PlayerSubscription | undefined;
1310
+ }
1311
+ /**
1312
+ * The state that a VoiceConnection will be in when it has been permanently been destroyed by the
1313
+ * user and untracked by the library. It cannot be reconnected, instead, a new VoiceConnection
1314
+ * needs to be established.
1315
+ */
1316
+ interface VoiceConnectionDestroyedState {
1317
+ status: VoiceConnectionStatus.Destroyed;
1318
+ }
1319
+ /**
1320
+ * The various states that a voice connection can be in.
1321
+ */
1322
+ declare type VoiceConnectionState = VoiceConnectionConnectingState | VoiceConnectionDestroyedState | VoiceConnectionDisconnectedState | VoiceConnectionReadyState | VoiceConnectionSignallingState;
1323
+ interface VoiceConnection extends EventEmitter {
1324
+ /**
1325
+ * Emitted when there is an error emitted from the voice connection
1326
+ *
1327
+ * @eventProperty
1328
+ */
1329
+ on(event: 'error', listener: (error: Error) => void): this;
1330
+ /**
1331
+ * Emitted debugging information about the voice connection
1332
+ *
1333
+ * @eventProperty
1334
+ */
1335
+ on(event: 'debug', listener: (message: string) => void): this;
1336
+ /**
1337
+ * Emitted when the state of the voice connection changes
1338
+ *
1339
+ * @eventProperty
1340
+ */
1341
+ on(event: 'stateChange', listener: (oldState: VoiceConnectionState, newState: VoiceConnectionState) => void): this;
1342
+ /**
1343
+ * Emitted when the state of the voice connection changes to a specific status
1344
+ *
1345
+ * @eventProperty
1346
+ */
1347
+ on<T extends VoiceConnectionStatus>(event: T, listener: (oldState: VoiceConnectionState, newState: VoiceConnectionState & {
1348
+ status: T;
1349
+ }) => void): this;
1350
+ }
1351
+ /**
1352
+ * A connection to the voice server of a Guild, can be used to play audio in voice channels.
1353
+ */
1354
+ declare class VoiceConnection extends EventEmitter {
1355
+ /**
1356
+ * The number of consecutive rejoin attempts. Initially 0, and increments for each rejoin.
1357
+ * When a connection is successfully established, it resets to 0.
1358
+ */
1359
+ rejoinAttempts: number;
1360
+ /**
1361
+ * The state of the voice connection.
1362
+ */
1363
+ private _state;
1364
+ /**
1365
+ * A configuration storing all the data needed to reconnect to a Guild's voice server.
1366
+ *
1367
+ * @internal
1368
+ */
1369
+ readonly joinConfig: JoinConfig;
1370
+ /**
1371
+ * The two packets needed to successfully establish a voice connection. They are received
1372
+ * from the main Discord gateway after signalling to change the voice state.
1373
+ */
1374
+ private readonly packets;
1375
+ /**
1376
+ * The receiver of this voice connection. You should join the voice channel with `selfDeaf` set
1377
+ * to false for this feature to work properly.
1378
+ */
1379
+ readonly receiver: VoiceReceiver;
1380
+ /**
1381
+ * The debug logger function, if debugging is enabled.
1382
+ */
1383
+ private readonly debug;
1384
+ /**
1385
+ * Creates a new voice connection.
1386
+ *
1387
+ * @param joinConfig - The data required to establish the voice connection
1388
+ * @param options - The options used to create this voice connection
1389
+ */
1390
+ constructor(joinConfig: JoinConfig, options: CreateVoiceConnectionOptions);
1391
+ /**
1392
+ * The current state of the voice connection.
1393
+ */
1394
+ get state(): VoiceConnectionState;
1395
+ /**
1396
+ * Updates the state of the voice connection, performing clean-up operations where necessary.
1397
+ */
1398
+ set state(newState: VoiceConnectionState);
1399
+ /**
1400
+ * Registers a `VOICE_SERVER_UPDATE` packet to the voice connection. This will cause it to reconnect using the
1401
+ * new data provided in the packet.
1402
+ *
1403
+ * @param packet - The received `VOICE_SERVER_UPDATE` packet
1404
+ */
1405
+ private addServerPacket;
1406
+ /**
1407
+ * Registers a `VOICE_STATE_UPDATE` packet to the voice connection. Most importantly, it stores the id of the
1408
+ * channel that the client is connected to.
1409
+ *
1410
+ * @param packet - The received `VOICE_STATE_UPDATE` packet
1411
+ */
1412
+ private addStatePacket;
1413
+ /**
1414
+ * Called when the networking state changes, and the new ws/udp packet/message handlers need to be rebound
1415
+ * to the new instances.
1416
+ *
1417
+ * @param newState - The new networking state
1418
+ * @param oldState - The old networking state, if there is one
1419
+ */
1420
+ private updateReceiveBindings;
1421
+ /**
1422
+ * Attempts to configure a networking instance for this voice connection using the received packets.
1423
+ * Both packets are required, and any existing networking instance will be destroyed.
1424
+ *
1425
+ * @remarks
1426
+ * This is called when the voice server of the connection changes, e.g. if the bot is moved into a
1427
+ * different channel in the same guild but has a different voice server. In this instance, the connection
1428
+ * needs to be re-established to the new voice server.
1429
+ *
1430
+ * The connection will transition to the Connecting state when this is called.
1431
+ */
1432
+ configureNetworking(): void;
1433
+ /**
1434
+ * Called when the networking instance for this connection closes. If the close code is 4014 (do not reconnect),
1435
+ * the voice connection will transition to the Disconnected state which will store the close code. You can
1436
+ * decide whether or not to reconnect when this occurs by listening for the state change and calling reconnect().
1437
+ *
1438
+ * @remarks
1439
+ * If the close code was anything other than 4014, it is likely that the closing was not intended, and so the
1440
+ * VoiceConnection will signal to Discord that it would like to rejoin the channel. This automatically attempts
1441
+ * to re-establish the connection. This would be seen as a transition from the Ready state to the Signalling state.
1442
+ * @param code - The close code
1443
+ */
1444
+ private onNetworkingClose;
1445
+ /**
1446
+ * Called when the state of the networking instance changes. This is used to derive the state of the voice connection.
1447
+ *
1448
+ * @param oldState - The previous state
1449
+ * @param newState - The new state
1450
+ */
1451
+ private onNetworkingStateChange;
1452
+ /**
1453
+ * Propagates errors from the underlying network instance.
1454
+ *
1455
+ * @param error - The error to propagate
1456
+ */
1457
+ private onNetworkingError;
1458
+ /**
1459
+ * Propagates debug messages from the underlying network instance.
1460
+ *
1461
+ * @param message - The debug message to propagate
1462
+ */
1463
+ private onNetworkingDebug;
1464
+ /**
1465
+ * Prepares an audio packet for dispatch.
1466
+ *
1467
+ * @param buffer - The Opus packet to prepare
1468
+ */
1469
+ prepareAudioPacket(buffer: Buffer): Buffer | undefined;
1470
+ /**
1471
+ * Dispatches the previously prepared audio packet (if any)
1472
+ */
1473
+ dispatchAudio(): boolean | undefined;
1474
+ /**
1475
+ * Prepares an audio packet and dispatches it immediately.
1476
+ *
1477
+ * @param buffer - The Opus packet to play
1478
+ */
1479
+ playOpusPacket(buffer: Buffer): boolean | undefined;
1480
+ /**
1481
+ * Destroys the VoiceConnection, preventing it from connecting to voice again.
1482
+ * This method should be called when you no longer require the VoiceConnection to
1483
+ * prevent memory leaks.
1484
+ *
1485
+ * @param adapterAvailable - Whether the adapter can be used
1486
+ */
1487
+ destroy(adapterAvailable?: boolean): void;
1488
+ /**
1489
+ * Disconnects the VoiceConnection, allowing the possibility of rejoining later on.
1490
+ *
1491
+ * @returns `true` if the connection was successfully disconnected
1492
+ */
1493
+ disconnect(): boolean;
1494
+ /**
1495
+ * Attempts to rejoin (better explanation soon:tm:)
1496
+ *
1497
+ * @remarks
1498
+ * Calling this method successfully will automatically increment the `rejoinAttempts` counter,
1499
+ * which you can use to inform whether or not you'd like to keep attempting to reconnect your
1500
+ * voice connection.
1501
+ *
1502
+ * A state transition from Disconnected to Signalling will be observed when this is called.
1503
+ */
1504
+ rejoin(joinConfig?: Omit<JoinConfig, 'group' | 'guildId'>): boolean;
1505
+ /**
1506
+ * Updates the speaking status of the voice connection. This is used when audio players are done playing audio,
1507
+ * and need to signal that the connection is no longer playing audio.
1508
+ *
1509
+ * @param enabled - Whether or not to show as speaking
1510
+ */
1511
+ setSpeaking(enabled: boolean): false | void;
1512
+ /**
1513
+ * Subscribes to an audio player, allowing the player to play audio on this voice connection.
1514
+ *
1515
+ * @param player - The audio player to subscribe to
1516
+ * @returns The created subscription
1517
+ */
1518
+ subscribe(player: AudioPlayer): PlayerSubscription | undefined;
1519
+ /**
1520
+ * The latest ping (in milliseconds) for the WebSocket connection and audio playback for this voice
1521
+ * connection, if this data is available.
1522
+ *
1523
+ * @remarks
1524
+ * For this data to be available, the VoiceConnection must be in the Ready state, and its underlying
1525
+ * WebSocket connection and UDP socket must have had at least one ping-pong exchange.
1526
+ */
1527
+ get ping(): {
1528
+ ws: number | undefined;
1529
+ udp: number | undefined;
1530
+ };
1531
+ /**
1532
+ * Called when a subscription of this voice connection to an audio player is removed.
1533
+ *
1534
+ * @param subscription - The removed subscription
1535
+ */
1536
+ protected onSubscriptionRemoved(subscription: PlayerSubscription): void;
1537
+ }
1538
+
1539
+ /**
1540
+ * The options that can be given when creating a voice connection.
1541
+ */
1542
+ interface CreateVoiceConnectionOptions {
1543
+ adapterCreator: DiscordGatewayAdapterCreator;
1544
+ /**
1545
+ * If true, debug messages will be enabled for the voice connection and its
1546
+ * related components. Defaults to false.
1547
+ */
1548
+ debug?: boolean | undefined;
1549
+ }
1550
+ /**
1551
+ * The options that can be given when joining a voice channel.
1552
+ */
1553
+ interface JoinVoiceChannelOptions {
1554
+ /**
1555
+ * The id of the Discord voice channel to join.
1556
+ */
1557
+ channelId: string;
1558
+ /**
1559
+ * An optional group identifier for the voice connection.
1560
+ */
1561
+ group?: string;
1562
+ /**
1563
+ * The id of the guild that the voice channel belongs to.
1564
+ */
1565
+ guildId: string;
1566
+ /**
1567
+ * Whether to join the channel deafened (defaults to true)
1568
+ */
1569
+ selfDeaf?: boolean;
1570
+ /**
1571
+ * Whether to join the channel muted (defaults to true)
1572
+ */
1573
+ selfMute?: boolean;
1574
+ }
1575
+ /**
1576
+ * Creates a VoiceConnection to a Discord voice channel.
1577
+ *
1578
+ * @param options - the options for joining the voice channel
1579
+ */
1580
+ declare function joinVoiceChannel(options: CreateVoiceConnectionOptions & JoinVoiceChannelOptions): VoiceConnection;
1581
+
1582
+ /**
1583
+ * Generates a report of the dependencies used by the \@discordjs/voice module.
1584
+ * Useful for debugging.
1585
+ */
1586
+ declare function generateDependencyReport(): string;
1587
+
1588
+ /**
1589
+ * Allows a voice connection a specified amount of time to enter a given state, otherwise rejects with an error.
1590
+ *
1591
+ * @param target - The voice connection that we want to observe the state change for
1592
+ * @param status - The status that the voice connection should be in
1593
+ * @param timeoutOrSignal - The maximum time we are allowing for this to occur, or a signal that will abort the operation
1594
+ */
1595
+ declare function entersState(target: VoiceConnection, status: VoiceConnectionStatus, timeoutOrSignal: AbortSignal | number): Promise<VoiceConnection>;
1596
+ /**
1597
+ * Allows an audio player a specified amount of time to enter a given state, otherwise rejects with an error.
1598
+ *
1599
+ * @param target - The audio player that we want to observe the state change for
1600
+ * @param status - The status that the audio player should be in
1601
+ * @param timeoutOrSignal - The maximum time we are allowing for this to occur, or a signal that will abort the operation
1602
+ */
1603
+ declare function entersState(target: AudioPlayer, status: AudioPlayerStatus, timeoutOrSignal: AbortSignal | number): Promise<AudioPlayer>;
1604
+
1605
+ /**
1606
+ * Takes an Opus Head, and verifies whether the associated Opus audio is suitable to play in a Discord voice channel.
1607
+ *
1608
+ * @param opusHead - The Opus Head to validate
1609
+ * @returns `true` if suitable to play in a Discord voice channel, otherwise `false`
1610
+ */
1611
+ declare function validateDiscordOpusHead(opusHead: Buffer): boolean;
1612
+ /**
1613
+ * The resulting information after probing an audio stream
1614
+ */
1615
+ interface ProbeInfo {
1616
+ /**
1617
+ * The readable audio stream to use. You should use this rather than the input stream, as the probing
1618
+ * function can sometimes read the input stream to its end and cause the stream to close.
1619
+ */
1620
+ stream: Readable;
1621
+ /**
1622
+ * The recommended stream type for this audio stream.
1623
+ */
1624
+ type: StreamType;
1625
+ }
1626
+ /**
1627
+ * Attempt to probe a readable stream to figure out whether it can be demuxed using an Ogg or WebM Opus demuxer.
1628
+ *
1629
+ * @param stream - The readable stream to probe
1630
+ * @param probeSize - The number of bytes to attempt to read before giving up on the probe
1631
+ * @param validator - The Opus Head validator function
1632
+ * @experimental
1633
+ */
1634
+ declare function demuxProbe(stream: Readable, probeSize?: number, validator?: typeof validateDiscordOpusHead): Promise<ProbeInfo>;
1635
+
1636
+ export { AudioPlayer, AudioPlayerBufferingState, AudioPlayerError, AudioPlayerIdleState, AudioPlayerPausedState, AudioPlayerPlayingState, AudioPlayerState, AudioPlayerStatus, AudioReceiveStream, AudioReceiveStreamOptions, AudioResource, CreateAudioPlayerOptions, CreateAudioResourceOptions, CreateVoiceConnectionOptions, DiscordGatewayAdapterCreator, DiscordGatewayAdapterImplementerMethods, DiscordGatewayAdapterLibraryMethods, EndBehavior, EndBehaviorType, JoinConfig, JoinVoiceChannelOptions, NoSubscriberBehavior, PlayerSubscription, ProbeInfo, SSRCMap, SpeakingMap, StreamType, VoiceConnection, VoiceConnectionConnectingState, VoiceConnectionDestroyedState, VoiceConnectionDisconnectReason, VoiceConnectionDisconnectedBaseState, VoiceConnectionDisconnectedOtherState, VoiceConnectionDisconnectedState, VoiceConnectionDisconnectedWebSocketState, VoiceConnectionReadyState, VoiceConnectionSignallingState, VoiceConnectionState, VoiceConnectionStatus, VoiceReceiver, VoiceUserData, createAudioPlayer, createAudioResource, createDefaultAudioReceiveStreamOptions, demuxProbe, entersState, generateDependencyReport, getGroups, getVoiceConnection, getVoiceConnections, joinVoiceChannel, validateDiscordOpusHead };