discord-player 5.2.1 → 5.2.2
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/README.md +1 -1
- package/dist/Player.js +4 -4
- package/dist/Structures/Queue.js +8 -4
- package/dist/VoiceInterface/VoiceUtils.js +7 -2
- package/dist/{VolumeTransformer.js → VoiceInterface/VolumeTransformer.js} +35 -9
- package/dist/index.d.ts +3 -0
- package/dist/index.js +2 -0
- package/dist/smoothVolume.js +11 -3
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -168,7 +168,7 @@ These bots are made by the community, they can help you build your own!
|
|
|
168
168
|
|
|
169
169
|
### Smooth Volume
|
|
170
170
|
|
|
171
|
-
Discord Player will
|
|
171
|
+
Discord Player will by default try to implement this. If smooth volume does not work, you need to add this line at the top of your main file:
|
|
172
172
|
|
|
173
173
|
```js
|
|
174
174
|
// CJS
|
package/dist/Player.js
CHANGED
|
@@ -26,7 +26,7 @@ class Player extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
26
26
|
* @param {PlayerInitOptions} [options={}] The player init options
|
|
27
27
|
*/
|
|
28
28
|
constructor(client, options = {}) {
|
|
29
|
-
var _a;
|
|
29
|
+
var _a, _b, _c, _d, _e;
|
|
30
30
|
super();
|
|
31
31
|
this.options = {
|
|
32
32
|
autoRegisterExtractor: true,
|
|
@@ -44,7 +44,7 @@ class Player extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
44
44
|
* @type {Client}
|
|
45
45
|
*/
|
|
46
46
|
this.client = client;
|
|
47
|
-
if (!new discord_js_1.Intents(this.client.options.intents).has(discord_js_1.Intents.FLAGS.GUILD_VOICE_STATES)) {
|
|
47
|
+
if (((_b = (_a = this.client) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.intents) && !new discord_js_1.Intents((_d = (_c = this.client) === null || _c === void 0 ? void 0 : _c.options) === null || _d === void 0 ? void 0 : _d.intents).has(discord_js_1.Intents.FLAGS.GUILD_VOICE_STATES)) {
|
|
48
48
|
throw new PlayerError_1.PlayerError('client is missing "GUILD_VOICE_STATES" intent');
|
|
49
49
|
}
|
|
50
50
|
/**
|
|
@@ -53,7 +53,7 @@ class Player extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
53
53
|
*/
|
|
54
54
|
this.options = Object.assign(this.options, options);
|
|
55
55
|
this.client.on("voiceStateUpdate", this._handleVoiceState.bind(this));
|
|
56
|
-
if ((
|
|
56
|
+
if ((_e = this.options) === null || _e === void 0 ? void 0 : _e.autoRegisterExtractor) {
|
|
57
57
|
let nv; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
58
58
|
if ((nv = Util_1.Util.require("@discord-player/extractor"))) {
|
|
59
59
|
["Attachment", "Facebook", "Reverbnation", "Vimeo"].forEach((ext) => void this.use(ext, nv[ext]));
|
|
@@ -157,7 +157,7 @@ class Player extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
157
157
|
return this.queues.get(guild.id);
|
|
158
158
|
const _meta = queueInitOptions.metadata;
|
|
159
159
|
delete queueInitOptions["metadata"];
|
|
160
|
-
(_a = queueInitOptions.volumeSmoothness) !== null && _a !== void 0 ? _a : (queueInitOptions.volumeSmoothness = 0.
|
|
160
|
+
(_a = queueInitOptions.volumeSmoothness) !== null && _a !== void 0 ? _a : (queueInitOptions.volumeSmoothness = 0.08);
|
|
161
161
|
(_b = queueInitOptions.ytdlOptions) !== null && _b !== void 0 ? _b : (queueInitOptions.ytdlOptions = this.options.ytdlOptions);
|
|
162
162
|
const queue = new Queue_1.Queue(this, guild, queueInitOptions);
|
|
163
163
|
queue.metadata = _meta;
|
package/dist/Structures/Queue.js
CHANGED
|
@@ -138,8 +138,7 @@ class Queue {
|
|
|
138
138
|
if (!["GUILD_STAGE_VOICE", "GUILD_VOICE"].includes(_channel === null || _channel === void 0 ? void 0 : _channel.type))
|
|
139
139
|
throw new PlayerError_1.PlayerError(`Channel type must be GUILD_VOICE or GUILD_STAGE_VOICE, got ${_channel === null || _channel === void 0 ? void 0 : _channel.type}!`, PlayerError_1.ErrorStatusCode.INVALID_ARG_TYPE);
|
|
140
140
|
const connection = yield this.player.voiceUtils.connect(_channel, {
|
|
141
|
-
deaf: this.options.autoSelfDeaf
|
|
142
|
-
maxTime: this.player.options.connectionTimeout || 20000
|
|
141
|
+
deaf: this.options.autoSelfDeaf
|
|
143
142
|
});
|
|
144
143
|
this.connection = connection;
|
|
145
144
|
if (_channel.type === "GUILD_STAGE_VOICE") {
|
|
@@ -195,6 +194,9 @@ class Queue {
|
|
|
195
194
|
return;
|
|
196
195
|
}
|
|
197
196
|
}));
|
|
197
|
+
yield this.player.voiceUtils.enterReady(this.connection.voiceConnection, {
|
|
198
|
+
maxTime: this.player.options.connectionTimeout || 30000
|
|
199
|
+
});
|
|
198
200
|
return this;
|
|
199
201
|
});
|
|
200
202
|
}
|
|
@@ -702,8 +704,10 @@ class Queue {
|
|
|
702
704
|
if (options.seek)
|
|
703
705
|
this._streamTime = options.seek;
|
|
704
706
|
this._filtersUpdate = options.filtersUpdate;
|
|
705
|
-
|
|
706
|
-
|
|
707
|
+
const volumeTransformer = resource.volume;
|
|
708
|
+
if ((volumeTransformer === null || volumeTransformer === void 0 ? void 0 : volumeTransformer.hasSmoothness) && typeof this.options.volumeSmoothness === "number") {
|
|
709
|
+
if (typeof volumeTransformer.setSmoothness === "function")
|
|
710
|
+
volumeTransformer.setSmoothness(this.options.volumeSmoothness || 0);
|
|
707
711
|
}
|
|
708
712
|
this.setVolume(this.options.initialVolume);
|
|
709
713
|
setTimeout(() => {
|
|
@@ -38,14 +38,19 @@ class VoiceUtils {
|
|
|
38
38
|
* @returns {VoiceConnection}
|
|
39
39
|
*/
|
|
40
40
|
join(channel, options) {
|
|
41
|
-
var _a;
|
|
42
41
|
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
|
|
43
|
-
|
|
42
|
+
const conn = (0, voice_1.joinVoiceChannel)({
|
|
44
43
|
guildId: channel.guild.id,
|
|
45
44
|
channelId: channel.id,
|
|
46
45
|
adapterCreator: channel.guild.voiceAdapterCreator,
|
|
47
46
|
selfDeaf: Boolean(options.deaf)
|
|
48
47
|
});
|
|
48
|
+
return conn;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
enterReady(conn, options = {}) {
|
|
52
|
+
var _a;
|
|
53
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
|
|
49
54
|
try {
|
|
50
55
|
conn = yield (0, voice_1.entersState)(conn, voice_1.VoiceConnectionStatus.Ready, (_a = options === null || options === void 0 ? void 0 : options.maxTime) !== null && _a !== void 0 ? _a : 20000);
|
|
51
56
|
return conn;
|
|
@@ -30,9 +30,12 @@ class VolumeTransformer extends stream_1.Transform {
|
|
|
30
30
|
default:
|
|
31
31
|
throw new Error("VolumeTransformer type should be one of s16le, s16be, s32le, s32be");
|
|
32
32
|
}
|
|
33
|
+
this.type = options.type;
|
|
33
34
|
this._bytes = this._bits / 8;
|
|
34
35
|
this._extremum = Math.pow(2, this._bits - 1);
|
|
35
|
-
this.volume =
|
|
36
|
+
this.volume = Number.isNaN(options.volume) ? 1 : Number(options.volume);
|
|
37
|
+
if (!Number.isFinite(this.volume))
|
|
38
|
+
this.volume = 1;
|
|
36
39
|
this._targetVolume = this.volume;
|
|
37
40
|
this._chunk = Buffer.alloc(0);
|
|
38
41
|
this._smoothing = options.smoothness || 0;
|
|
@@ -43,15 +46,17 @@ class VolumeTransformer extends stream_1.Transform {
|
|
|
43
46
|
_writeInt(buffer, int, index) {
|
|
44
47
|
return index;
|
|
45
48
|
}
|
|
46
|
-
|
|
47
|
-
if (this.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
this.volume = this.volume - this._smoothing <= this._targetVolume ? this._targetVolume : this.volume - this._smoothing;
|
|
53
|
-
}
|
|
49
|
+
_applySmoothness() {
|
|
50
|
+
if (this.volume < this._targetVolume) {
|
|
51
|
+
this.volume = this.volume + this._smoothing >= this._targetVolume ? this._targetVolume : this.volume + this._smoothing;
|
|
52
|
+
}
|
|
53
|
+
else if (this.volume > this._targetVolume) {
|
|
54
|
+
this.volume = this.volume - this._smoothing <= this._targetVolume ? this._targetVolume : this.volume - this._smoothing;
|
|
54
55
|
}
|
|
56
|
+
}
|
|
57
|
+
_transform(chunk, encoding, done) {
|
|
58
|
+
if (this.smoothingEnabled() && this.volume !== this._targetVolume)
|
|
59
|
+
this._applySmoothness();
|
|
55
60
|
if (this.volume === 1) {
|
|
56
61
|
this.push(chunk);
|
|
57
62
|
return done();
|
|
@@ -74,6 +79,12 @@ class VolumeTransformer extends stream_1.Transform {
|
|
|
74
79
|
this._chunk = null;
|
|
75
80
|
}
|
|
76
81
|
setVolume(volume) {
|
|
82
|
+
if (Number.isNaN(volume))
|
|
83
|
+
volume = 1;
|
|
84
|
+
if (typeof volume !== "number")
|
|
85
|
+
volume = Number(volume);
|
|
86
|
+
if (!Number.isFinite(volume))
|
|
87
|
+
volume = volume < 0 ? 0 : 1;
|
|
77
88
|
this._targetVolume = volume;
|
|
78
89
|
if (this._smoothing <= 0)
|
|
79
90
|
this.volume = volume;
|
|
@@ -90,5 +101,20 @@ class VolumeTransformer extends stream_1.Transform {
|
|
|
90
101
|
get volumeLogarithmic() {
|
|
91
102
|
return Math.pow(this.volume, 1 / 1.660964);
|
|
92
103
|
}
|
|
104
|
+
get smoothness() {
|
|
105
|
+
return this._smoothing;
|
|
106
|
+
}
|
|
107
|
+
setSmoothness(smoothness) {
|
|
108
|
+
this._smoothing = smoothness;
|
|
109
|
+
}
|
|
110
|
+
smoothingEnabled() {
|
|
111
|
+
return Number.isFinite(this._smoothing) && this._smoothing > 0;
|
|
112
|
+
}
|
|
113
|
+
get hasSmoothness() {
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
static get hasSmoothing() {
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
93
119
|
}
|
|
94
120
|
exports.VolumeTransformer = VolumeTransformer;
|
package/dist/index.d.ts
CHANGED
|
@@ -191,6 +191,9 @@ declare class VoiceUtils {
|
|
|
191
191
|
deaf?: boolean;
|
|
192
192
|
maxTime?: number;
|
|
193
193
|
}): Promise<VoiceConnection>;
|
|
194
|
+
enterReady(conn: VoiceConnection, options?: {
|
|
195
|
+
maxTime?: number;
|
|
196
|
+
}): Promise<VoiceConnection>;
|
|
194
197
|
/**
|
|
195
198
|
* Disconnects voice connection
|
|
196
199
|
* @param {VoiceConnection} connection The voice connection
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.version = exports.Util = exports.StreamDispatcher = exports.VoiceUtils = exports.Track = exports.Queue = exports.QueryResolver = exports.ErrorStatusCode = exports.PlayerError = exports.Player = exports.Playlist = exports.ExtractorModel = exports.AudioFilters = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
// try applying smooth volume patch on load
|
|
6
|
+
require("./smoothVolume");
|
|
5
7
|
var AudioFilters_1 = require("./utils/AudioFilters");
|
|
6
8
|
Object.defineProperty(exports, "AudioFilters", { enumerable: true, get: function () { return AudioFilters_1.AudioFilters; } });
|
|
7
9
|
var ExtractorModel_1 = require("./Structures/ExtractorModel");
|
package/dist/smoothVolume.js
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const VolumeTransformer_1 = require("./VolumeTransformer");
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
const VolumeTransformer_1 = require("./VoiceInterface/VolumeTransformer");
|
|
4
|
+
try {
|
|
5
|
+
// eslint-disable-next-line
|
|
6
|
+
const mod = require("prism-media");
|
|
7
|
+
if (typeof mod.VolumeTransformer.hasSmoothing !== "boolean") {
|
|
8
|
+
Reflect.set(mod, "VolumeTransformer", VolumeTransformer_1.VolumeTransformer);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
catch (_a) {
|
|
12
|
+
/* do nothing */
|
|
13
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "discord-player",
|
|
3
|
-
"version": "5.2.
|
|
3
|
+
"version": "5.2.2",
|
|
4
4
|
"description": "Complete framework to facilitate music commands using discord.js",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -13,7 +13,9 @@
|
|
|
13
13
|
"require": "./dist/index.js",
|
|
14
14
|
"import": "./dist/index.mjs"
|
|
15
15
|
},
|
|
16
|
-
"./smoothVolume": "./dist/smoothVolume.js"
|
|
16
|
+
"./smoothVolume": "./dist/smoothVolume.js",
|
|
17
|
+
"./src/*": "./dist/*",
|
|
18
|
+
"./dist/*": "./dist/*"
|
|
17
19
|
},
|
|
18
20
|
"scripts": {
|
|
19
21
|
"dev": "cd example/test && ts-node index.ts",
|
|
@@ -67,7 +69,7 @@
|
|
|
67
69
|
"discord-ytdl-core": "^5.0.4",
|
|
68
70
|
"libsodium-wrappers": "^0.7.9",
|
|
69
71
|
"soundcloud-scraper": "^5.0.2",
|
|
70
|
-
"spotify-url-info": "^2.2.
|
|
72
|
+
"spotify-url-info": "^2.2.5",
|
|
71
73
|
"tiny-typed-emitter": "^2.1.0",
|
|
72
74
|
"youtube-sr": "^4.1.13",
|
|
73
75
|
"ytdl-core": "^4.10.0"
|
|
@@ -86,7 +88,7 @@
|
|
|
86
88
|
"@typescript-eslint/eslint-plugin": "^5.4.0",
|
|
87
89
|
"@typescript-eslint/parser": "^5.4.0",
|
|
88
90
|
"discord-api-types": "^0.24.0",
|
|
89
|
-
"discord.js": "^13.
|
|
91
|
+
"discord.js": "^13.6.0",
|
|
90
92
|
"eslint": "^8.3.0",
|
|
91
93
|
"gen-esm-wrapper": "^1.1.3",
|
|
92
94
|
"husky": "^7.0.4",
|