diff --git a/src/client/voice/dispatcher/StreamDispatcher.js b/src/client/voice/dispatcher/StreamDispatcher.js index 19ded79ff..8f1483e17 100644 --- a/src/client/voice/dispatcher/StreamDispatcher.js +++ b/src/client/voice/dispatcher/StreamDispatcher.js @@ -114,9 +114,10 @@ class StreamDispatcher extends EventEmitter { /** * Stops the current stream permanently and emits an `end` event. + * @param {string} [reason='user'] An optional reason for stopping the dispatcher. */ - end() { - this._triggerTerminalState('end', 'user requested'); + end(reason = 'user') { + this._triggerTerminalState('end', reason); } _setSpeaking(value) { @@ -179,7 +180,7 @@ class StreamDispatcher extends EventEmitter { const data = this.streamingData; if (data.missed >= 5) { - this._triggerTerminalState('end', 'Stream is not generating quickly enough.'); + this._triggerTerminalState('error', 'Stream is not generating quickly enough.'); return; } @@ -233,12 +234,14 @@ class StreamDispatcher extends EventEmitter { } } - _triggerEnd() { + _triggerEnd(reason) { /** * Emitted once the stream has ended. Attach a `once` listener to this. * @event StreamDispatcher#end + * @param {string} reason The reason for the end of the dispatcher. If it ended because it reached the end of the + * stream, this would be `stream`. If you invoke `.end()` without specifying a reason, this would be `user`. */ - this.emit('end'); + this.emit('end', reason); } _triggerError(err) { @@ -280,7 +283,7 @@ class StreamDispatcher extends EventEmitter { return; } - this.stream.on('end', err => this._triggerTerminalState('end', err)); + this.stream.on('end', err => this._triggerTerminalState('end', err || 'stream')); this.stream.on('error', err => this._triggerTerminalState('error', err)); const data = this.streamingData;