VoiceReadable stream now ends when a member leaves a VoiceChannel

This commit is contained in:
Amish Shah
2016-08-27 15:35:45 +01:00
parent e47f3dda94
commit 19d976748c
2 changed files with 20 additions and 1 deletions

File diff suppressed because one or more lines are too long

View File

@@ -152,6 +152,25 @@ class VoiceConnection extends EventEmitter {
this.queue = [];
});
});
this.manager.client.on(Constants.Events.VOICE_STATE_UPDATE, (oldM, newM) => {
if (oldM.voiceChannel && oldM.voiceChannel.guild.id === this.channel.guild.id && !newM.voiceChannel) {
const user = newM.user;
for (const receiver of this.receivers) {
const opusStream = receiver.opusStreams.get(user.id);
const pcmStream = receiver.pcmStreams.get(user.id);
if (opusStream) {
opusStream.push(null);
opusStream.open = false;
receiver.opusStreams.delete(user.id);
}
if (pcmStream) {
pcmStream.push(null);
pcmStream.open = false;
receiver.pcmStreams.delete(user.id);
}
}
}
});
this.websocket.on('speaking', data => {
const guild = this.channel.guild;
const user = this.manager.client.users.get(data.user_id);