mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 03:53:29 +01:00
voice: workaround for receiving audio
(#2929 and discordapp/discord-api-docs#808)
This commit is contained in:
@@ -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');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user