mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 12:03:31 +01:00
Reset what is playing
This commit is contained in:
@@ -16,6 +16,7 @@ class VoiceBroadcast extends EventEmitter {
|
|||||||
this.dispatchers = [];
|
this.dispatchers = [];
|
||||||
this.prism = new Prism();
|
this.prism = new Prism();
|
||||||
this.currentTranscoder = null;
|
this.currentTranscoder = null;
|
||||||
|
this.tickInterval = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
get _playableStream() {
|
get _playableStream() {
|
||||||
@@ -24,7 +25,13 @@ class VoiceBroadcast extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
registerDispatcher(dispatcher) {
|
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() {
|
killCurrentTranscoder() {
|
||||||
@@ -71,6 +78,11 @@ class VoiceBroadcast extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_startPlaying() {
|
_startPlaying() {
|
||||||
|
if (this.tickInterval) clearInterval(this.tickInterval);
|
||||||
|
this.tickInterval = this.client.setInterval(this.tick.bind(this), 20);
|
||||||
|
}
|
||||||
|
|
||||||
|
tick() {
|
||||||
if (!this._playableStream) return;
|
if (!this._playableStream) return;
|
||||||
const stream = this._playableStream;
|
const stream = this._playableStream;
|
||||||
const buffer = stream.read(1920 * 2);
|
const buffer = stream.read(1920 * 2);
|
||||||
@@ -78,7 +90,13 @@ class VoiceBroadcast extends EventEmitter {
|
|||||||
for (const dispatcher of this.dispatchers) {
|
for (const dispatcher of this.dispatchers) {
|
||||||
setImmediate(() => dispatcher.process(buffer, true));
|
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;
|
const data = this.streamingData;
|
||||||
|
|
||||||
if (data.missed >= 5) {
|
if (data.missed >= 5 && !controlled) {
|
||||||
this.destroy('end', 'Stream is not generating quickly enough.');
|
this.destroy('end', 'Stream is not generating quickly enough.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user