@discordjs/voice 0.5.4 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +190 -21
- package/README.md +41 -18
- package/dist/index.d.ts +357 -216
- package/dist/index.js +10 -26
- package/dist/index.js.map +7 -1
- package/dist/index.mjs +10 -0
- package/dist/index.mjs.map +7 -0
- package/package.json +67 -93
- package/dist/DataStore.js +0 -151
- package/dist/DataStore.js.map +0 -1
- package/dist/VoiceConnection.js +0 -494
- package/dist/VoiceConnection.js.map +0 -1
- package/dist/audio/AudioPlayer.js +0 -449
- package/dist/audio/AudioPlayer.js.map +0 -1
- package/dist/audio/AudioPlayerError.js +0 -17
- package/dist/audio/AudioPlayerError.js.map +0 -1
- package/dist/audio/AudioResource.js +0 -164
- package/dist/audio/AudioResource.js.map +0 -1
- package/dist/audio/PlayerSubscription.js +0 -23
- package/dist/audio/PlayerSubscription.js.map +0 -1
- package/dist/audio/TransformerGraph.js +0 -233
- package/dist/audio/TransformerGraph.js.map +0 -1
- package/dist/audio/index.js +0 -18
- package/dist/audio/index.js.map +0 -1
- package/dist/joinVoiceChannel.js +0 -24
- package/dist/joinVoiceChannel.js.map +0 -1
- package/dist/networking/Networking.js +0 -457
- package/dist/networking/Networking.js.map +0 -1
- package/dist/networking/VoiceUDPSocket.js +0 -145
- package/dist/networking/VoiceUDPSocket.js.map +0 -1
- package/dist/networking/VoiceWebSocket.js +0 -129
- package/dist/networking/VoiceWebSocket.js.map +0 -1
- package/dist/networking/index.js +0 -16
- package/dist/networking/index.js.map +0 -1
- package/dist/receive/AudioReceiveStream.js +0 -20
- package/dist/receive/AudioReceiveStream.js.map +0 -1
- package/dist/receive/SSRCMap.js +0 -67
- package/dist/receive/SSRCMap.js.map +0 -1
- package/dist/receive/VoiceReceiver.js +0 -215
- package/dist/receive/VoiceReceiver.js.map +0 -1
- package/dist/receive/index.js +0 -16
- package/dist/receive/index.js.map +0 -1
- package/dist/util/Secretbox.js +0 -50
- package/dist/util/Secretbox.js.map +0 -1
- package/dist/util/adapter.js +0 -3
- package/dist/util/adapter.js.map +0 -1
- package/dist/util/demuxProbe.js +0 -90
- package/dist/util/demuxProbe.js.map +0 -1
- package/dist/util/entersState.js +0 -30
- package/dist/util/entersState.js.map +0 -1
- package/dist/util/generateDependencyReport.js +0 -82
- package/dist/util/generateDependencyReport.js.map +0 -1
- package/dist/util/index.js +0 -17
- package/dist/util/index.js.map +0 -1
- package/dist/util/util.js +0 -7
- package/dist/util/util.js.map +0 -1
package/dist/util/demuxProbe.js
DELETED
|
@@ -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,SAAS,CAAC,CAAC,CAAC,CAAC;IACvC,MAAM,UAAU,GAAG,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;IAC7C,OAAO,QAAQ,KAAK,CAAC,IAAI,UAAU,KAAK,KAAK,CAAC;AAC/C,CAAC;AAJD,0DAIC;AAiBD;;;;;;GAMG;AACH,SAAgB,UAAU,CACzB,MAAgB,EAChB,SAAS,GAAG,IAAI,EAChB,SAAS,GAAG,uBAAuB;IAEnC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACtC,gBAAgB;QAChB,IAAI,MAAM,CAAC,kBAAkB;YAAE,MAAM,CAAC,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC,CAAC;QAClG,IAAI,MAAM,CAAC,aAAa;YAAE,MAAM,CAAC,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC,CAAC;QAEpF,IA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AO,EAAE,WAAI,CAAC,CAAC;QACxB,GAAG,CAAC,EAAE,CAAC,MAAM,EAAE,SAAS,CAAC,cAAU,CAAC,OAAO,CAAC,CAAC,CAAC;QAE9C,MAAM,OAAO,GAAG,GAAG,EAAE;YACpB,IAAI,CAAC,QAAQ,EAAE;gBACd,MAAM,CAAC,cAAU,CAAC,SAAS,CAAC,CAAC;aAC7B;QACF,CAAC,CAAC;QAEF,MAAM,MAAM,GAAG,CAAC,MAAc,EAAE,EAAE;YACjC,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC;YAEjD,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;YACnB,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;YAElB,IAAI,UAAU,CAAC,MAAM,IAAI,SAAS,EAAE;gBACnC,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;gBAC3B,MAAM,CAAC,KAAK,EAAE,CAAC;gBACf,OAAO,CAAC,QAAQ,CAAC,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"]}
|
package/dist/util/entersState.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.entersState = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Allows a target a specified amount of time to enter a given state, otherwise rejects with an error.
|
|
6
|
-
*
|
|
7
|
-
* @param target - The object that we want to observe the state change for
|
|
8
|
-
* @param status - The status that the target should be in
|
|
9
|
-
* @param maxTime - The maximum time we are allowing for this to occur
|
|
10
|
-
*/
|
|
11
|
-
function entersState(target, status, maxTime) {
|
|
12
|
-
if (target.state.status === status) {
|
|
13
|
-
return Promise.resolve(target);
|
|
14
|
-
}
|
|
15
|
-
let cleanup;
|
|
16
|
-
return new Promise((resolve, reject) => {
|
|
17
|
-
const timeout = setTimeout(() => reject(new Error(`Did not enter state ${status} within ${maxTime}ms`)), maxTime);
|
|
18
|
-
target.once(status, resolve);
|
|
19
|
-
target.once('error', reject);
|
|
20
|
-
cleanup = () => {
|
|
21
|
-
clearTimeout(timeout);
|
|
22
|
-
target.off(status, resolve);
|
|
23
|
-
target.off('error', reject);
|
|
24
|
-
};
|
|
25
|
-
})
|
|
26
|
-
.then(() => target)
|
|
27
|
-
.finally(cleanup);
|
|
28
|
-
}
|
|
29
|
-
exports.entersState = entersState;
|
|
30
|
-
//# sourceMappingURL=entersState.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"entersState.js","sourceRoot":"","sources":["../../src/util/entersState.ts"],"names":[],"mappings":";;;AAyBA;;;;;;GAMG;AACH,SAAgB,WAAW,CAC1B,MAAS,EACT,MAAiD,EACjD,OAAe;IAEf,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,KAAK,MAAM,EAAE;QACnC,OAAO,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;KAC/B;IACD,IAAI,OAAmB,CAAC;IACxB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACtC,MAAM,OAAO,GAAG,UAAU,CACzB,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,uBAAuB,MAAgB,WAAW,OAAO,IAAI,CAAC,CAAC,EACtF,OAAO,CACP,CAAC;QAED,MAAc,CAAC,IAAI,CAAC,MAAa,EAAE,OAAO,CAAC,CAAC;QAC5C,MAAc,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAEtC,OAAO,GAAG,GAAG,EAAE;YACd,YAAY,CAAC,OAAO,CAAC,CAAC;YACrB,MAAc,CAAC,GAAG,CAAC,MAAa,EAAE,OAAO,CAAC,CAAC;YAC3C,MAAc,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QACtC,CAAC,CAAC;IACH,CAAC,CAAC;SACA,IAAI,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC;SAClB,OAAO,CAAC,OAAQ,CAAC,CAAC;AACrB,CAAC;AA1BD,kCA0BC","sourcesContent":["import { VoiceConnection, VoiceConnectionStatus } from '../VoiceConnection';\nimport { AudioPlayer, AudioPlayerStatus } from '../audio/AudioPlayer';\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 maxTime - The maximum time we are allowing for this to occur\n */\nexport function entersState(\n\ttarget: VoiceConnection,\n\tstatus: VoiceConnectionStatus,\n\tmaxTime: number,\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 maxTime - The maximum time we are allowing for this to occur\n */\nexport function entersState(target: AudioPlayer, status: AudioPlayerStatus, maxTime: number): 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 maxTime - The maximum time we are allowing for this to occur\n */\nexport function entersState<T extends VoiceConnection | AudioPlayer>(\n\ttarget: T,\n\tstatus: VoiceConnectionStatus | AudioPlayerStatus,\n\tmaxTime: number,\n) {\n\tif (target.state.status === status) {\n\t\treturn Promise.resolve(target);\n\t}\n\tlet cleanup: () => void;\n\treturn new Promise((resolve, reject) => {\n\t\tconst timeout = setTimeout(\n\t\t\t() => reject(new Error(`Did not enter state ${status as string} within ${maxTime}ms`)),\n\t\t\tmaxTime,\n\t\t);\n\n\t\t(target as any).once(status as any, resolve);\n\t\t(target as any).once('error', reject);\n\n\t\tcleanup = () => {\n\t\t\tclearTimeout(timeout);\n\t\t\t(target as any).off(status as any, resolve);\n\t\t\t(target as any).off('error', reject);\n\t\t};\n\t})\n\t\t.then(() => target)\n\t\t.finally(cleanup!);\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,CAA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,4DAiCC;AAED;;;;;;GAMG;AACH,SAAS,eAAe,CACvB,GAAW,EACX,WAAmB,EACnB,KAAa;IAEb,IAAI,KAAK,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IAClC,MAAM,aAAa,GAAG,cAAO,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;IACrD,IAAI;QACH,MAAM,GAAG,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;QACnC,IAAI,GAAG,CAAC,IAAI,KAAK,WAAW;YAAE,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;QAC7E,OAAO,GAAG,CAAC;KACX;IAAC,OAAO,GAAG,EAAE;QACb,OAAO,eAAe,CAAC,cAAO,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,WAAW,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;KACnE;AACF,CAAC;AAED;;;;GAIG;AACH,SAAS,OAAO,CAAC,IAAY;;IAC5B,IAAI;QACH,MAAM,GAAG,GACR,IAAI,KAAK,kBAAkB;YAC1B,CAAC,CAAC,OAAO,CAAC,oBAAoB,CAAC;YAC/B,CAAC,CAAC,eAAe,CAAC,cAAO,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,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"]}
|
package/dist/util/index.js
DELETED
|
@@ -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
|
package/dist/util/index.js.map
DELETED
|
@@ -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
package/dist/util/util.js.map
DELETED
|
@@ -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"]}
|