change currentDispatcher to just dispatcher

This commit is contained in:
Amish Shah
2016-10-25 21:55:38 +01:00
parent 0f8e8dddff
commit ff16c9f01f

View File

@@ -11,7 +11,7 @@ class AudioPlayer extends EventEmitter {
this.audioToPCM = new (PCMConverters.fetch())(); this.audioToPCM = new (PCMConverters.fetch())();
this.opusEncoder = OpusEncoders.fetch(); this.opusEncoder = OpusEncoders.fetch();
this.currentConverter = null; this.currentConverter = null;
this.currentDispatcher = null; this.dispatcher = null;
this.audioToPCM.on('error', e => this.emit('error', e)); this.audioToPCM.on('error', e => this.emit('error', e));
this.streamingData = { this.streamingData = {
channels: 2, channels: 2,
@@ -38,7 +38,7 @@ class AudioPlayer extends EventEmitter {
cleanup(checkStream, reason) { cleanup(checkStream, reason) {
// cleanup is a lot less aggressive than v9 because it doesn't try to kill every single stream it is aware of // cleanup is a lot less aggressive than v9 because it doesn't try to kill every single stream it is aware of
this.emit('debug', `clean up triggered due to ${reason}`); this.emit('debug', `clean up triggered due to ${reason}`);
const filter = checkStream && this.currentDispatcher && this.currentDispatcher.stream === checkStream; const filter = checkStream && this.dispatcher && this.dispatcher.stream === checkStream;
if (this.currentConverter && (checkStream ? filter : true)) { if (this.currentConverter && (checkStream ? filter : true)) {
this.currentConverter.destroy(); this.currentConverter.destroy();
this.currentConverter = null; this.currentConverter = null;
@@ -50,15 +50,15 @@ class AudioPlayer extends EventEmitter {
stream.on('end', () => this.emit('debug', 'pcm input stream ended')); stream.on('end', () => this.emit('debug', 'pcm input stream ended'));
this.cleanup(null, 'outstanding play stream'); this.cleanup(null, 'outstanding play stream');
this.currentConverter = converter; this.currentConverter = converter;
if (this.currentDispatcher) { if (this.dispatcher) {
this.streamingData = this.currentDispatcher.streamingData; this.streamingData = this.dispatcher.streamingData;
} }
stream.on('error', e => this.emit('error', e)); stream.on('error', e => this.emit('error', e));
const dispatcher = new StreamDispatcher(this, stream, this.streamingData, options); const dispatcher = new StreamDispatcher(this, stream, this.streamingData, options);
dispatcher.on('error', e => this.emit('error', e)); dispatcher.on('error', e => this.emit('error', e));
dispatcher.on('end', () => this.cleanup(dispatcher.stream, 'disp ended')); dispatcher.on('end', () => this.cleanup(dispatcher.stream, 'disp ended'));
dispatcher.on('speaking', value => this.voiceConnection.setSpeaking(value)); dispatcher.on('speaking', value => this.voiceConnection.setSpeaking(value));
this.currentDispatcher = dispatcher; this.dispatcher = dispatcher;
dispatcher.on('debug', m => this.emit('debug', `stream dispatch - ${m}`)); dispatcher.on('debug', m => this.emit('debug', `stream dispatch - ${m}`));
return dispatcher; return dispatcher;
} }