@zygout/eris 0.19.0 → 0.19.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/LICENSE +20 -20
- package/README.md +71 -80
- package/esm.mjs +72 -72
- package/index.d.ts +4407 -4397
- package/index.js +75 -75
- package/lib/Client.js +4708 -4683
- package/lib/Constants.d.ts +990 -988
- package/lib/Constants.js +1163 -1161
- package/lib/command/Command.js +552 -552
- package/lib/command/CommandClient.js +460 -460
- package/lib/errors/DiscordHTTPError.js +63 -63
- package/lib/errors/DiscordRESTError.js +77 -77
- package/lib/gateway/Shard.js +3029 -3029
- package/lib/gateway/ShardManager.js +164 -164
- package/lib/rest/Endpoints.js +172 -172
- package/lib/rest/RequestHandler.js +459 -459
- package/lib/structures/ApplicationCommand.js +125 -125
- package/lib/structures/AutoModerationRule.js +143 -143
- package/lib/structures/AutocompleteInteraction.js +80 -80
- package/lib/structures/Base.js +81 -81
- package/lib/structures/CategoryChannel.js +77 -77
- package/lib/structures/Channel.js +98 -98
- package/lib/structures/CommandInteraction.js +473 -473
- package/lib/structures/ComponentInteraction.js +538 -538
- package/lib/structures/DMChannel.js +278 -278
- package/lib/structures/Entitlement.js +77 -77
- package/lib/structures/ExtendedUser.js +46 -46
- package/lib/structures/ForumChannel.js +24 -24
- package/lib/structures/GroupChannel.js +106 -106
- package/lib/structures/Guild.js +1677 -1677
- package/lib/structures/GuildAuditLogEntry.js +190 -190
- package/lib/structures/GuildChannel.js +128 -128
- package/lib/structures/GuildIntegration.js +99 -99
- package/lib/structures/GuildPreview.js +97 -97
- package/lib/structures/GuildScheduledEvent.js +176 -176
- package/lib/structures/GuildTemplate.js +76 -76
- package/lib/structures/GuildTextableChannel.js +260 -260
- package/lib/structures/Interaction.js +133 -133
- package/lib/structures/Invite.js +143 -143
- package/lib/structures/Lobby.js +108 -108
- package/lib/structures/LobbyMember.js +59 -59
- package/lib/structures/MediaChannel.js +216 -216
- package/lib/structures/Member.js +371 -371
- package/lib/structures/Message.js +708 -708
- package/lib/structures/ModalSubmitInteraction.js +478 -478
- package/lib/structures/NewsChannel.js +34 -34
- package/lib/structures/NewsThreadChannel.js +12 -12
- package/lib/structures/Permission.js +80 -80
- package/lib/structures/PermissionOverwrite.js +32 -32
- package/lib/structures/PingInteraction.js +39 -39
- package/lib/structures/PrivateThreadChannel.js +25 -25
- package/lib/structures/PublicThreadChannel.js +26 -26
- package/lib/structures/Role.js +163 -163
- package/lib/structures/SKU.js +80 -80
- package/lib/structures/SoundboardSound.js +79 -79
- package/lib/structures/StageChannel.js +59 -59
- package/lib/structures/StageInstance.js +55 -55
- package/lib/structures/Subscription.js +69 -69
- package/lib/structures/TextChannel.js +202 -202
- package/lib/structures/ThreadChannel.js +143 -143
- package/lib/structures/ThreadMember.js +59 -59
- package/lib/structures/UnavailableGuild.js +26 -26
- package/lib/structures/UnknownInteraction.js +502 -502
- package/lib/structures/User.js +296 -296
- package/lib/structures/VoiceChannel.js +166 -166
- package/lib/structures/VoiceState.js +84 -84
- package/lib/util/BrowserWebSocket.js +76 -76
- package/lib/util/Bucket.js +89 -89
- package/lib/util/Collection.js +202 -202
- package/lib/util/MultipartData.js +70 -70
- package/lib/util/Opus.js +33 -33
- package/lib/util/SequentialBucket.js +83 -83
- package/lib/util/emitDeprecation.js +26 -26
- package/lib/voice/Piper.js +300 -300
- package/lib/voice/SharedStream.js +238 -238
- package/lib/voice/VoiceConnection.js +1440 -1440
- package/lib/voice/VoiceConnectionManager.js +151 -151
- package/lib/voice/VoiceDataStream.js +22 -22
- package/lib/voice/streams/BaseTransformer.js +40 -40
- package/lib/voice/streams/DCAOpusTransformer.js +78 -78
- package/lib/voice/streams/FFmpegDuplex.js +192 -192
- package/lib/voice/streams/FFmpegOggTransformer.js +35 -35
- package/lib/voice/streams/FFmpegPCMTransformer.js +26 -26
- package/lib/voice/streams/OggOpusTransformer.js +108 -108
- package/lib/voice/streams/PCMOpusTransformer.js +61 -61
- package/lib/voice/streams/VolumeTransformer.js +50 -50
- package/lib/voice/streams/WebmOpusTransformer.js +258 -258
- package/package.json +83 -82
|
@@ -1,238 +1,238 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const util = require("util");
|
|
4
|
-
const Base = require("../structures/Base");
|
|
5
|
-
const Piper = require("./Piper");
|
|
6
|
-
const VoiceConnection = require("./VoiceConnection");
|
|
7
|
-
const Collection = require("../util/Collection");
|
|
8
|
-
const { createOpus } = require("../util/Opus");
|
|
9
|
-
|
|
10
|
-
let EventEmitter;
|
|
11
|
-
try {
|
|
12
|
-
EventEmitter = require("eventemitter3");
|
|
13
|
-
} catch {
|
|
14
|
-
EventEmitter = require("events").EventEmitter;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Represents a collection of VoiceConnections sharing an input stream
|
|
19
|
-
* @extends EventEmitter
|
|
20
|
-
* @prop {Object?} current The current stream
|
|
21
|
-
* @prop {Boolean} ended Whether the stream ended
|
|
22
|
-
* @prop {Boolean} playing Whether the voice connection is playing something
|
|
23
|
-
* @prop {Boolean} speaking Whether someone is speaking
|
|
24
|
-
* @prop {Number} volume The current volume level of the connection
|
|
25
|
-
*/
|
|
26
|
-
class SharedStream extends EventEmitter {
|
|
27
|
-
constructor() {
|
|
28
|
-
super();
|
|
29
|
-
|
|
30
|
-
this.samplingRate = 48000;
|
|
31
|
-
this.frameDuration = 20;
|
|
32
|
-
this.channels = 2;
|
|
33
|
-
this.bitrate = 64000;
|
|
34
|
-
|
|
35
|
-
this.voiceConnections = new Collection(VoiceConnection);
|
|
36
|
-
|
|
37
|
-
if (!VoiceConnection._converterCommand.cmd) {
|
|
38
|
-
VoiceConnection._converterCommand.pickCommand();
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
this.piper = new Piper(VoiceConnection._converterCommand.cmd, () => createOpus(this.samplingRate, this.channels, this.bitrate));
|
|
42
|
-
/**
|
|
43
|
-
* Fired when the shared stream encounters an error
|
|
44
|
-
* @event SharedStream#error
|
|
45
|
-
* @prop {Error} e The error
|
|
46
|
-
*/
|
|
47
|
-
this.piper.on("error", (e) => this.emit("error", e));
|
|
48
|
-
if (!VoiceConnection._converterCommand.libopus) {
|
|
49
|
-
this.piper.libopus = false;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
this.ended = true;
|
|
53
|
-
this.playing = false;
|
|
54
|
-
this.speaking = false;
|
|
55
|
-
|
|
56
|
-
this._send = this._send.bind(this);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
get volume() {
|
|
60
|
-
return this.piper.volumeLevel;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Add a voice connection to the shared stream
|
|
65
|
-
* @arg {VoiceConnection} connection The voice connection to add
|
|
66
|
-
*/
|
|
67
|
-
add(connection) {
|
|
68
|
-
const _connection = this.voiceConnections.add(connection);
|
|
69
|
-
if (_connection.ready) {
|
|
70
|
-
_connection.setSpeaking(this.speaking);
|
|
71
|
-
} else {
|
|
72
|
-
_connection.once("ready", () => {
|
|
73
|
-
_connection.setSpeaking(this.speaking);
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
return _connection;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Play an audio or video resource. If playing from a non-opus resource, FFMPEG should be compiled with --enable-libopus for best performance. If playing from HTTPS, FFMPEG must be compiled with --enable-openssl
|
|
81
|
-
* @arg {ReadableStream | String} resource The audio or video resource, either a ReadableStream, URL, or file path
|
|
82
|
-
* @arg {Object} [options] Music options
|
|
83
|
-
* @arg {Array<String>} [options.encoderArgs] Additional encoder parameters to pass to ffmpeg/avconv (after -i)
|
|
84
|
-
* @arg {String} [options.format] The format of the resource. If null, FFmpeg will attempt to guess and play the format. Available options: "dca", "ogg", "webm", "pcm", "opusPackets", null
|
|
85
|
-
* @arg {Number} [options.frameDuration=60] The resource opus frame duration (required for DCA/Ogg)
|
|
86
|
-
* @arg {Number} [options.frameSize=2880] The resource opus frame size
|
|
87
|
-
* @arg {Boolean} [options.inlineVolume=false] Whether to enable on-the-fly volume changing. Note that enabling this leads to increased CPU usage
|
|
88
|
-
* @arg {Array<String>} [options.inputArgs] Additional input parameters to pass to ffmpeg/avconv (before -i)
|
|
89
|
-
* @arg {Number} [options.sampleRate=48000] The resource audio sampling rate
|
|
90
|
-
* @arg {Number} [options.voiceDataTimeout=2000] Timeout when waiting for voice data (-1 for no timeout)
|
|
91
|
-
*/
|
|
92
|
-
play(source, options = {}) {
|
|
93
|
-
options.format = options.format || null;
|
|
94
|
-
options.voiceDataTimeout = !isNaN(options.voiceDataTimeout) ? options.voiceDataTimeout : 2000;
|
|
95
|
-
options.inlineVolume = !!options.inlineVolume;
|
|
96
|
-
options.inputArgs = options.inputArgs || [];
|
|
97
|
-
options.encoderArgs = options.encoderArgs || [];
|
|
98
|
-
|
|
99
|
-
options.samplingRate = options.samplingRate || this.samplingRate;
|
|
100
|
-
options.frameDuration = options.frameDuration || this.frameDuration;
|
|
101
|
-
options.frameSize = options.frameSize || options.samplingRate * options.frameDuration / 1000;
|
|
102
|
-
options.pcmSize = options.pcmSize || options.frameSize * 2 * this.channels;
|
|
103
|
-
|
|
104
|
-
if (!this.piper.encode(source, options)) {
|
|
105
|
-
this.emit("error", new Error("Unable to encode source"));
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
this.ended = false;
|
|
110
|
-
this.current = {
|
|
111
|
-
startTime: 0, // later
|
|
112
|
-
playTime: 0,
|
|
113
|
-
pausedTimestamp: 0,
|
|
114
|
-
pausedTime: 0,
|
|
115
|
-
bufferingTicks: 0,
|
|
116
|
-
options: options,
|
|
117
|
-
timeout: null,
|
|
118
|
-
buffer: null,
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
this.playing = true;
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Fired when the shared stream starts playing a stream
|
|
125
|
-
* @event SharedStream#start
|
|
126
|
-
*/
|
|
127
|
-
this.emit("start");
|
|
128
|
-
|
|
129
|
-
this._send();
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Remove a voice connection from the shared stream
|
|
134
|
-
* @arg {VoiceConnection} connection The voice connection to remove
|
|
135
|
-
*/
|
|
136
|
-
remove(connection) {
|
|
137
|
-
return this.voiceConnections.remove(connection);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
setSpeaking(value) {
|
|
141
|
-
if ((value = !!value) != this.speaking) {
|
|
142
|
-
this.speaking = value;
|
|
143
|
-
for (const vc of this.voiceConnections.values()) {
|
|
144
|
-
vc.setSpeaking(value);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Sets the volume of this shared stream if inline volume is enabled
|
|
151
|
-
* @arg {Number} volume The volume as a value from 0 (min) to 1 (max)
|
|
152
|
-
*/
|
|
153
|
-
setVolume(volume) {
|
|
154
|
-
this.piper.setVolume(volume);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Stop the bot from sending audio
|
|
159
|
-
*/
|
|
160
|
-
stopPlaying() {
|
|
161
|
-
if (this.ended) {
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
this.ended = true;
|
|
165
|
-
if (this.current && this.current.timeout) {
|
|
166
|
-
clearTimeout(this.current.timeout);
|
|
167
|
-
this.current.timeout = null;
|
|
168
|
-
}
|
|
169
|
-
this.current = null;
|
|
170
|
-
this.piper.stop();
|
|
171
|
-
this.piper.resetPackets();
|
|
172
|
-
|
|
173
|
-
this.setSpeaking(this.playing = false);
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Fired when the shared stream finishes playing a stream
|
|
177
|
-
* @event SharedStream#end
|
|
178
|
-
*/
|
|
179
|
-
this.emit("end");
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
_incrementSequences() {
|
|
183
|
-
for (const vc of this.voiceConnections.values()) {
|
|
184
|
-
vc.sequence = (vc.sequence + 1) & 0xFFFF;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
_incrementTimestamps(val) {
|
|
189
|
-
for (const vc of this.voiceConnections.values()) {
|
|
190
|
-
vc.timestamp = (vc.timestamp + val) >>> 0;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
_send() {
|
|
195
|
-
if (!this.piper.encoding && this.piper.dataPacketCount === 0) {
|
|
196
|
-
return this.stopPlaying();
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
this._incrementTimestamps(this.current.options.frameSize);
|
|
200
|
-
|
|
201
|
-
this._incrementSequences();
|
|
202
|
-
|
|
203
|
-
if ((this.current.buffer = this.piper.getDataPacket())) {
|
|
204
|
-
if (this.current.startTime === 0) {
|
|
205
|
-
this.current.startTime = Date.now();
|
|
206
|
-
}
|
|
207
|
-
if (this.current.bufferingTicks > 0) {
|
|
208
|
-
this.current.bufferingTicks = 0;
|
|
209
|
-
this.setSpeaking(true);
|
|
210
|
-
}
|
|
211
|
-
} else if (this.current.options.voiceDataTimeout === -1 || this.current.bufferingTicks < this.current.options.voiceDataTimeout / (4 * this.current.options.frameDuration)) { // wait for data
|
|
212
|
-
if (++this.current.bufferingTicks === 1) {
|
|
213
|
-
this.setSpeaking(false);
|
|
214
|
-
} else {
|
|
215
|
-
this.current.pausedTime += 4 * this.current.options.frameDuration;
|
|
216
|
-
this._incrementTimestamps(3 * this.current.options.frameSize);
|
|
217
|
-
this.current.timeout = setTimeout(this._send, 4 * this.current.options.frameDuration);
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
} else {
|
|
221
|
-
return this.stopPlaying();
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
this.voiceConnections.forEach((connection) => {
|
|
225
|
-
if (connection.ready && this.current.buffer) {
|
|
226
|
-
connection._sendAudioFrame(this.current.buffer);
|
|
227
|
-
}
|
|
228
|
-
});
|
|
229
|
-
this.current.playTime += this.current.options.frameDuration;
|
|
230
|
-
this.current.timeout = setTimeout(this._send, Math.max(0, this.current.startTime + this.current.pausedTime + this.current.playTime - Date.now()));
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
[util.inspect.custom]() {
|
|
234
|
-
return Base.prototype[util.inspect.custom].call(this);
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
module.exports = SharedStream;
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const util = require("util");
|
|
4
|
+
const Base = require("../structures/Base");
|
|
5
|
+
const Piper = require("./Piper");
|
|
6
|
+
const VoiceConnection = require("./VoiceConnection");
|
|
7
|
+
const Collection = require("../util/Collection");
|
|
8
|
+
const { createOpus } = require("../util/Opus");
|
|
9
|
+
|
|
10
|
+
let EventEmitter;
|
|
11
|
+
try {
|
|
12
|
+
EventEmitter = require("eventemitter3");
|
|
13
|
+
} catch {
|
|
14
|
+
EventEmitter = require("events").EventEmitter;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Represents a collection of VoiceConnections sharing an input stream
|
|
19
|
+
* @extends EventEmitter
|
|
20
|
+
* @prop {Object?} current The current stream
|
|
21
|
+
* @prop {Boolean} ended Whether the stream ended
|
|
22
|
+
* @prop {Boolean} playing Whether the voice connection is playing something
|
|
23
|
+
* @prop {Boolean} speaking Whether someone is speaking
|
|
24
|
+
* @prop {Number} volume The current volume level of the connection
|
|
25
|
+
*/
|
|
26
|
+
class SharedStream extends EventEmitter {
|
|
27
|
+
constructor() {
|
|
28
|
+
super();
|
|
29
|
+
|
|
30
|
+
this.samplingRate = 48000;
|
|
31
|
+
this.frameDuration = 20;
|
|
32
|
+
this.channels = 2;
|
|
33
|
+
this.bitrate = 64000;
|
|
34
|
+
|
|
35
|
+
this.voiceConnections = new Collection(VoiceConnection);
|
|
36
|
+
|
|
37
|
+
if (!VoiceConnection._converterCommand.cmd) {
|
|
38
|
+
VoiceConnection._converterCommand.pickCommand();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
this.piper = new Piper(VoiceConnection._converterCommand.cmd, () => createOpus(this.samplingRate, this.channels, this.bitrate));
|
|
42
|
+
/**
|
|
43
|
+
* Fired when the shared stream encounters an error
|
|
44
|
+
* @event SharedStream#error
|
|
45
|
+
* @prop {Error} e The error
|
|
46
|
+
*/
|
|
47
|
+
this.piper.on("error", (e) => this.emit("error", e));
|
|
48
|
+
if (!VoiceConnection._converterCommand.libopus) {
|
|
49
|
+
this.piper.libopus = false;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
this.ended = true;
|
|
53
|
+
this.playing = false;
|
|
54
|
+
this.speaking = false;
|
|
55
|
+
|
|
56
|
+
this._send = this._send.bind(this);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
get volume() {
|
|
60
|
+
return this.piper.volumeLevel;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Add a voice connection to the shared stream
|
|
65
|
+
* @arg {VoiceConnection} connection The voice connection to add
|
|
66
|
+
*/
|
|
67
|
+
add(connection) {
|
|
68
|
+
const _connection = this.voiceConnections.add(connection);
|
|
69
|
+
if (_connection.ready) {
|
|
70
|
+
_connection.setSpeaking(this.speaking);
|
|
71
|
+
} else {
|
|
72
|
+
_connection.once("ready", () => {
|
|
73
|
+
_connection.setSpeaking(this.speaking);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return _connection;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Play an audio or video resource. If playing from a non-opus resource, FFMPEG should be compiled with --enable-libopus for best performance. If playing from HTTPS, FFMPEG must be compiled with --enable-openssl
|
|
81
|
+
* @arg {ReadableStream | String} resource The audio or video resource, either a ReadableStream, URL, or file path
|
|
82
|
+
* @arg {Object} [options] Music options
|
|
83
|
+
* @arg {Array<String>} [options.encoderArgs] Additional encoder parameters to pass to ffmpeg/avconv (after -i)
|
|
84
|
+
* @arg {String} [options.format] The format of the resource. If null, FFmpeg will attempt to guess and play the format. Available options: "dca", "ogg", "webm", "pcm", "opusPackets", null
|
|
85
|
+
* @arg {Number} [options.frameDuration=60] The resource opus frame duration (required for DCA/Ogg)
|
|
86
|
+
* @arg {Number} [options.frameSize=2880] The resource opus frame size
|
|
87
|
+
* @arg {Boolean} [options.inlineVolume=false] Whether to enable on-the-fly volume changing. Note that enabling this leads to increased CPU usage
|
|
88
|
+
* @arg {Array<String>} [options.inputArgs] Additional input parameters to pass to ffmpeg/avconv (before -i)
|
|
89
|
+
* @arg {Number} [options.sampleRate=48000] The resource audio sampling rate
|
|
90
|
+
* @arg {Number} [options.voiceDataTimeout=2000] Timeout when waiting for voice data (-1 for no timeout)
|
|
91
|
+
*/
|
|
92
|
+
play(source, options = {}) {
|
|
93
|
+
options.format = options.format || null;
|
|
94
|
+
options.voiceDataTimeout = !isNaN(options.voiceDataTimeout) ? options.voiceDataTimeout : 2000;
|
|
95
|
+
options.inlineVolume = !!options.inlineVolume;
|
|
96
|
+
options.inputArgs = options.inputArgs || [];
|
|
97
|
+
options.encoderArgs = options.encoderArgs || [];
|
|
98
|
+
|
|
99
|
+
options.samplingRate = options.samplingRate || this.samplingRate;
|
|
100
|
+
options.frameDuration = options.frameDuration || this.frameDuration;
|
|
101
|
+
options.frameSize = options.frameSize || options.samplingRate * options.frameDuration / 1000;
|
|
102
|
+
options.pcmSize = options.pcmSize || options.frameSize * 2 * this.channels;
|
|
103
|
+
|
|
104
|
+
if (!this.piper.encode(source, options)) {
|
|
105
|
+
this.emit("error", new Error("Unable to encode source"));
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
this.ended = false;
|
|
110
|
+
this.current = {
|
|
111
|
+
startTime: 0, // later
|
|
112
|
+
playTime: 0,
|
|
113
|
+
pausedTimestamp: 0,
|
|
114
|
+
pausedTime: 0,
|
|
115
|
+
bufferingTicks: 0,
|
|
116
|
+
options: options,
|
|
117
|
+
timeout: null,
|
|
118
|
+
buffer: null,
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
this.playing = true;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Fired when the shared stream starts playing a stream
|
|
125
|
+
* @event SharedStream#start
|
|
126
|
+
*/
|
|
127
|
+
this.emit("start");
|
|
128
|
+
|
|
129
|
+
this._send();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Remove a voice connection from the shared stream
|
|
134
|
+
* @arg {VoiceConnection} connection The voice connection to remove
|
|
135
|
+
*/
|
|
136
|
+
remove(connection) {
|
|
137
|
+
return this.voiceConnections.remove(connection);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
setSpeaking(value) {
|
|
141
|
+
if ((value = !!value) != this.speaking) {
|
|
142
|
+
this.speaking = value;
|
|
143
|
+
for (const vc of this.voiceConnections.values()) {
|
|
144
|
+
vc.setSpeaking(value);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Sets the volume of this shared stream if inline volume is enabled
|
|
151
|
+
* @arg {Number} volume The volume as a value from 0 (min) to 1 (max)
|
|
152
|
+
*/
|
|
153
|
+
setVolume(volume) {
|
|
154
|
+
this.piper.setVolume(volume);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Stop the bot from sending audio
|
|
159
|
+
*/
|
|
160
|
+
stopPlaying() {
|
|
161
|
+
if (this.ended) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
this.ended = true;
|
|
165
|
+
if (this.current && this.current.timeout) {
|
|
166
|
+
clearTimeout(this.current.timeout);
|
|
167
|
+
this.current.timeout = null;
|
|
168
|
+
}
|
|
169
|
+
this.current = null;
|
|
170
|
+
this.piper.stop();
|
|
171
|
+
this.piper.resetPackets();
|
|
172
|
+
|
|
173
|
+
this.setSpeaking(this.playing = false);
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Fired when the shared stream finishes playing a stream
|
|
177
|
+
* @event SharedStream#end
|
|
178
|
+
*/
|
|
179
|
+
this.emit("end");
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
_incrementSequences() {
|
|
183
|
+
for (const vc of this.voiceConnections.values()) {
|
|
184
|
+
vc.sequence = (vc.sequence + 1) & 0xFFFF;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
_incrementTimestamps(val) {
|
|
189
|
+
for (const vc of this.voiceConnections.values()) {
|
|
190
|
+
vc.timestamp = (vc.timestamp + val) >>> 0;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
_send() {
|
|
195
|
+
if (!this.piper.encoding && this.piper.dataPacketCount === 0) {
|
|
196
|
+
return this.stopPlaying();
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
this._incrementTimestamps(this.current.options.frameSize);
|
|
200
|
+
|
|
201
|
+
this._incrementSequences();
|
|
202
|
+
|
|
203
|
+
if ((this.current.buffer = this.piper.getDataPacket())) {
|
|
204
|
+
if (this.current.startTime === 0) {
|
|
205
|
+
this.current.startTime = Date.now();
|
|
206
|
+
}
|
|
207
|
+
if (this.current.bufferingTicks > 0) {
|
|
208
|
+
this.current.bufferingTicks = 0;
|
|
209
|
+
this.setSpeaking(true);
|
|
210
|
+
}
|
|
211
|
+
} else if (this.current.options.voiceDataTimeout === -1 || this.current.bufferingTicks < this.current.options.voiceDataTimeout / (4 * this.current.options.frameDuration)) { // wait for data
|
|
212
|
+
if (++this.current.bufferingTicks === 1) {
|
|
213
|
+
this.setSpeaking(false);
|
|
214
|
+
} else {
|
|
215
|
+
this.current.pausedTime += 4 * this.current.options.frameDuration;
|
|
216
|
+
this._incrementTimestamps(3 * this.current.options.frameSize);
|
|
217
|
+
this.current.timeout = setTimeout(this._send, 4 * this.current.options.frameDuration);
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
} else {
|
|
221
|
+
return this.stopPlaying();
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
this.voiceConnections.forEach((connection) => {
|
|
225
|
+
if (connection.ready && this.current.buffer) {
|
|
226
|
+
connection._sendAudioFrame(this.current.buffer);
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
this.current.playTime += this.current.options.frameDuration;
|
|
230
|
+
this.current.timeout = setTimeout(this._send, Math.max(0, this.current.startTime + this.current.pausedTime + this.current.playTime - Date.now()));
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
[util.inspect.custom]() {
|
|
234
|
+
return Base.prototype[util.inspect.custom].call(this);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
module.exports = SharedStream;
|