Fix some stream bugs

This commit is contained in:
Amish Shah
2017-01-07 21:10:46 +00:00
parent fcd7cf1450
commit dc640017cd
3 changed files with 8 additions and 8 deletions

View File

@@ -151,6 +151,7 @@ class VoiceBroadcast extends EventEmitter {
if (this.currentTranscoder) { if (this.currentTranscoder) {
if (this.currentTranscoder.transcoder) this.currentTranscoder.transcoder.kill(); if (this.currentTranscoder.transcoder) this.currentTranscoder.transcoder.kill();
this.currentTranscoder = null; this.currentTranscoder = null;
this.emit('end');
} }
} }
@@ -225,10 +226,7 @@ class VoiceBroadcast extends EventEmitter {
* Emitted once the broadcast (the audio stream) ends * Emitted once the broadcast (the audio stream) ends
* @event VoiceBroadcast#end * @event VoiceBroadcast#end
*/ */
transcoder.once('end', () => { transcoder.once('end', () => this.killCurrentTranscoder());
this.emit('end');
this.killCurrentTranscoder();
});
this.currentTranscoder = { this.currentTranscoder = {
transcoder, transcoder,
options, options,
@@ -245,7 +243,6 @@ class VoiceBroadcast extends EventEmitter {
*/ */
playConvertedStream(stream, { seek = 0, volume = 1, passes = 1 } = {}) { playConvertedStream(stream, { seek = 0, volume = 1, passes = 1 } = {}) {
this.killCurrentTranscoder(); this.killCurrentTranscoder();
stream.once('end', () => this.emit('end'));
const options = { seek, volume, passes, stream }; const options = { seek, volume, passes, stream };
this.currentTranscoder = { options }; this.currentTranscoder = { options };
stream.once('readable', () => this._startPlaying()); stream.once('readable', () => this._startPlaying());

View File

@@ -160,7 +160,7 @@ class VoiceConnection extends EventEmitter {
this.sockets.udp = new VoiceUDP(this); this.sockets.udp = new VoiceUDP(this);
this.sockets.ws.on('error', e => this.emit('error', e)); this.sockets.ws.on('error', e => this.emit('error', e));
this.sockets.udp.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.port = d.port;
this.authentication.ssrc = d.ssrc; this.authentication.ssrc = d.ssrc;
/** /**
@@ -173,7 +173,7 @@ class VoiceConnection extends EventEmitter {
this.sockets.udp.createUDPSocket(address); this.sockets.udp.createUDPSocket(address);
}, e => this.emit('error', e)); }, 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.encryptionMode = mode;
this.authentication.secretKey = secret; this.authentication.secretKey = secret;
/** /**

View File

@@ -172,7 +172,10 @@ class StreamDispatcher extends EventEmitter {
this.setSpeaking(true); this.setSpeaking(true);
while (repeats--) { while (repeats--) {
this.player.voiceConnection.sockets.udp.send(packet) 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}`);
});
} }
} }