Remove old stuff

This commit is contained in:
Amish Shah
2016-12-28 18:16:26 +00:00
parent 8e75b47a7b
commit 0a47d0e1d6
6 changed files with 18 additions and 552 deletions

View File

@@ -32,14 +32,20 @@ class AudioPlayer extends EventEmitter {
return this.streams.last().transcoder;
}
destroyAllStreams(exceptLatest) {
destroyStream(stream) {
const data = this.streams.get(stream);
if (!data) return;
const transcoder = data.transcoder;
const dispatcher = data.dispatcher;
if (transcoder) transcoder.kill();
if (dispatcher) dispatcher.destroy('end');
}
destroyAllStreams(except) {
for (const stream of this.streams.keys()) {
const data = this.streams.get(stream);
const transcoder = data.transcoder;
const dispatcher = data.dispatcher;
if (exceptLatest && transcoder === this.currentTranscoder) continue;
if (transcoder) transcoder.kill();
if (dispatcher) dispatcher.destroy('end');
if (except === stream) continue;
if (except === true && this.streams.get(stream) === this.streams.last()) continue;
this.destroyStream(stream);
}
}
@@ -51,6 +57,11 @@ class AudioPlayer extends EventEmitter {
ffmpegArguments: ffmpegArguments.concat(['-ss', String(seek)]),
});
this.streams.set(stream, { transcoder });
transcoder.on('error', e => {
this.destroyStream(stream);
if (this.listenerCount('error') > 0) this.emit('error', e);
else this.emit('warn', e);
});
this.playPCMStream(transcoder.output, options);
}