discord-player 5.4.0 → 5.4.1-dev.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 +1 -1
- package/dist/index.d.ts +1492 -1281
- package/dist/index.js +2072 -36
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2039 -22
- package/dist/index.mjs.map +1 -0
- package/package.json +15 -31
- package/dist/Player.js +0 -623
- package/dist/Structures/ExtractorModel.js +0 -65
- package/dist/Structures/PlayerError.js +0 -48
- package/dist/Structures/Playlist.js +0 -108
- package/dist/Structures/Queue.js +0 -917
- package/dist/Structures/Track.js +0 -155
- package/dist/VoiceInterface/StreamDispatcher.js +0 -238
- package/dist/VoiceInterface/VoiceUtils.js +0 -65
- package/dist/VoiceInterface/VolumeTransformer.js +0 -120
- package/dist/smoothVolume.js +0 -15
- package/dist/types/types.js +0 -58
- package/dist/utils/AudioFilters.js +0 -95
- package/dist/utils/FFmpegStream.js +0 -53
- package/dist/utils/QueryResolver.js +0 -68
- package/dist/utils/Util.js +0 -136
package/dist/Structures/Track.js
DELETED
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Track = void 0;
|
|
4
|
-
const discord_js_1 = require("discord.js");
|
|
5
|
-
class Track {
|
|
6
|
-
/**
|
|
7
|
-
* Track constructor
|
|
8
|
-
* @param {Player} player The player that instantiated this Track
|
|
9
|
-
* @param {RawTrackData} data Track data
|
|
10
|
-
*/
|
|
11
|
-
constructor(player, data) {
|
|
12
|
-
this.raw = {};
|
|
13
|
-
this.id = discord_js_1.SnowflakeUtil.generate().toString();
|
|
14
|
-
/**
|
|
15
|
-
* The player that instantiated this Track
|
|
16
|
-
* @name Track#player
|
|
17
|
-
* @type {Player}
|
|
18
|
-
* @readonly
|
|
19
|
-
*/
|
|
20
|
-
Object.defineProperty(this, "player", { value: player, enumerable: false });
|
|
21
|
-
/**
|
|
22
|
-
* Title of this track
|
|
23
|
-
* @name Track#title
|
|
24
|
-
* @type {string}
|
|
25
|
-
*/
|
|
26
|
-
/**
|
|
27
|
-
* Description of this track
|
|
28
|
-
* @name Track#description
|
|
29
|
-
* @type {string}
|
|
30
|
-
*/
|
|
31
|
-
/**
|
|
32
|
-
* Author of this track
|
|
33
|
-
* @name Track#author
|
|
34
|
-
* @type {string}
|
|
35
|
-
*/
|
|
36
|
-
/**
|
|
37
|
-
* URL of this track
|
|
38
|
-
* @name Track#url
|
|
39
|
-
* @type {string}
|
|
40
|
-
*/
|
|
41
|
-
/**
|
|
42
|
-
* Thumbnail of this track
|
|
43
|
-
* @name Track#thumbnail
|
|
44
|
-
* @type {string}
|
|
45
|
-
*/
|
|
46
|
-
/**
|
|
47
|
-
* Duration of this track
|
|
48
|
-
* @name Track#duration
|
|
49
|
-
* @type {string}
|
|
50
|
-
*/
|
|
51
|
-
/**
|
|
52
|
-
* Views count of this track
|
|
53
|
-
* @name Track#views
|
|
54
|
-
* @type {number}
|
|
55
|
-
*/
|
|
56
|
-
/**
|
|
57
|
-
* Person who requested this track
|
|
58
|
-
* @name Track#requestedBy
|
|
59
|
-
* @type {User}
|
|
60
|
-
*/
|
|
61
|
-
/**
|
|
62
|
-
* If this track belongs to playlist
|
|
63
|
-
* @name Track#fromPlaylist
|
|
64
|
-
* @type {boolean}
|
|
65
|
-
*/
|
|
66
|
-
/**
|
|
67
|
-
* Raw track data
|
|
68
|
-
* @name Track#raw
|
|
69
|
-
* @type {RawTrackData}
|
|
70
|
-
*/
|
|
71
|
-
/**
|
|
72
|
-
* The track id
|
|
73
|
-
* @name Track#id
|
|
74
|
-
* @type {Snowflake}
|
|
75
|
-
* @readonly
|
|
76
|
-
*/
|
|
77
|
-
/**
|
|
78
|
-
* The playlist which track belongs
|
|
79
|
-
* @name Track#playlist
|
|
80
|
-
* @type {Playlist}
|
|
81
|
-
*/
|
|
82
|
-
void this._patch(data);
|
|
83
|
-
}
|
|
84
|
-
_patch(data) {
|
|
85
|
-
this.title = (0, discord_js_1.escapeMarkdown)(data.title ?? "");
|
|
86
|
-
this.author = data.author ?? "";
|
|
87
|
-
this.url = data.url ?? "";
|
|
88
|
-
this.thumbnail = data.thumbnail ?? "";
|
|
89
|
-
this.duration = data.duration ?? "";
|
|
90
|
-
this.views = data.views ?? 0;
|
|
91
|
-
this.requestedBy = data.requestedBy;
|
|
92
|
-
this.playlist = data.playlist;
|
|
93
|
-
// raw
|
|
94
|
-
Object.defineProperty(this, "raw", { value: Object.assign({}, { source: data.raw?.source ?? data.source }, data.raw ?? data), enumerable: false });
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* The queue in which this track is located
|
|
98
|
-
* @type {Queue}
|
|
99
|
-
*/
|
|
100
|
-
get queue() {
|
|
101
|
-
return this.player.queues.find((q) => q.tracks.some((ab) => ab.id === this.id));
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* The track duration in millisecond
|
|
105
|
-
* @type {number}
|
|
106
|
-
*/
|
|
107
|
-
get durationMS() {
|
|
108
|
-
const times = (n, t) => {
|
|
109
|
-
let tn = 1;
|
|
110
|
-
for (let i = 0; i < t; i++)
|
|
111
|
-
tn *= n;
|
|
112
|
-
return t <= 0 ? 1000 : tn * 1000;
|
|
113
|
-
};
|
|
114
|
-
return this.duration
|
|
115
|
-
.split(":")
|
|
116
|
-
.reverse()
|
|
117
|
-
.map((m, i) => parseInt(m) * times(60, i))
|
|
118
|
-
.reduce((a, c) => a + c, 0);
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Returns source of this track
|
|
122
|
-
* @type {TrackSource}
|
|
123
|
-
*/
|
|
124
|
-
get source() {
|
|
125
|
-
return this.raw.source ?? "arbitrary";
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* String representation of this track
|
|
129
|
-
* @returns {string}
|
|
130
|
-
*/
|
|
131
|
-
toString() {
|
|
132
|
-
return `${this.title} by ${this.author}`;
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Raw JSON representation of this track
|
|
136
|
-
* @returns {TrackJSON}
|
|
137
|
-
*/
|
|
138
|
-
toJSON(hidePlaylist) {
|
|
139
|
-
return {
|
|
140
|
-
id: this.id,
|
|
141
|
-
title: this.title,
|
|
142
|
-
description: this.description,
|
|
143
|
-
author: this.author,
|
|
144
|
-
url: this.url,
|
|
145
|
-
thumbnail: this.thumbnail,
|
|
146
|
-
duration: this.duration,
|
|
147
|
-
durationMS: this.durationMS,
|
|
148
|
-
views: this.views,
|
|
149
|
-
requestedBy: this.requestedBy?.id,
|
|
150
|
-
playlist: hidePlaylist ? null : this.playlist?.toJSON() ?? null
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
exports.Track = Track;
|
|
155
|
-
exports.default = Track;
|
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.StreamDispatcher = void 0;
|
|
4
|
-
const voice_1 = require("@discordjs/voice");
|
|
5
|
-
const tiny_typed_emitter_1 = require("tiny-typed-emitter");
|
|
6
|
-
const Util_1 = require("../utils/Util");
|
|
7
|
-
const PlayerError_1 = require("../Structures/PlayerError");
|
|
8
|
-
const equalizer_1 = require("@discord-player/equalizer");
|
|
9
|
-
class StreamDispatcher extends tiny_typed_emitter_1.TypedEmitter {
|
|
10
|
-
/**
|
|
11
|
-
* Creates new connection object
|
|
12
|
-
* @param {VoiceConnection} connection The connection
|
|
13
|
-
* @param {VoiceChannel|StageChannel} channel The connected channel
|
|
14
|
-
* @private
|
|
15
|
-
*/
|
|
16
|
-
constructor(connection, channel, connectionTimeout = 20000) {
|
|
17
|
-
super();
|
|
18
|
-
this.connectionTimeout = connectionTimeout;
|
|
19
|
-
this.readyLock = false;
|
|
20
|
-
this.equalizer = null;
|
|
21
|
-
/**
|
|
22
|
-
* The voice connection
|
|
23
|
-
* @type {VoiceConnection}
|
|
24
|
-
*/
|
|
25
|
-
this.voiceConnection = connection;
|
|
26
|
-
/**
|
|
27
|
-
* The audio player
|
|
28
|
-
* @type {AudioPlayer}
|
|
29
|
-
*/
|
|
30
|
-
this.audioPlayer = (0, voice_1.createAudioPlayer)();
|
|
31
|
-
/**
|
|
32
|
-
* The voice channel
|
|
33
|
-
* @type {VoiceChannel|StageChannel}
|
|
34
|
-
*/
|
|
35
|
-
this.channel = channel;
|
|
36
|
-
/**
|
|
37
|
-
* The paused state
|
|
38
|
-
* @type {boolean}
|
|
39
|
-
*/
|
|
40
|
-
this.paused = false;
|
|
41
|
-
this.voiceConnection.on("stateChange", async (_, newState) => {
|
|
42
|
-
if (newState.status === voice_1.VoiceConnectionStatus.Disconnected) {
|
|
43
|
-
if (newState.reason === voice_1.VoiceConnectionDisconnectReason.WebSocketClose && newState.closeCode === 4014) {
|
|
44
|
-
try {
|
|
45
|
-
await (0, voice_1.entersState)(this.voiceConnection, voice_1.VoiceConnectionStatus.Connecting, this.connectionTimeout);
|
|
46
|
-
}
|
|
47
|
-
catch {
|
|
48
|
-
try {
|
|
49
|
-
this.voiceConnection.destroy();
|
|
50
|
-
}
|
|
51
|
-
catch (err) {
|
|
52
|
-
this.emit("error", err);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
else if (this.voiceConnection.rejoinAttempts < 5) {
|
|
57
|
-
await Util_1.Util.wait((this.voiceConnection.rejoinAttempts + 1) * 5000);
|
|
58
|
-
this.voiceConnection.rejoin();
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
try {
|
|
62
|
-
this.voiceConnection.destroy();
|
|
63
|
-
}
|
|
64
|
-
catch (err) {
|
|
65
|
-
this.emit("error", err);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
else if (newState.status === voice_1.VoiceConnectionStatus.Destroyed) {
|
|
70
|
-
this.end();
|
|
71
|
-
}
|
|
72
|
-
else if (!this.readyLock && (newState.status === voice_1.VoiceConnectionStatus.Connecting || newState.status === voice_1.VoiceConnectionStatus.Signalling)) {
|
|
73
|
-
this.readyLock = true;
|
|
74
|
-
try {
|
|
75
|
-
await (0, voice_1.entersState)(this.voiceConnection, voice_1.VoiceConnectionStatus.Ready, this.connectionTimeout);
|
|
76
|
-
}
|
|
77
|
-
catch {
|
|
78
|
-
if (this.voiceConnection.state.status !== voice_1.VoiceConnectionStatus.Destroyed) {
|
|
79
|
-
try {
|
|
80
|
-
this.voiceConnection.destroy();
|
|
81
|
-
}
|
|
82
|
-
catch (err) {
|
|
83
|
-
this.emit("error", err);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
finally {
|
|
88
|
-
this.readyLock = false;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
this.audioPlayer.on("stateChange", (oldState, newState) => {
|
|
93
|
-
if (newState.status === voice_1.AudioPlayerStatus.Playing) {
|
|
94
|
-
if (!this.paused)
|
|
95
|
-
return void this.emit("start", this.audioResource);
|
|
96
|
-
}
|
|
97
|
-
else if (newState.status === voice_1.AudioPlayerStatus.Idle && oldState.status !== voice_1.AudioPlayerStatus.Idle) {
|
|
98
|
-
if (!this.paused) {
|
|
99
|
-
void this.emit("finish", this.audioResource);
|
|
100
|
-
if (this.equalizer) {
|
|
101
|
-
this.equalizer.destroy();
|
|
102
|
-
this.equalizer = null;
|
|
103
|
-
}
|
|
104
|
-
this.audioResource = null;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
this.audioPlayer.on("debug", (m) => void this.emit("debug", m));
|
|
109
|
-
this.audioPlayer.on("error", (error) => void this.emit("error", error));
|
|
110
|
-
this.voiceConnection.subscribe(this.audioPlayer);
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Creates stream
|
|
114
|
-
* @param {Readable|Duplex|string} src The stream source
|
|
115
|
-
* @param {object} [ops] Options
|
|
116
|
-
* @returns {AudioResource}
|
|
117
|
-
*/
|
|
118
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
119
|
-
createStream(src, ops) {
|
|
120
|
-
if (!ops.disableEqualizer)
|
|
121
|
-
this.equalizer = new equalizer_1.EqualizerStream({
|
|
122
|
-
channels: 1,
|
|
123
|
-
disabled: false,
|
|
124
|
-
bandMultiplier: ops.eq || []
|
|
125
|
-
});
|
|
126
|
-
const stream = this.equalizer && typeof src !== "string" ? src.pipe(this.equalizer) : src;
|
|
127
|
-
this.audioResource = (0, voice_1.createAudioResource)(stream, {
|
|
128
|
-
inputType: ops?.type ?? voice_1.StreamType.Arbitrary,
|
|
129
|
-
metadata: ops?.data,
|
|
130
|
-
inlineVolume: !ops?.disableVolume
|
|
131
|
-
});
|
|
132
|
-
return this.audioResource;
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* The player status
|
|
136
|
-
* @type {AudioPlayerStatus}
|
|
137
|
-
*/
|
|
138
|
-
get status() {
|
|
139
|
-
return this.audioPlayer.state.status;
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Disconnects from voice
|
|
143
|
-
* @returns {void}
|
|
144
|
-
*/
|
|
145
|
-
disconnect() {
|
|
146
|
-
try {
|
|
147
|
-
this.audioPlayer.stop(true);
|
|
148
|
-
this.voiceConnection.destroy();
|
|
149
|
-
}
|
|
150
|
-
catch { } // eslint-disable-line no-empty
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Stops the player
|
|
154
|
-
* @returns {void}
|
|
155
|
-
*/
|
|
156
|
-
end() {
|
|
157
|
-
this.audioPlayer.stop();
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Pauses the stream playback
|
|
161
|
-
* @param {boolean} [interpolateSilence=false] If true, the player will play 5 packets of silence after pausing to prevent audio glitches.
|
|
162
|
-
* @returns {boolean}
|
|
163
|
-
*/
|
|
164
|
-
pause(interpolateSilence) {
|
|
165
|
-
const success = this.audioPlayer.pause(interpolateSilence);
|
|
166
|
-
this.paused = success;
|
|
167
|
-
return success;
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Resumes the stream playback
|
|
171
|
-
* @returns {boolean}
|
|
172
|
-
*/
|
|
173
|
-
resume() {
|
|
174
|
-
const success = this.audioPlayer.unpause();
|
|
175
|
-
this.paused = !success;
|
|
176
|
-
return success;
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Play stream
|
|
180
|
-
* @param {AudioResource<Track>} [resource=this.audioResource] The audio resource to play
|
|
181
|
-
* @returns {Promise<StreamDispatcher>}
|
|
182
|
-
*/
|
|
183
|
-
async playStream(resource = this.audioResource) {
|
|
184
|
-
if (!resource)
|
|
185
|
-
throw new PlayerError_1.PlayerError("Audio resource is not available!", PlayerError_1.ErrorStatusCode.NO_AUDIO_RESOURCE);
|
|
186
|
-
if (resource.ended) {
|
|
187
|
-
return void this.emit("finish", resource);
|
|
188
|
-
}
|
|
189
|
-
if (!this.audioResource)
|
|
190
|
-
this.audioResource = resource;
|
|
191
|
-
if (this.voiceConnection.state.status !== voice_1.VoiceConnectionStatus.Ready) {
|
|
192
|
-
try {
|
|
193
|
-
await (0, voice_1.entersState)(this.voiceConnection, voice_1.VoiceConnectionStatus.Ready, this.connectionTimeout);
|
|
194
|
-
}
|
|
195
|
-
catch (err) {
|
|
196
|
-
return void this.emit("error", err);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
try {
|
|
200
|
-
this.audioPlayer.play(resource);
|
|
201
|
-
}
|
|
202
|
-
catch (e) {
|
|
203
|
-
this.emit("error", e);
|
|
204
|
-
}
|
|
205
|
-
return this;
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* Sets playback volume
|
|
209
|
-
* @param {number} value The volume amount
|
|
210
|
-
* @returns {boolean}
|
|
211
|
-
*/
|
|
212
|
-
setVolume(value) {
|
|
213
|
-
if (!this.audioResource?.volume || isNaN(value) || value < 0 || value > Infinity)
|
|
214
|
-
return false;
|
|
215
|
-
this.audioResource.volume.setVolumeLogarithmic(value / 100);
|
|
216
|
-
return true;
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* The current volume
|
|
220
|
-
* @type {number}
|
|
221
|
-
*/
|
|
222
|
-
get volume() {
|
|
223
|
-
if (!this.audioResource?.volume)
|
|
224
|
-
return 100;
|
|
225
|
-
const currentVol = this.audioResource.volume.volume;
|
|
226
|
-
return Math.round(Math.pow(currentVol, 1 / 1.660964) * 100);
|
|
227
|
-
}
|
|
228
|
-
/**
|
|
229
|
-
* The playback time
|
|
230
|
-
* @type {number}
|
|
231
|
-
*/
|
|
232
|
-
get streamTime() {
|
|
233
|
-
if (!this.audioResource)
|
|
234
|
-
return 0;
|
|
235
|
-
return this.audioResource.playbackDuration;
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
exports.StreamDispatcher = StreamDispatcher;
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.VoiceUtils = void 0;
|
|
4
|
-
const discord_js_1 = require("discord.js");
|
|
5
|
-
const voice_1 = require("@discordjs/voice");
|
|
6
|
-
const StreamDispatcher_1 = require("./StreamDispatcher");
|
|
7
|
-
class VoiceUtils {
|
|
8
|
-
/**
|
|
9
|
-
* The voice utils
|
|
10
|
-
* @private
|
|
11
|
-
*/
|
|
12
|
-
constructor() {
|
|
13
|
-
/**
|
|
14
|
-
* The cache where voice utils stores stream managers
|
|
15
|
-
* @type {Collection<Snowflake, StreamDispatcher>}
|
|
16
|
-
*/
|
|
17
|
-
this.cache = new discord_js_1.Collection();
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Joins a voice channel, creating basic stream dispatch manager
|
|
21
|
-
* @param {StageChannel|VoiceChannel} channel The voice channel
|
|
22
|
-
* @param {object} [options] Join options
|
|
23
|
-
* @returns {Promise<StreamDispatcher>}
|
|
24
|
-
*/
|
|
25
|
-
async connect(channel, options) {
|
|
26
|
-
const conn = await this.join(channel, options);
|
|
27
|
-
const sub = new StreamDispatcher_1.StreamDispatcher(conn, channel, options.maxTime);
|
|
28
|
-
this.cache.set(channel.guild.id, sub);
|
|
29
|
-
return sub;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Joins a voice channel
|
|
33
|
-
* @param {StageChannel|VoiceChannel} [channel] The voice/stage channel to join
|
|
34
|
-
* @param {object} [options] Join options
|
|
35
|
-
* @returns {VoiceConnection}
|
|
36
|
-
*/
|
|
37
|
-
async join(channel, options) {
|
|
38
|
-
const conn = (0, voice_1.joinVoiceChannel)({
|
|
39
|
-
guildId: channel.guild.id,
|
|
40
|
-
channelId: channel.id,
|
|
41
|
-
adapterCreator: channel.guild.voiceAdapterCreator,
|
|
42
|
-
selfDeaf: Boolean(options.deaf)
|
|
43
|
-
});
|
|
44
|
-
return conn;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Disconnects voice connection
|
|
48
|
-
* @param {VoiceConnection} connection The voice connection
|
|
49
|
-
* @returns {void}
|
|
50
|
-
*/
|
|
51
|
-
disconnect(connection) {
|
|
52
|
-
if (connection instanceof StreamDispatcher_1.StreamDispatcher)
|
|
53
|
-
return connection.voiceConnection.destroy();
|
|
54
|
-
return connection.destroy();
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Returns Discord Player voice connection
|
|
58
|
-
* @param {Snowflake} guild The guild id
|
|
59
|
-
* @returns {StreamDispatcher}
|
|
60
|
-
*/
|
|
61
|
-
getConnection(guild) {
|
|
62
|
-
return this.cache.get(guild);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
exports.VoiceUtils = VoiceUtils;
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// prism's volume transformer with smooth volume support
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.VolumeTransformer = void 0;
|
|
5
|
-
const stream_1 = require("stream");
|
|
6
|
-
class VolumeTransformer extends stream_1.Transform {
|
|
7
|
-
constructor(options = {}) {
|
|
8
|
-
super(options);
|
|
9
|
-
switch (options.type) {
|
|
10
|
-
case "s16le":
|
|
11
|
-
this._readInt = (buffer, index) => buffer.readInt16LE(index);
|
|
12
|
-
this._writeInt = (buffer, int, index) => buffer.writeInt16LE(int, index);
|
|
13
|
-
this._bits = 16;
|
|
14
|
-
break;
|
|
15
|
-
case "s16be":
|
|
16
|
-
this._readInt = (buffer, index) => buffer.readInt16BE(index);
|
|
17
|
-
this._writeInt = (buffer, int, index) => buffer.writeInt16BE(int, index);
|
|
18
|
-
this._bits = 16;
|
|
19
|
-
break;
|
|
20
|
-
case "s32le":
|
|
21
|
-
this._readInt = (buffer, index) => buffer.readInt32LE(index);
|
|
22
|
-
this._writeInt = (buffer, int, index) => buffer.writeInt32LE(int, index);
|
|
23
|
-
this._bits = 32;
|
|
24
|
-
break;
|
|
25
|
-
case "s32be":
|
|
26
|
-
this._readInt = (buffer, index) => buffer.readInt32BE(index);
|
|
27
|
-
this._writeInt = (buffer, int, index) => buffer.writeInt32BE(int, index);
|
|
28
|
-
this._bits = 32;
|
|
29
|
-
break;
|
|
30
|
-
default:
|
|
31
|
-
throw new Error("VolumeTransformer type should be one of s16le, s16be, s32le, s32be");
|
|
32
|
-
}
|
|
33
|
-
this.type = options.type;
|
|
34
|
-
this._bytes = this._bits / 8;
|
|
35
|
-
this._extremum = Math.pow(2, this._bits - 1);
|
|
36
|
-
this.volume = Number.isNaN(options.volume) ? 1 : Number(options.volume);
|
|
37
|
-
if (!Number.isFinite(this.volume))
|
|
38
|
-
this.volume = 1;
|
|
39
|
-
this._targetVolume = this.volume;
|
|
40
|
-
this._chunk = Buffer.alloc(0);
|
|
41
|
-
this._smoothing = options.smoothness || 0;
|
|
42
|
-
}
|
|
43
|
-
_readInt(buffer, index) {
|
|
44
|
-
return index;
|
|
45
|
-
}
|
|
46
|
-
_writeInt(buffer, int, index) {
|
|
47
|
-
return index;
|
|
48
|
-
}
|
|
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;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
_transform(chunk, encoding, done) {
|
|
58
|
-
if (this.smoothingEnabled() && this.volume !== this._targetVolume)
|
|
59
|
-
this._applySmoothness();
|
|
60
|
-
if (this.volume === 1) {
|
|
61
|
-
this.push(chunk);
|
|
62
|
-
return done();
|
|
63
|
-
}
|
|
64
|
-
const { _bytes, _extremum } = this;
|
|
65
|
-
chunk = this._chunk = Buffer.concat([this._chunk, chunk]);
|
|
66
|
-
if (chunk.length < _bytes)
|
|
67
|
-
return done();
|
|
68
|
-
const complete = Math.floor(chunk.length / _bytes) * _bytes;
|
|
69
|
-
for (let i = 0; i < complete; i += _bytes) {
|
|
70
|
-
const int = Math.min(_extremum - 1, Math.max(-_extremum, Math.floor(this.volume * this._readInt(chunk, i))));
|
|
71
|
-
this._writeInt(chunk, int, i);
|
|
72
|
-
}
|
|
73
|
-
this._chunk = chunk.slice(complete);
|
|
74
|
-
this.push(chunk.slice(0, complete));
|
|
75
|
-
return done();
|
|
76
|
-
}
|
|
77
|
-
_destroy(err, cb) {
|
|
78
|
-
super._destroy(err, cb);
|
|
79
|
-
this._chunk = null;
|
|
80
|
-
}
|
|
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;
|
|
88
|
-
this._targetVolume = volume;
|
|
89
|
-
if (this._smoothing <= 0)
|
|
90
|
-
this.volume = volume;
|
|
91
|
-
}
|
|
92
|
-
setVolumeDecibels(db) {
|
|
93
|
-
this.setVolume(Math.pow(10, db / 20));
|
|
94
|
-
}
|
|
95
|
-
setVolumeLogarithmic(value) {
|
|
96
|
-
this.setVolume(Math.pow(value, 1.660964));
|
|
97
|
-
}
|
|
98
|
-
get volumeDecibels() {
|
|
99
|
-
return Math.log10(this.volume) * 20;
|
|
100
|
-
}
|
|
101
|
-
get volumeLogarithmic() {
|
|
102
|
-
return Math.pow(this.volume, 1 / 1.660964);
|
|
103
|
-
}
|
|
104
|
-
get smoothness() {
|
|
105
|
-
return this._smoothing;
|
|
106
|
-
}
|
|
107
|
-
setSmoothness(smoothness) {
|
|
108
|
-
this._smoothing = smoothness;
|
|
109
|
-
}
|
|
110
|
-
smoothingEnabled() {
|
|
111
|
-
return typeof this._smoothing === "number" && !Number.isNaN(this._smoothing) && Number.isFinite(this._smoothing) && this._smoothing > 0;
|
|
112
|
-
}
|
|
113
|
-
get hasSmoothness() {
|
|
114
|
-
return true;
|
|
115
|
-
}
|
|
116
|
-
static get hasSmoothing() {
|
|
117
|
-
return true;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
exports.VolumeTransformer = VolumeTransformer;
|
package/dist/smoothVolume.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const VolumeTransformer_1 = require("./VoiceInterface/VolumeTransformer");
|
|
4
|
-
if (!("DISABLE_DISCORD_PLAYER_SMOOTH_VOLUME" in process.env)) {
|
|
5
|
-
try {
|
|
6
|
-
// eslint-disable-next-line
|
|
7
|
-
const mod = require("prism-media");
|
|
8
|
-
if (typeof mod.VolumeTransformer.hasSmoothing !== "boolean") {
|
|
9
|
-
Reflect.set(mod, "VolumeTransformer", VolumeTransformer_1.VolumeTransformer);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
catch {
|
|
13
|
-
/* do nothing */
|
|
14
|
-
}
|
|
15
|
-
}
|
package/dist/types/types.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.QueueRepeatMode = exports.QueryType = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* The search query type
|
|
6
|
-
* This can be one of:
|
|
7
|
-
* - AUTO
|
|
8
|
-
* - YOUTUBE
|
|
9
|
-
* - YOUTUBE_PLAYLIST
|
|
10
|
-
* - SOUNDCLOUD_TRACK
|
|
11
|
-
* - SOUNDCLOUD_PLAYLIST
|
|
12
|
-
* - SOUNDCLOUD
|
|
13
|
-
* - SPOTIFY_SONG
|
|
14
|
-
* - SPOTIFY_ALBUM
|
|
15
|
-
* - SPOTIFY_PLAYLIST
|
|
16
|
-
* - FACEBOOK
|
|
17
|
-
* - VIMEO
|
|
18
|
-
* - ARBITRARY
|
|
19
|
-
* - REVERBNATION
|
|
20
|
-
* - YOUTUBE_SEARCH
|
|
21
|
-
* - YOUTUBE_VIDEO
|
|
22
|
-
* - SOUNDCLOUD_SEARCH
|
|
23
|
-
* @typedef {number} QueryType
|
|
24
|
-
*/
|
|
25
|
-
var QueryType;
|
|
26
|
-
(function (QueryType) {
|
|
27
|
-
QueryType[QueryType["AUTO"] = 0] = "AUTO";
|
|
28
|
-
QueryType[QueryType["YOUTUBE"] = 1] = "YOUTUBE";
|
|
29
|
-
QueryType[QueryType["YOUTUBE_PLAYLIST"] = 2] = "YOUTUBE_PLAYLIST";
|
|
30
|
-
QueryType[QueryType["SOUNDCLOUD_TRACK"] = 3] = "SOUNDCLOUD_TRACK";
|
|
31
|
-
QueryType[QueryType["SOUNDCLOUD_PLAYLIST"] = 4] = "SOUNDCLOUD_PLAYLIST";
|
|
32
|
-
QueryType[QueryType["SOUNDCLOUD"] = 5] = "SOUNDCLOUD";
|
|
33
|
-
QueryType[QueryType["SPOTIFY_SONG"] = 6] = "SPOTIFY_SONG";
|
|
34
|
-
QueryType[QueryType["SPOTIFY_ALBUM"] = 7] = "SPOTIFY_ALBUM";
|
|
35
|
-
QueryType[QueryType["SPOTIFY_PLAYLIST"] = 8] = "SPOTIFY_PLAYLIST";
|
|
36
|
-
QueryType[QueryType["FACEBOOK"] = 9] = "FACEBOOK";
|
|
37
|
-
QueryType[QueryType["VIMEO"] = 10] = "VIMEO";
|
|
38
|
-
QueryType[QueryType["ARBITRARY"] = 11] = "ARBITRARY";
|
|
39
|
-
QueryType[QueryType["REVERBNATION"] = 12] = "REVERBNATION";
|
|
40
|
-
QueryType[QueryType["YOUTUBE_SEARCH"] = 13] = "YOUTUBE_SEARCH";
|
|
41
|
-
QueryType[QueryType["YOUTUBE_VIDEO"] = 14] = "YOUTUBE_VIDEO";
|
|
42
|
-
QueryType[QueryType["SOUNDCLOUD_SEARCH"] = 15] = "SOUNDCLOUD_SEARCH";
|
|
43
|
-
})(QueryType = exports.QueryType || (exports.QueryType = {}));
|
|
44
|
-
/**
|
|
45
|
-
* The queue repeat mode. This can be one of:
|
|
46
|
-
* - OFF
|
|
47
|
-
* - TRACK
|
|
48
|
-
* - QUEUE
|
|
49
|
-
* - AUTOPLAY
|
|
50
|
-
* @typedef {number} QueueRepeatMode
|
|
51
|
-
*/
|
|
52
|
-
var QueueRepeatMode;
|
|
53
|
-
(function (QueueRepeatMode) {
|
|
54
|
-
QueueRepeatMode[QueueRepeatMode["OFF"] = 0] = "OFF";
|
|
55
|
-
QueueRepeatMode[QueueRepeatMode["TRACK"] = 1] = "TRACK";
|
|
56
|
-
QueueRepeatMode[QueueRepeatMode["QUEUE"] = 2] = "QUEUE";
|
|
57
|
-
QueueRepeatMode[QueueRepeatMode["AUTOPLAY"] = 3] = "AUTOPLAY";
|
|
58
|
-
})(QueueRepeatMode = exports.QueueRepeatMode || (exports.QueueRepeatMode = {}));
|