From dc640017cdaf732fdb544e9e40e0db1cbba308e3 Mon Sep 17 00:00:00 2001 From: Amish Shah Date: Sat, 7 Jan 2017 21:10:46 +0000 Subject: [PATCH] Fix some stream bugs --- src/client/voice/VoiceBroadcast.js | 7 ++----- src/client/voice/VoiceConnection.js | 4 ++-- src/client/voice/dispatcher/StreamDispatcher.js | 5 ++++- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/client/voice/VoiceBroadcast.js b/src/client/voice/VoiceBroadcast.js index 9851457f..003da16b 100644 --- a/src/client/voice/VoiceBroadcast.js +++ b/src/client/voice/VoiceBroadcast.js @@ -151,6 +151,7 @@ class VoiceBroadcast extends EventEmitter { if (this.currentTranscoder) { if (this.currentTranscoder.transcoder) this.currentTranscoder.transcoder.kill(); this.currentTranscoder = null; + this.emit('end'); } } @@ -225,10 +226,7 @@ class VoiceBroadcast extends EventEmitter { * Emitted once the broadcast (the audio stream) ends * @event VoiceBroadcast#end */ - transcoder.once('end', () => { - this.emit('end'); - this.killCurrentTranscoder(); - }); + transcoder.once('end', () => this.killCurrentTranscoder()); this.currentTranscoder = { transcoder, options, @@ -245,7 +243,6 @@ class VoiceBroadcast extends EventEmitter { */ playConvertedStream(stream, { seek = 0, volume = 1, passes = 1 } = {}) { this.killCurrentTranscoder(); - stream.once('end', () => this.emit('end')); const options = { seek, volume, passes, stream }; this.currentTranscoder = { options }; stream.once('readable', () => this._startPlaying()); diff --git a/src/client/voice/VoiceConnection.js b/src/client/voice/VoiceConnection.js index c0c6e43b..f90fec91 100644 --- a/src/client/voice/VoiceConnection.js +++ b/src/client/voice/VoiceConnection.js @@ -160,7 +160,7 @@ class VoiceConnection extends EventEmitter { this.sockets.udp = new VoiceUDP(this); this.sockets.ws.on('error', e => this.emit('error', e)); this.sockets.udp.on('error', e => this.emit('error', e)); - this.sockets.ws.once('ready', d => { + this.sockets.ws.on('ready', d => { this.authentication.port = d.port; this.authentication.ssrc = d.ssrc; /** @@ -173,7 +173,7 @@ class VoiceConnection extends EventEmitter { this.sockets.udp.createUDPSocket(address); }, e => this.emit('error', e)); }); - this.sockets.ws.once('sessionDescription', (mode, secret) => { + this.sockets.ws.on('sessionDescription', (mode, secret) => { this.authentication.encryptionMode = mode; this.authentication.secretKey = secret; /** diff --git a/src/client/voice/dispatcher/StreamDispatcher.js b/src/client/voice/dispatcher/StreamDispatcher.js index a2d15046..3edb759f 100644 --- a/src/client/voice/dispatcher/StreamDispatcher.js +++ b/src/client/voice/dispatcher/StreamDispatcher.js @@ -172,7 +172,10 @@ class StreamDispatcher extends EventEmitter { this.setSpeaking(true); while (repeats--) { this.player.voiceConnection.sockets.udp.send(packet) - .catch(e => this.emit('debug', `Failed to send a packet ${e}`)); + .catch(e => { + this.setSpeaking(false); + this.emit('debug', `Failed to send a packet ${e}`); + }); } }