discord-player 5.3.2-dev.2 → 5.3.2-dev.3
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/dist/Player.js +26 -2
- package/dist/Structures/Queue.js +35 -0
- package/dist/index.d.ts +63 -2
- package/dist/index.js +4 -0
- package/dist/utils/AudioFilters.js +35 -37
- package/dist/utils/Util.js +3 -2
- package/package.json +1 -1
package/dist/Player.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var _Player_lastLatency;
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
4
|
exports.Player = void 0;
|
|
4
5
|
const tslib_1 = require("tslib");
|
|
@@ -33,12 +34,14 @@ class Player extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
33
34
|
highWaterMark: 1 << 25
|
|
34
35
|
},
|
|
35
36
|
connectionTimeout: 20000,
|
|
36
|
-
smoothVolume: true
|
|
37
|
+
smoothVolume: true,
|
|
38
|
+
lagMonitor: 30000
|
|
37
39
|
};
|
|
38
40
|
this.queues = new discord_js_1.Collection();
|
|
39
41
|
this.voiceUtils = new VoiceUtils_1.VoiceUtils();
|
|
40
42
|
this.extractors = new discord_js_1.Collection();
|
|
41
43
|
this.requiredEvents = ["error", "connectionError"];
|
|
44
|
+
_Player_lastLatency.set(this, -1);
|
|
42
45
|
/**
|
|
43
46
|
* The discord.js client
|
|
44
47
|
* @type {Client}
|
|
@@ -59,6 +62,27 @@ class Player extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
59
62
|
["Attachment", "Facebook", "Reverbnation", "Vimeo"].forEach((ext) => void this.use(ext, nv[ext]));
|
|
60
63
|
}
|
|
61
64
|
}
|
|
65
|
+
if (typeof this.options.lagMonitor === "number" && this.options.lagMonitor > 0) {
|
|
66
|
+
setInterval(() => {
|
|
67
|
+
const start = performance.now();
|
|
68
|
+
setTimeout(() => {
|
|
69
|
+
tslib_1.__classPrivateFieldSet(this, _Player_lastLatency, performance.now() - start, "f");
|
|
70
|
+
}, 0).unref();
|
|
71
|
+
}, this.options.lagMonitor).unref();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Event loop lag
|
|
76
|
+
* @type {number}
|
|
77
|
+
*/
|
|
78
|
+
get eventLoopLag() {
|
|
79
|
+
return tslib_1.__classPrivateFieldGet(this, _Player_lastLatency, "f");
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Generates statistics
|
|
83
|
+
*/
|
|
84
|
+
generateStatistics() {
|
|
85
|
+
return this.queues.map((m) => m.generateStatistics());
|
|
62
86
|
}
|
|
63
87
|
/**
|
|
64
88
|
* Handles voice state update
|
|
@@ -569,7 +593,7 @@ class Player extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
569
593
|
resolveQueue(queueLike) {
|
|
570
594
|
return this.getQueue(queueLike instanceof Queue_1.Queue ? queueLike.guild : queueLike);
|
|
571
595
|
}
|
|
572
|
-
*[Symbol.iterator]() {
|
|
596
|
+
*[(_Player_lastLatency = new WeakMap(), Symbol.iterator)]() {
|
|
573
597
|
yield* Array.from(this.queues.values());
|
|
574
598
|
}
|
|
575
599
|
/**
|
package/dist/Structures/Queue.js
CHANGED
|
@@ -13,6 +13,8 @@ const youtube_sr_1 = tslib_1.__importDefault(require("youtube-sr"));
|
|
|
13
13
|
const AudioFilters_1 = tslib_1.__importDefault(require("../utils/AudioFilters"));
|
|
14
14
|
const PlayerError_1 = require("./PlayerError");
|
|
15
15
|
const FFmpegStream_1 = require("../utils/FFmpegStream");
|
|
16
|
+
const os_1 = tslib_1.__importDefault(require("os"));
|
|
17
|
+
const worker_threads_1 = require("worker_threads");
|
|
16
18
|
class Queue {
|
|
17
19
|
/**
|
|
18
20
|
* Queue constructor
|
|
@@ -632,6 +634,39 @@ class Queue {
|
|
|
632
634
|
return;
|
|
633
635
|
return this.tracks.length > 0 ? this.tracks.map((t) => t.durationMS).reduce((p, c) => p + c) : 0;
|
|
634
636
|
}
|
|
637
|
+
/**
|
|
638
|
+
* Generates statistics
|
|
639
|
+
*/
|
|
640
|
+
generateStatistics() {
|
|
641
|
+
return {
|
|
642
|
+
guild: this.guild.id,
|
|
643
|
+
memory: process.memoryUsage(),
|
|
644
|
+
tracks: this.tracks.length,
|
|
645
|
+
os: {
|
|
646
|
+
cpuCount: os_1.default.cpus().length,
|
|
647
|
+
totalMem: os_1.default.totalmem(),
|
|
648
|
+
freeMem: os_1.default.freemem(),
|
|
649
|
+
platform: process.platform
|
|
650
|
+
},
|
|
651
|
+
isShard: typeof process.send === "function" || worker_threads_1.parentPort != null,
|
|
652
|
+
latency: {
|
|
653
|
+
client: this.player.client.ws.ping,
|
|
654
|
+
udp: this.connection.voiceConnection.ping.udp,
|
|
655
|
+
ws: this.connection.voiceConnection.ping.ws,
|
|
656
|
+
eventLoop: this.player.eventLoopLag
|
|
657
|
+
},
|
|
658
|
+
subscribers: this.player.queues.size,
|
|
659
|
+
connections: this.player.queues.filter((x) => x.connection?.voiceConnection != null).size,
|
|
660
|
+
extractors: this.player.extractors.size
|
|
661
|
+
};
|
|
662
|
+
}
|
|
663
|
+
/**
|
|
664
|
+
* Voice connection latency in ms
|
|
665
|
+
* @type {number}
|
|
666
|
+
*/
|
|
667
|
+
get ping() {
|
|
668
|
+
return this.connection.voiceConnection.ping.udp;
|
|
669
|
+
}
|
|
635
670
|
/**
|
|
636
671
|
* Play stream in a voice/stage channel
|
|
637
672
|
* @param {Track} [src] The track to play (if empty, uses first track from the queue)
|
package/dist/index.d.ts
CHANGED
|
@@ -234,6 +234,7 @@ declare class ExtractorModel {
|
|
|
234
234
|
}
|
|
235
235
|
|
|
236
236
|
declare class Player extends TypedEmitter<PlayerEvents> {
|
|
237
|
+
#private;
|
|
237
238
|
readonly client: Client;
|
|
238
239
|
readonly options: PlayerInitOptions;
|
|
239
240
|
readonly queues: Collection<string, Queue<unknown>>;
|
|
@@ -246,6 +247,35 @@ declare class Player extends TypedEmitter<PlayerEvents> {
|
|
|
246
247
|
* @param {PlayerInitOptions} [options] The player init options
|
|
247
248
|
*/
|
|
248
249
|
constructor(client: Client, options?: PlayerInitOptions);
|
|
250
|
+
/**
|
|
251
|
+
* Event loop lag
|
|
252
|
+
* @type {number}
|
|
253
|
+
*/
|
|
254
|
+
get eventLoopLag(): number;
|
|
255
|
+
/**
|
|
256
|
+
* Generates statistics
|
|
257
|
+
*/
|
|
258
|
+
generateStatistics(): {
|
|
259
|
+
guild: string;
|
|
260
|
+
memory: NodeJS.MemoryUsage;
|
|
261
|
+
tracks: number;
|
|
262
|
+
os: {
|
|
263
|
+
cpuCount: number;
|
|
264
|
+
totalMem: number;
|
|
265
|
+
freeMem: number;
|
|
266
|
+
platform: NodeJS.Platform;
|
|
267
|
+
};
|
|
268
|
+
isShard: boolean;
|
|
269
|
+
latency: {
|
|
270
|
+
client: number;
|
|
271
|
+
udp: number;
|
|
272
|
+
ws: number;
|
|
273
|
+
eventLoop: number;
|
|
274
|
+
};
|
|
275
|
+
subscribers: number;
|
|
276
|
+
connections: number;
|
|
277
|
+
extractors: number;
|
|
278
|
+
}[];
|
|
249
279
|
/**
|
|
250
280
|
* Handles voice state update
|
|
251
281
|
* @param {VoiceState} oldState The old voice state
|
|
@@ -528,6 +558,35 @@ declare class Queue<T = unknown> {
|
|
|
528
558
|
* @type {Number}
|
|
529
559
|
*/
|
|
530
560
|
get totalTime(): number;
|
|
561
|
+
/**
|
|
562
|
+
* Generates statistics
|
|
563
|
+
*/
|
|
564
|
+
generateStatistics(): {
|
|
565
|
+
guild: string;
|
|
566
|
+
memory: NodeJS.MemoryUsage;
|
|
567
|
+
tracks: number;
|
|
568
|
+
os: {
|
|
569
|
+
cpuCount: number;
|
|
570
|
+
totalMem: number;
|
|
571
|
+
freeMem: number;
|
|
572
|
+
platform: NodeJS.Platform;
|
|
573
|
+
};
|
|
574
|
+
isShard: boolean;
|
|
575
|
+
latency: {
|
|
576
|
+
client: number;
|
|
577
|
+
udp: number;
|
|
578
|
+
ws: number;
|
|
579
|
+
eventLoop: number;
|
|
580
|
+
};
|
|
581
|
+
subscribers: number;
|
|
582
|
+
connections: number;
|
|
583
|
+
extractors: number;
|
|
584
|
+
};
|
|
585
|
+
/**
|
|
586
|
+
* Voice connection latency in ms
|
|
587
|
+
* @type {number}
|
|
588
|
+
*/
|
|
589
|
+
get ping(): number;
|
|
531
590
|
/**
|
|
532
591
|
* Play stream in a voice/stage channel
|
|
533
592
|
* @param {Track} [src] The track to play (if empty, uses first track from the queue)
|
|
@@ -1005,17 +1064,19 @@ interface PlaylistJSON {
|
|
|
1005
1064
|
* @property {YTDLDownloadOptions} [ytdlOptions] The options passed to `ytdl-core`
|
|
1006
1065
|
* @property {number} [connectionTimeout=20000] The voice connection timeout
|
|
1007
1066
|
* @property {boolean} [smoothVolume=true] Toggle smooth volume transition
|
|
1067
|
+
* @property {boolean} [lagMonitor=30000] Time in ms to re-monitor event loop lag
|
|
1008
1068
|
*/
|
|
1009
1069
|
interface PlayerInitOptions {
|
|
1010
1070
|
autoRegisterExtractor?: boolean;
|
|
1011
1071
|
ytdlOptions?: downloadOptions;
|
|
1012
1072
|
connectionTimeout?: number;
|
|
1013
1073
|
smoothVolume?: boolean;
|
|
1074
|
+
lagMonitor?: number;
|
|
1014
1075
|
}
|
|
1015
1076
|
|
|
1016
1077
|
declare class AudioFilters {
|
|
1017
1078
|
constructor();
|
|
1018
|
-
static
|
|
1079
|
+
static filters: Record<FiltersName, string>;
|
|
1019
1080
|
static get<K extends FiltersName>(name: K): Record<keyof QueueFilters, string>[K];
|
|
1020
1081
|
static has<K extends FiltersName>(name: K): boolean;
|
|
1021
1082
|
static [Symbol.iterator](): IterableIterator<{
|
|
@@ -1176,7 +1237,7 @@ declare class Util {
|
|
|
1176
1237
|
* @param {number} time The time in ms to wait
|
|
1177
1238
|
* @returns {Promise<unknown>}
|
|
1178
1239
|
*/
|
|
1179
|
-
static wait(time: number): Promise<
|
|
1240
|
+
static wait(time: number): Promise<any>;
|
|
1180
1241
|
static noop(): void;
|
|
1181
1242
|
static getFetch(): Promise<any>;
|
|
1182
1243
|
}
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.version = exports.Util = exports.StreamDispatcher = exports.VoiceUtils =
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
// try applying smooth volume patch on load
|
|
6
6
|
require("./smoothVolume");
|
|
7
|
+
const discord_js_1 = require("discord.js");
|
|
7
8
|
var AudioFilters_1 = require("./utils/AudioFilters");
|
|
8
9
|
Object.defineProperty(exports, "AudioFilters", { enumerable: true, get: function () { return AudioFilters_1.AudioFilters; } });
|
|
9
10
|
var ExtractorModel_1 = require("./Structures/ExtractorModel");
|
|
@@ -32,3 +33,6 @@ tslib_1.__exportStar(require("./types/types"), exports);
|
|
|
32
33
|
tslib_1.__exportStar(require("./utils/FFmpegStream"), exports);
|
|
33
34
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
34
35
|
exports.version = require(`${__dirname}/../package.json`).version;
|
|
36
|
+
if (!discord_js_1.version.startsWith("14")) {
|
|
37
|
+
process.emitWarning(`Discord.js v${discord_js_1.version} is incompatible with Discord Player v${exports.version}! Please use >=v14.x of Discord.js`);
|
|
38
|
+
}
|
|
@@ -6,43 +6,6 @@ class AudioFilters {
|
|
|
6
6
|
constructor() {
|
|
7
7
|
return AudioFilters;
|
|
8
8
|
}
|
|
9
|
-
static get filters() {
|
|
10
|
-
return {
|
|
11
|
-
bassboost_low: bass(15),
|
|
12
|
-
bassboost: bass(20),
|
|
13
|
-
bassboost_high: bass(30),
|
|
14
|
-
"8D": "apulsator=hz=0.09",
|
|
15
|
-
vaporwave: "aresample=48000,asetrate=48000*0.8",
|
|
16
|
-
nightcore: "aresample=48000,asetrate=48000*1.25",
|
|
17
|
-
phaser: "aphaser=in_gain=0.4",
|
|
18
|
-
tremolo: "tremolo",
|
|
19
|
-
vibrato: "vibrato=f=6.5",
|
|
20
|
-
reverse: "areverse",
|
|
21
|
-
treble: "treble=g=5",
|
|
22
|
-
normalizer2: "dynaudnorm=g=101",
|
|
23
|
-
normalizer: "acompressor",
|
|
24
|
-
surrounding: "surround",
|
|
25
|
-
pulsator: "apulsator=hz=1",
|
|
26
|
-
subboost: "asubboost",
|
|
27
|
-
karaoke: "stereotools=mlev=0.03",
|
|
28
|
-
flanger: "flanger",
|
|
29
|
-
gate: "agate",
|
|
30
|
-
haas: "haas",
|
|
31
|
-
mcompand: "mcompand",
|
|
32
|
-
mono: "pan=mono|c0=.5*c0+.5*c1",
|
|
33
|
-
mstlr: "stereotools=mode=ms>lr",
|
|
34
|
-
mstrr: "stereotools=mode=ms>rr",
|
|
35
|
-
compressor: "compand=points=-80/-105|-62/-80|-15.4/-15.4|0/-12|20/-7.6",
|
|
36
|
-
expander: "compand=attacks=0:points=-80/-169|-54/-80|-49.5/-64.6|-41.1/-41.1|-25.8/-15|-10.8/-4.5|0/0|20/8.3",
|
|
37
|
-
softlimiter: "compand=attacks=0:points=-80/-80|-12.4/-12.4|-6/-8|0/-6.8|20/-2.8",
|
|
38
|
-
chorus: "chorus=0.7:0.9:55:0.4:0.25:2",
|
|
39
|
-
chorus2d: "chorus=0.6:0.9:50|60:0.4|0.32:0.25|0.4:2|1.3",
|
|
40
|
-
chorus3d: "chorus=0.5:0.9:50|60|40:0.4|0.32|0.3:0.25|0.4|0.3:2|2.3|1.3",
|
|
41
|
-
fadein: "afade=t=in:ss=0:d=10",
|
|
42
|
-
dim: `afftfilt="'real=re * (1-clip((b/nb)*b,0,1))':imag='im * (1-clip((b/nb)*b,0,1))'"`,
|
|
43
|
-
earrape: "channelsplit,sidechaingate=level_in=64"
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
9
|
static get(name) {
|
|
47
10
|
return this.filters[name];
|
|
48
11
|
}
|
|
@@ -94,4 +57,39 @@ class AudioFilters {
|
|
|
94
57
|
}
|
|
95
58
|
}
|
|
96
59
|
exports.AudioFilters = AudioFilters;
|
|
60
|
+
AudioFilters.filters = {
|
|
61
|
+
bassboost_low: bass(15),
|
|
62
|
+
bassboost: bass(20),
|
|
63
|
+
bassboost_high: bass(30),
|
|
64
|
+
"8D": "apulsator=hz=0.09",
|
|
65
|
+
vaporwave: "aresample=48000,asetrate=48000*0.8",
|
|
66
|
+
nightcore: "aresample=48000,asetrate=48000*1.25",
|
|
67
|
+
phaser: "aphaser=in_gain=0.4",
|
|
68
|
+
tremolo: "tremolo",
|
|
69
|
+
vibrato: "vibrato=f=6.5",
|
|
70
|
+
reverse: "areverse",
|
|
71
|
+
treble: "treble=g=5",
|
|
72
|
+
normalizer2: "dynaudnorm=g=101",
|
|
73
|
+
normalizer: "acompressor",
|
|
74
|
+
surrounding: "surround",
|
|
75
|
+
pulsator: "apulsator=hz=1",
|
|
76
|
+
subboost: "asubboost",
|
|
77
|
+
karaoke: "stereotools=mlev=0.03",
|
|
78
|
+
flanger: "flanger",
|
|
79
|
+
gate: "agate",
|
|
80
|
+
haas: "haas",
|
|
81
|
+
mcompand: "mcompand",
|
|
82
|
+
mono: "pan=mono|c0=.5*c0+.5*c1",
|
|
83
|
+
mstlr: "stereotools=mode=ms>lr",
|
|
84
|
+
mstrr: "stereotools=mode=ms>rr",
|
|
85
|
+
compressor: "compand=points=-80/-105|-62/-80|-15.4/-15.4|0/-12|20/-7.6",
|
|
86
|
+
expander: "compand=attacks=0:points=-80/-169|-54/-80|-49.5/-64.6|-41.1/-41.1|-25.8/-15|-10.8/-4.5|0/0|20/8.3",
|
|
87
|
+
softlimiter: "compand=attacks=0:points=-80/-80|-12.4/-12.4|-6/-8|0/-6.8|20/-2.8",
|
|
88
|
+
chorus: "chorus=0.7:0.9:55:0.4:0.25:2",
|
|
89
|
+
chorus2d: "chorus=0.6:0.9:50|60:0.4|0.32:0.25|0.4:2|1.3",
|
|
90
|
+
chorus3d: "chorus=0.5:0.9:50|60|40:0.4|0.32|0.3:0.25|0.4|0.3:2|2.3|1.3",
|
|
91
|
+
fadein: "afade=t=in:ss=0:d=10",
|
|
92
|
+
dim: `afftfilt="'real=re * (1-clip((b/nb)*b,0,1))':imag='im * (1-clip((b/nb)*b,0,1))'"`,
|
|
93
|
+
earrape: "channelsplit,sidechaingate=level_in=64"
|
|
94
|
+
};
|
|
97
95
|
exports.default = AudioFilters;
|
package/dist/utils/Util.js
CHANGED
|
@@ -24,6 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.Util = void 0;
|
|
27
|
+
const promises_1 = require("timers/promises");
|
|
27
28
|
class Util {
|
|
28
29
|
/**
|
|
29
30
|
* Utils
|
|
@@ -108,13 +109,13 @@ class Util {
|
|
|
108
109
|
* @returns {Promise<unknown>}
|
|
109
110
|
*/
|
|
110
111
|
static wait(time) {
|
|
111
|
-
return
|
|
112
|
+
return (0, promises_1.setTimeout)(time, undefined, { ref: false });
|
|
112
113
|
}
|
|
113
114
|
static noop() { } // eslint-disable-line @typescript-eslint/no-empty-function
|
|
114
115
|
static async getFetch() {
|
|
115
116
|
if ("fetch" in globalThis)
|
|
116
117
|
return globalThis.fetch;
|
|
117
|
-
for (const lib of ["
|
|
118
|
+
for (const lib of ["node-fetch", "undici"]) {
|
|
118
119
|
try {
|
|
119
120
|
return await Promise.resolve().then(() => __importStar(require(lib))).then((res) => res.fetch || res.default?.fetch || res.default);
|
|
120
121
|
}
|