@discordjs/voice 0.6.0 → 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.
Files changed (60) hide show
  1. package/LICENSE +190 -21
  2. package/README.md +41 -18
  3. package/dist/index.d.ts +155 -89
  4. package/dist/index.js +10 -26
  5. package/dist/index.js.map +7 -1
  6. package/dist/index.mjs +10 -0
  7. package/dist/index.mjs.map +7 -0
  8. package/package.json +67 -96
  9. package/dist/DataStore.js +0 -151
  10. package/dist/DataStore.js.map +0 -1
  11. package/dist/VoiceConnection.js +0 -529
  12. package/dist/VoiceConnection.js.map +0 -1
  13. package/dist/audio/AudioPlayer.js +0 -449
  14. package/dist/audio/AudioPlayer.js.map +0 -1
  15. package/dist/audio/AudioPlayerError.js +0 -17
  16. package/dist/audio/AudioPlayerError.js.map +0 -1
  17. package/dist/audio/AudioResource.js +0 -162
  18. package/dist/audio/AudioResource.js.map +0 -1
  19. package/dist/audio/PlayerSubscription.js +0 -23
  20. package/dist/audio/PlayerSubscription.js.map +0 -1
  21. package/dist/audio/TransformerGraph.js +0 -233
  22. package/dist/audio/TransformerGraph.js.map +0 -1
  23. package/dist/audio/index.js +0 -18
  24. package/dist/audio/index.js.map +0 -1
  25. package/dist/joinVoiceChannel.js +0 -24
  26. package/dist/joinVoiceChannel.js.map +0 -1
  27. package/dist/networking/Networking.js +0 -457
  28. package/dist/networking/Networking.js.map +0 -1
  29. package/dist/networking/VoiceUDPSocket.js +0 -145
  30. package/dist/networking/VoiceUDPSocket.js.map +0 -1
  31. package/dist/networking/VoiceWebSocket.js +0 -129
  32. package/dist/networking/VoiceWebSocket.js.map +0 -1
  33. package/dist/networking/index.js +0 -16
  34. package/dist/networking/index.js.map +0 -1
  35. package/dist/receive/AudioReceiveStream.js +0 -64
  36. package/dist/receive/AudioReceiveStream.js.map +0 -1
  37. package/dist/receive/SSRCMap.js +0 -69
  38. package/dist/receive/SSRCMap.js.map +0 -1
  39. package/dist/receive/SpeakingMap.js +0 -38
  40. package/dist/receive/SpeakingMap.js.map +0 -1
  41. package/dist/receive/VoiceReceiver.js +0 -149
  42. package/dist/receive/VoiceReceiver.js.map +0 -1
  43. package/dist/receive/index.js +0 -16
  44. package/dist/receive/index.js.map +0 -1
  45. package/dist/util/Secretbox.js +0 -50
  46. package/dist/util/Secretbox.js.map +0 -1
  47. package/dist/util/abortAfter.js +0 -15
  48. package/dist/util/abortAfter.js.map +0 -1
  49. package/dist/util/adapter.js +0 -3
  50. package/dist/util/adapter.js.map +0 -1
  51. package/dist/util/demuxProbe.js +0 -90
  52. package/dist/util/demuxProbe.js.map +0 -1
  53. package/dist/util/entersState.js +0 -26
  54. package/dist/util/entersState.js.map +0 -1
  55. package/dist/util/generateDependencyReport.js +0 -82
  56. package/dist/util/generateDependencyReport.js.map +0 -1
  57. package/dist/util/index.js +0 -17
  58. package/dist/util/index.js.map +0 -1
  59. package/dist/util/util.js +0 -7
  60. package/dist/util/util.js.map +0 -1
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.abortAfter = void 0;
4
- /**
5
- * Creates an abort controller that aborts after the given time.
6
- * @param delay - The time in milliseconds to wait before aborting
7
- */
8
- function abortAfter(delay) {
9
- const ac = new AbortController();
10
- const timeout = setTimeout(() => ac.abort(), delay);
11
- ac.signal.addEventListener('abort', () => clearTimeout(timeout));
12
- return [ac, ac.signal];
13
- }
14
- exports.abortAfter = abortAfter;
15
- //# sourceMappingURL=abortAfter.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"abortAfter.js","sourceRoot":"","sources":["../../src/util/abortAfter.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,SAAgB,UAAU,CAAC,KAAa;IACvC,MAAM,EAAE,GAAG,IAAI,eAAe,EAAE,CAAC;IACjC,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE,KAAK,CAAC,CAAC;IACpD,EAAE,CAAC,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC;IACjE,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC;AACxB,CAAC;AALD,gCAKC","sourcesContent":["/**\n * Creates an abort controller that aborts after the given time.\n * @param delay - The time in milliseconds to wait before aborting\n */\nexport function abortAfter(delay: number): [AbortController, AbortSignal] {\n\tconst ac = new AbortController();\n\tconst timeout = setTimeout(() => ac.abort(), delay);\n\tac.signal.addEventListener('abort', () => clearTimeout(timeout));\n\treturn [ac, ac.signal];\n}\n"]}
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=adapter.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"adapter.js","sourceRoot":"","sources":["../../src/util/adapter.ts"],"names":[],"mappings":"","sourcesContent":["import { GatewayVoiceServerUpdateDispatchData, GatewayVoiceStateUpdateDispatchData } from 'discord-api-types/v9';\n\n/**\n * Methods that are provided by the @discordjs/voice library to implementations of\n * Discord gateway DiscordGatewayAdapters.\n */\nexport interface DiscordGatewayAdapterLibraryMethods {\n\t/**\n\t * Call this when you receive a VOICE_SERVER_UPDATE payload that is relevant to the adapter.\n\t *\n\t * @param data - The inner data of the VOICE_SERVER_UPDATE payload\n\t */\n\tonVoiceServerUpdate(data: GatewayVoiceServerUpdateDispatchData): void;\n\t/**\n\t * Call this when you receive a VOICE_STATE_UPDATE payload that is relevant to the adapter.\n\t *\n\t * @param data - The inner data of the VOICE_STATE_UPDATE payload\n\t */\n\tonVoiceStateUpdate(data: GatewayVoiceStateUpdateDispatchData): void;\n\t/**\n\t * Call this when the adapter can no longer be used (e.g. due to a disconnect from the main gateway)\n\t */\n\tdestroy(): void;\n}\n\n/**\n * Methods that are provided by the implementer of a Discord gateway DiscordGatewayAdapter.\n */\nexport interface DiscordGatewayAdapterImplementerMethods {\n\t/**\n\t * Implement this method such that the given payload is sent to the main Discord gateway connection.\n\t *\n\t * @param payload - The payload to send to the main Discord gateway connection\n\t * @returns false if the payload definitely failed to send - in this case, the voice connection disconnects.\n\t */\n\tsendPayload(payload: any): boolean;\n\t/**\n\t * This will be called by @discordjs/voice when the adapter can safely be destroyed as it will no\n\t * longer be used.\n\t */\n\tdestroy(): void;\n}\n\n/**\n * A function used to build adapters. It accepts a methods parameter that contains functions that\n * can be called by the implementer when new data is received on its gateway connection. In return,\n * the implementer will return some methods that the library can call - e.g. to send messages on\n * the gateway, or to signal that the adapter can be removed.\n */\nexport type DiscordGatewayAdapterCreator = (\n\tmethods: DiscordGatewayAdapterLibraryMethods,\n) => DiscordGatewayAdapterImplementerMethods;\n"]}
@@ -1,90 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.demuxProbe = exports.validateDiscordOpusHead = void 0;
4
- const stream_1 = require("stream");
5
- const prism_media_1 = require("prism-media");
6
- const util_1 = require("./util");
7
- const __1 = require("..");
8
- /**
9
- * Takes an Opus Head, and verifies whether the associated Opus audio is suitable to play in a Discord voice channel.
10
- * @param opusHead The Opus Head to validate
11
- * @returns true if suitable to play in a Discord voice channel, false otherwise
12
- */
13
- function validateDiscordOpusHead(opusHead) {
14
- const channels = opusHead.readUInt8(9);
15
- const sampleRate = opusHead.readUInt32LE(12);
16
- return channels === 2 && sampleRate === 48000;
17
- }
18
- exports.validateDiscordOpusHead = validateDiscordOpusHead;
19
- /**
20
- * Attempt to probe a readable stream to figure out whether it can be demuxed using an Ogg or WebM Opus demuxer.
21
- * @param stream The readable stream to probe
22
- * @param probeSize The number of bytes to attempt to read before giving up on the probe
23
- * @param validator The Opus Head validator function
24
- * @experimental
25
- */
26
- function demuxProbe(stream, probeSize = 1024, validator = validateDiscordOpusHead) {
27
- return new Promise((resolve, reject) => {
28
- // Preconditions
29
- if (stream.readableObjectMode)
30
- reject(new Error('Cannot probe a readable stream in object mode'));
31
- if (stream.readableEnded)
32
- reject(new Error('Cannot probe a stream that has ended'));
33
- let readBuffer = Buffer.alloc(0);
34
- let resolved = undefined;
35
- const finish = (type) => {
36
- stream.off('data', onData);
37
- stream.off('close', onClose);
38
- stream.off('end', onClose);
39
- stream.pause();
40
- resolved = type;
41
- if (stream.readableEnded) {
42
- resolve({
43
- stream: stream_1.Readable.from(readBuffer),
44
- type,
45
- });
46
- }
47
- else {
48
- if (readBuffer.length > 0) {
49
- stream.push(readBuffer);
50
- }
51
- resolve({
52
- stream,
53
- type,
54
- });
55
- }
56
- };
57
- const foundHead = (type) => (head) => {
58
- if (validator(head)) {
59
- finish(type);
60
- }
61
- };
62
- const webm = new prism_media_1.opus.WebmDemuxer();
63
- webm.once('error', util_1.noop);
64
- webm.on('head', foundHead(__1.StreamType.WebmOpus));
65
- const ogg = new prism_media_1.opus.OggDemuxer();
66
- ogg.once('error', util_1.noop);
67
- ogg.on('head', foundHead(__1.StreamType.OggOpus));
68
- const onClose = () => {
69
- if (!resolved) {
70
- finish(__1.StreamType.Arbitrary);
71
- }
72
- };
73
- const onData = (buffer) => {
74
- readBuffer = Buffer.concat([readBuffer, buffer]);
75
- webm.write(buffer);
76
- ogg.write(buffer);
77
- if (readBuffer.length >= probeSize) {
78
- stream.off('data', onData);
79
- stream.pause();
80
- process.nextTick(onClose);
81
- }
82
- };
83
- stream.once('error', reject);
84
- stream.on('data', onData);
85
- stream.once('close', onClose);
86
- stream.once('end', onClose);
87
- });
88
- }
89
- exports.demuxProbe = demuxProbe;
90
- //# sourceMappingURL=demuxProbe.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"demuxProbe.js","sourceRoot":"","sources":["../../src/util/demuxProbe.ts"],"names":[],"mappings":";;;AAAA,mCAAkC;AAClC,6CAAmC;AACnC,iCAA8B;AAC9B,0BAAgC;AAEhC;;;;GAIG;AACH,SAAgB,uBAAuB,CAAC,QAAgB;IACvD,MAAM,QAAQ,GAAG,QAAQ,CAAC,SA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OAAO,CAAC,CAAC;aAC1B;QACF,CAAC,CAAC;QAEF,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC7B,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC1B,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC9B,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAC;AACJ,CAAC;AA1ED,gCA0EC","sourcesContent":["import { Readable } from 'stream';\nimport { opus } from 'prism-media';\nimport { noop } from './util';\nimport { StreamType } from '..';\n\n/**\n * Takes an Opus Head, and verifies whether the associated Opus audio is suitable to play in a Discord voice channel.\n * @param opusHead The Opus Head to validate\n * @returns true if suitable to play in a Discord voice channel, false otherwise\n */\nexport function validateDiscordOpusHead(opusHead: Buffer): boolean {\n\tconst channels = opusHead.readUInt8(9);\n\tconst sampleRate = opusHead.readUInt32LE(12);\n\treturn channels === 2 && sampleRate === 48000;\n}\n\n/**\n * The resulting information after probing an audio stream\n */\nexport interface ProbeInfo {\n\t/**\n\t * The readable audio stream to use. You should use this rather than the input stream, as the probing\n\t * function can sometimes read the input stream to its end and cause the stream to close.\n\t */\n\tstream: Readable;\n\t/**\n\t * The recommended stream type for this audio stream\n\t */\n\ttype: StreamType;\n}\n\n/**\n * Attempt to probe a readable stream to figure out whether it can be demuxed using an Ogg or WebM Opus demuxer.\n * @param stream The readable stream to probe\n * @param probeSize The number of bytes to attempt to read before giving up on the probe\n * @param validator The Opus Head validator function\n * @experimental\n */\nexport function demuxProbe(\n\tstream: Readable,\n\tprobeSize = 1024,\n\tvalidator = validateDiscordOpusHead,\n): Promise<ProbeInfo> {\n\treturn new Promise((resolve, reject) => {\n\t\t// Preconditions\n\t\tif (stream.readableObjectMode) reject(new Error('Cannot probe a readable stream in object mode'));\n\t\tif (stream.readableEnded) reject(new Error('Cannot probe a stream that has ended'));\n\n\t\tlet readBuffer = Buffer.alloc(0);\n\n\t\tlet resolved: StreamType | undefined = undefined;\n\n\t\tconst finish = (type: StreamType) => {\n\t\t\tstream.off('data', onData);\n\t\t\tstream.off('close', onClose);\n\t\t\tstream.off('end', onClose);\n\t\t\tstream.pause();\n\t\t\tresolved = type;\n\t\t\tif (stream.readableEnded) {\n\t\t\t\tresolve({\n\t\t\t\t\tstream: Readable.from(readBuffer),\n\t\t\t\t\ttype,\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tif (readBuffer.length > 0) {\n\t\t\t\t\tstream.push(readBuffer);\n\t\t\t\t}\n\t\t\t\tresolve({\n\t\t\t\t\tstream,\n\t\t\t\t\ttype,\n\t\t\t\t});\n\t\t\t}\n\t\t};\n\n\t\tconst foundHead = (type: StreamType) => (head: Buffer) => {\n\t\t\tif (validator(head)) {\n\t\t\t\tfinish(type);\n\t\t\t}\n\t\t};\n\n\t\tconst webm = new opus.WebmDemuxer();\n\t\twebm.once('error', noop);\n\t\twebm.on('head', foundHead(StreamType.WebmOpus));\n\n\t\tconst ogg = new opus.OggDemuxer();\n\t\togg.once('error', noop);\n\t\togg.on('head', foundHead(StreamType.OggOpus));\n\n\t\tconst onClose = () => {\n\t\t\tif (!resolved) {\n\t\t\t\tfinish(StreamType.Arbitrary);\n\t\t\t}\n\t\t};\n\n\t\tconst onData = (buffer: Buffer) => {\n\t\t\treadBuffer = Buffer.concat([readBuffer, buffer]);\n\n\t\t\twebm.write(buffer);\n\t\t\togg.write(buffer);\n\n\t\t\tif (readBuffer.length >= probeSize) {\n\t\t\t\tstream.off('data', onData);\n\t\t\t\tstream.pause();\n\t\t\t\tprocess.nextTick(onClose);\n\t\t\t}\n\t\t};\n\n\t\tstream.once('error', reject);\n\t\tstream.on('data', onData);\n\t\tstream.once('close', onClose);\n\t\tstream.once('end', onClose);\n\t});\n}\n"]}
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.entersState = void 0;
4
- const abortAfter_1 = require("./abortAfter");
5
- const events_1 = require("events");
6
- /**
7
- * Allows a target a specified amount of time to enter a given state, otherwise rejects with an error.
8
- *
9
- * @param target - The object that we want to observe the state change for
10
- * @param status - The status that the target should be in
11
- * @param timeoutOrSignal - The maximum time we are allowing for this to occur, or a signal that will abort the operation
12
- */
13
- async function entersState(target, status, timeoutOrSignal) {
14
- if (target.state.status !== status) {
15
- const [ac, signal] = typeof timeoutOrSignal === 'number' ? abortAfter_1.abortAfter(timeoutOrSignal) : [undefined, timeoutOrSignal];
16
- try {
17
- await events_1.once(target, status, { signal });
18
- }
19
- finally {
20
- ac === null || ac === void 0 ? void 0 : ac.abort();
21
- }
22
- }
23
- return target;
24
- }
25
- exports.entersState = entersState;
26
- //# sourceMappingURL=entersState.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"entersState.js","sourceRoot":"","sources":["../../src/util/entersState.ts"],"names":[],"mappings":";;;AAEA,6CAA0C;AAC1C,mCAA4C;AA4B5C;;;;;;GAMG;AACI,KAAK,UAAU,WAAW,CAChC,MAAS,EACT,MAAiD,EACjD,eAAqC;IAErC,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,KAAK,MAAM,EAAE;QACnC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,GACjB,OAAO,eAAe,KAAK,QAAQ,CAAC,CAAC,CAAC,uBAAU,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;QAClG,IAAI;YACH,MAAM,aAAI,CAAC,MAAsB,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;SACvD;gBAAS;YACT,EAAE,aAAF,EAAE,uBAAF,EAAE,CAAE,KAAK,EAAE,CAAC;SACZ;KACD;IACD,OAAO,MAAM,CAAC;AACf,CAAC;AAfD,kCAeC","sourcesContent":["import { VoiceConnection, VoiceConnectionStatus } from '../VoiceConnection';\nimport { AudioPlayer, AudioPlayerStatus } from '../audio/AudioPlayer';\nimport { abortAfter } from './abortAfter';\nimport EventEmitter, { once } from 'events';\n\n/**\n * Allows a voice connection a specified amount of time to enter a given state, otherwise rejects with an error.\n *\n * @param target - The voice connection that we want to observe the state change for\n * @param status - The status that the voice connection should be in\n * @param timeoutOrSignal - The maximum time we are allowing for this to occur, or a signal that will abort the operation\n */\nexport function entersState(\n\ttarget: VoiceConnection,\n\tstatus: VoiceConnectionStatus,\n\ttimeoutOrSignal: number | AbortSignal,\n): Promise<VoiceConnection>;\n\n/**\n * Allows an audio player a specified amount of time to enter a given state, otherwise rejects with an error.\n *\n * @param target - The audio player that we want to observe the state change for\n * @param status - The status that the audio player should be in\n * @param timeoutOrSignal - The maximum time we are allowing for this to occur, or a signal that will abort the operation\n */\nexport function entersState(\n\ttarget: AudioPlayer,\n\tstatus: AudioPlayerStatus,\n\ttimeoutOrSignal: number | AbortSignal,\n): Promise<AudioPlayer>;\n\n/**\n * Allows a target a specified amount of time to enter a given state, otherwise rejects with an error.\n *\n * @param target - The object that we want to observe the state change for\n * @param status - The status that the target should be in\n * @param timeoutOrSignal - The maximum time we are allowing for this to occur, or a signal that will abort the operation\n */\nexport async function entersState<T extends VoiceConnection | AudioPlayer>(\n\ttarget: T,\n\tstatus: VoiceConnectionStatus | AudioPlayerStatus,\n\ttimeoutOrSignal: number | AbortSignal,\n) {\n\tif (target.state.status !== status) {\n\t\tconst [ac, signal] =\n\t\t\ttypeof timeoutOrSignal === 'number' ? abortAfter(timeoutOrSignal) : [undefined, timeoutOrSignal];\n\t\ttry {\n\t\t\tawait once(target as EventEmitter, status, { signal });\n\t\t} finally {\n\t\t\tac?.abort();\n\t\t}\n\t}\n\treturn target;\n}\n"]}
@@ -1,82 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateDependencyReport = void 0;
4
- /* eslint-disable @typescript-eslint/no-var-requires */
5
- /* eslint-disable @typescript-eslint/no-require-imports */
6
- const path_1 = require("path");
7
- const prism_media_1 = require("prism-media");
8
- /**
9
- * Generates a report of the dependencies used by the \@discordjs/voice module.
10
- * Useful for debugging.
11
- */
12
- function generateDependencyReport() {
13
- const report = [];
14
- const addVersion = (name) => report.push(`- ${name}: ${version(name)}`);
15
- // general
16
- report.push('Core Dependencies');
17
- addVersion('@discordjs/voice');
18
- addVersion('prism-media');
19
- report.push('');
20
- // opus
21
- report.push('Opus Libraries');
22
- addVersion('@discordjs/opus');
23
- addVersion('opusscript');
24
- report.push('');
25
- // encryption
26
- report.push('Encryption Libraries');
27
- addVersion('sodium');
28
- addVersion('libsodium-wrappers');
29
- addVersion('tweetnacl');
30
- report.push('');
31
- // ffmpeg
32
- report.push('FFmpeg');
33
- try {
34
- const info = prism_media_1.FFmpeg.getInfo();
35
- report.push(`- version: ${info.version}`);
36
- report.push(`- libopus: ${info.output.includes('--enable-libopus') ? 'yes' : 'no'}`);
37
- }
38
- catch (err) {
39
- report.push('- not found');
40
- }
41
- return ['-'.repeat(50), ...report, '-'.repeat(50)].join('\n');
42
- }
43
- exports.generateDependencyReport = generateDependencyReport;
44
- /**
45
- * Tries to find the package.json file for a given module.
46
- *
47
- * @param dir - The directory to look in
48
- * @param packageName - The name of the package to look for
49
- * @param depth - The maximum recursion depth
50
- */
51
- function findPackageJSON(dir, packageName, depth) {
52
- if (depth === 0)
53
- return undefined;
54
- const attemptedPath = path_1.resolve(dir, './package.json');
55
- try {
56
- const pkg = require(attemptedPath);
57
- if (pkg.name !== packageName)
58
- throw new Error('package.json does not match');
59
- return pkg;
60
- }
61
- catch (err) {
62
- return findPackageJSON(path_1.resolve(dir, '..'), packageName, depth - 1);
63
- }
64
- }
65
- /**
66
- * Tries to find the version of a dependency.
67
- *
68
- * @param name - The package to find the version of
69
- */
70
- function version(name) {
71
- var _a;
72
- try {
73
- const pkg = name === '@discordjs/voice'
74
- ? require('../../package.json')
75
- : findPackageJSON(path_1.dirname(require.resolve(name)), name, 3);
76
- return (_a = pkg === null || pkg === void 0 ? void 0 : pkg.version) !== null && _a !== void 0 ? _a : 'not found';
77
- }
78
- catch (err) {
79
- return 'not found';
80
- }
81
- }
82
- //# sourceMappingURL=generateDependencyReport.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generateDependencyReport.js","sourceRoot":"","sources":["../../src/util/generateDependencyReport.ts"],"names":[],"mappings":";;;AAAA,uDAAuD;AACvD,0DAA0D;AAC1D,+BAAwC;AACxC,6CAAqC;AAErC;;;GAGG;AACH,SAAgB,wBAAwB;IACvC,MAAM,MAAM,GAAG,EAAE,CAAC;IAClB,MAAM,UAAU,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAChF,UAAU;IACV,MAAM,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;IACjC,UAAU,CAAC,kBAAkB,CAAC,CAAC;IAC/B,UAAU,CAAC,aAAa,CAAC,CAAC;IAC1B,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAEhB,OAAO;IACP,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;IAC9B,UAAU,CAAC,iBAAiB,CAAC,CAAC;IAC9B,UAAU,CAAC,YAAY,CAAC,CAAC;IACzB,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAEhB,aAAa;IACb,MAAM,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;IACpC,UAAU,CAAC,QAAQ,CAAC,CAAC;IACrB,UAAU,CAAC,oBAAoB,CAAC,CAAC;IACjC,UAAU,CAAC,WAAW,CAAC,CAAC;IACxB,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAEhB,SAAS;IACT,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACtB,IAAI;QACH,MAAM,IAAI,GAAG,oBAAM,CAAC,OAAO,EAAE,CAAC;QAC9B,MAAM,CAAC,IAAI,CAAC,cA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I,EAAE,CAAC,CAAC,CAAC;QAC7D,OAAO,MAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,OAAO,mCAAI,WAAW,CAAC;KACnC;IAAC,OAAO,GAAG,EAAE;QACb,OAAO,WAAW,CAAC;KACnB;AACF,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-var-requires */\n/* eslint-disable @typescript-eslint/no-require-imports */\nimport { resolve, dirname } from 'path';\nimport { FFmpeg } from 'prism-media';\n\n/**\n * Generates a report of the dependencies used by the \\@discordjs/voice module.\n * Useful for debugging.\n */\nexport function generateDependencyReport() {\n\tconst report = [];\n\tconst addVersion = (name: string) => report.push(`- ${name}: ${version(name)}`);\n\t// general\n\treport.push('Core Dependencies');\n\taddVersion('@discordjs/voice');\n\taddVersion('prism-media');\n\treport.push('');\n\n\t// opus\n\treport.push('Opus Libraries');\n\taddVersion('@discordjs/opus');\n\taddVersion('opusscript');\n\treport.push('');\n\n\t// encryption\n\treport.push('Encryption Libraries');\n\taddVersion('sodium');\n\taddVersion('libsodium-wrappers');\n\taddVersion('tweetnacl');\n\treport.push('');\n\n\t// ffmpeg\n\treport.push('FFmpeg');\n\ttry {\n\t\tconst info = FFmpeg.getInfo();\n\t\treport.push(`- version: ${info.version}`);\n\t\treport.push(`- libopus: ${info.output.includes('--enable-libopus') ? 'yes' : 'no'}`);\n\t} catch (err) {\n\t\treport.push('- not found');\n\t}\n\n\treturn ['-'.repeat(50), ...report, '-'.repeat(50)].join('\\n');\n}\n\n/**\n * Tries to find the package.json file for a given module.\n *\n * @param dir - The directory to look in\n * @param packageName - The name of the package to look for\n * @param depth - The maximum recursion depth\n */\nfunction findPackageJSON(\n\tdir: string,\n\tpackageName: string,\n\tdepth: number,\n): { name: string; version: string } | undefined {\n\tif (depth === 0) return undefined;\n\tconst attemptedPath = resolve(dir, './package.json');\n\ttry {\n\t\tconst pkg = require(attemptedPath);\n\t\tif (pkg.name !== packageName) throw new Error('package.json does not match');\n\t\treturn pkg;\n\t} catch (err) {\n\t\treturn findPackageJSON(resolve(dir, '..'), packageName, depth - 1);\n\t}\n}\n\n/**\n * Tries to find the version of a dependency.\n *\n * @param name - The package to find the version of\n */\nfunction version(name: string): string {\n\ttry {\n\t\tconst pkg =\n\t\t\tname === '@discordjs/voice'\n\t\t\t\t? require('../../package.json')\n\t\t\t\t: findPackageJSON(dirname(require.resolve(name)), name, 3);\n\t\treturn pkg?.version ?? 'not found';\n\t} catch (err) {\n\t\treturn 'not found';\n\t}\n}\n"]}
@@ -1,17 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
- };
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- __exportStar(require("./generateDependencyReport"), exports);
14
- __exportStar(require("./entersState"), exports);
15
- __exportStar(require("./adapter"), exports);
16
- __exportStar(require("./demuxProbe"), exports);
17
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/util/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6DAA2C;AAC3C,gDAA8B;AAC9B,4CAA0B;AAC1B,+CAA6B","sourcesContent":["export * from './generateDependencyReport';\nexport * from './entersState';\nexport * from './adapter';\nexport * from './demuxProbe';\n"]}
package/dist/util/util.js DELETED
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noop = void 0;
4
- // eslint-disable-next-line @typescript-eslint/no-empty-function
5
- const noop = () => { };
6
- exports.noop = noop;
7
- //# sourceMappingURL=util.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/util/util.ts"],"names":[],"mappings":";;;AAAA,gEAAgE;AACzD,MAAM,IAAI,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;AAAhB,QAAA,IAAI,QAAY","sourcesContent":["// eslint-disable-next-line @typescript-eslint/no-empty-function\nexport const noop = () => {};\n\nexport type Awaited<T> = T | Promise<T>;\n"]}