voice: workaround for receiving audio

(#2929 and discordapp/discord-api-docs#808)
This commit is contained in:
Amish Shah
2019-02-05 10:26:16 +00:00
parent d98d464d74
commit f826c9c75e

View File

@@ -10,6 +10,15 @@ const EventEmitter = require('events');
const { Error } = require('../../errors'); const { Error } = require('../../errors');
const PlayInterface = require('./util/PlayInterface'); const PlayInterface = require('./util/PlayInterface');
const Speaking = require('../../util/Speaking'); const Speaking = require('../../util/Speaking');
const Silence = require('./util/Silence');
// Workaround for Discord now requiring silence to be sent before being able to receive audio
class SingleSilence extends Silence {
_read() {
super._read();
this.push(null);
}
}
const SUPPORTED_MODES = [ const SUPPORTED_MODES = [
'xsalsa20_poly1305_lite', 'xsalsa20_poly1305_lite',
@@ -419,13 +428,16 @@ class VoiceConnection extends EventEmitter {
onSessionDescription(data) { onSessionDescription(data) {
Object.assign(this.authentication, data); Object.assign(this.authentication, data);
this.status = VoiceStatus.CONNECTED; this.status = VoiceStatus.CONNECTED;
clearTimeout(this.connectTimeout); const dispatcher = this.play(new SingleSilence(), { type: 'opus' });
/** dispatcher.on('finish', () => {
* Emitted once the connection is ready, when a promise to join a voice channel resolves, clearTimeout(this.connectTimeout);
* the connection will already be ready. /**
* @event VoiceConnection#ready * Emitted once the connection is ready, when a promise to join a voice channel resolves,
*/ * the connection will already be ready.
this.emit('ready'); * @event VoiceConnection#ready
*/
this.emit('ready');
});
} }
/** /**