mirror of
https://github.com/danbulant/discord.js
synced 2026-05-25 04:52:22 +00:00
Reset what is playing
This commit is contained in:
parent
72a99f9582
commit
ad18b05d66
2 changed files with 21 additions and 3 deletions
|
|
@ -16,6 +16,7 @@ class VoiceBroadcast extends EventEmitter {
|
|||
this.dispatchers = [];
|
||||
this.prism = new Prism();
|
||||
this.currentTranscoder = null;
|
||||
this.tickInterval = null;
|
||||
}
|
||||
|
||||
get _playableStream() {
|
||||
|
|
@ -24,7 +25,13 @@ class VoiceBroadcast extends EventEmitter {
|
|||
}
|
||||
|
||||
registerDispatcher(dispatcher) {
|
||||
if (!this.dispatchers.includes(dispatcher)) this.dispatchers.push(dispatcher);
|
||||
if (!this.dispatchers.includes(dispatcher)) {
|
||||
this.dispatchers.push(dispatcher);
|
||||
dispatcher.once('end', () => {
|
||||
const ind = this.dispatchers.indexOf(dispatcher);
|
||||
if (ind > -1) this.dispatchers.splice(ind, 1);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
killCurrentTranscoder() {
|
||||
|
|
@ -71,6 +78,11 @@ class VoiceBroadcast extends EventEmitter {
|
|||
}
|
||||
|
||||
_startPlaying() {
|
||||
if (this.tickInterval) clearInterval(this.tickInterval);
|
||||
this.tickInterval = this.client.setInterval(this.tick.bind(this), 20);
|
||||
}
|
||||
|
||||
tick() {
|
||||
if (!this._playableStream) return;
|
||||
const stream = this._playableStream;
|
||||
const buffer = stream.read(1920 * 2);
|
||||
|
|
@ -78,7 +90,13 @@ class VoiceBroadcast extends EventEmitter {
|
|||
for (const dispatcher of this.dispatchers) {
|
||||
setImmediate(() => dispatcher.process(buffer, true));
|
||||
}
|
||||
setTimeout(this._startPlaying.bind(this), 20);
|
||||
}
|
||||
|
||||
end() {
|
||||
this.killCurrentTranscoder();
|
||||
for (const dispatcher of this.dispatchers) {
|
||||
dispatcher.destroy('end', 'broadcast ended');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -177,7 +177,7 @@ class StreamDispatcher extends EventEmitter {
|
|||
|
||||
const data = this.streamingData;
|
||||
|
||||
if (data.missed >= 5) {
|
||||
if (data.missed >= 5 && !controlled) {
|
||||
this.destroy('end', 'Stream is not generating quickly enough.');
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue