mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
voice: remove createReceiver, just use VoiceConnection.receiver
This commit is contained in:
@@ -54,12 +54,6 @@ class VoiceConnection extends EventEmitter {
|
||||
*/
|
||||
this.speaking = false;
|
||||
|
||||
/**
|
||||
* An array of Voice Receivers that have been created for this connection
|
||||
* @type {VoiceReceiver[]}
|
||||
*/
|
||||
this.receivers = [];
|
||||
|
||||
/**
|
||||
* The authentication data needed to connect to the voice server
|
||||
* @type {Object}
|
||||
@@ -114,6 +108,12 @@ class VoiceConnection extends EventEmitter {
|
||||
*/
|
||||
this.sockets = {};
|
||||
|
||||
/**
|
||||
* The voice receiver of this connection
|
||||
* @type {VoiceReceiver}
|
||||
*/
|
||||
this.receiver = null;
|
||||
|
||||
this.authenticate();
|
||||
}
|
||||
|
||||
@@ -417,6 +417,7 @@ class VoiceConnection extends EventEmitter {
|
||||
Object.assign(this.authentication, data);
|
||||
this.status = VoiceStatus.CONNECTED;
|
||||
clearTimeout(this.connectTimeout);
|
||||
this.receiver = new VoiceReceiver(this);
|
||||
/**
|
||||
* Emitted once the connection is ready, when a promise to join a voice channel resolves,
|
||||
* the connection will already be ready.
|
||||
@@ -446,9 +447,7 @@ class VoiceConnection extends EventEmitter {
|
||||
if (this.status === VoiceStatus.CONNECTED) {
|
||||
this.emit('speaking', user, speaking);
|
||||
if (!speaking) {
|
||||
for (const receiver of this.receivers) {
|
||||
receiver.packets._stoppedSpeaking(user_id);
|
||||
}
|
||||
this.receiver.packets._stoppedSpeaking(user_id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -466,17 +465,6 @@ class VoiceConnection extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a VoiceReceiver so you can start listening to voice data.
|
||||
* It's recommended to only create one of these.
|
||||
* @returns {VoiceReceiver}
|
||||
*/
|
||||
createReceiver() {
|
||||
const receiver = new VoiceReceiver(this);
|
||||
this.receivers.push(receiver);
|
||||
return receiver;
|
||||
}
|
||||
|
||||
play() {} // eslint-disable-line no-empty-function
|
||||
}
|
||||
|
||||
|
||||
@@ -180,12 +180,10 @@ class VoiceWebSocket extends EventEmitter {
|
||||
this.connection.ssrcMap.set(+packet.d.audio_ssrc, packet.d.user_id);
|
||||
break;
|
||||
case VoiceOPCodes.CLIENT_DISCONNECT:
|
||||
for (const receiver of this.connection.receivers) {
|
||||
const streamInfo = receiver.packets.streams.get(packet.d.user_id);
|
||||
if (streamInfo) {
|
||||
receiver.packets.streams.delete(packet.d.user_id);
|
||||
streamInfo.stream.push(null);
|
||||
}
|
||||
const streamInfo = this.connection.receiver.packets.streams.get(packet.d.user_id);
|
||||
if (streamInfo) {
|
||||
this.connection.receiver.packets.streams.delete(packet.d.user_id);
|
||||
streamInfo.stream.push(null);
|
||||
}
|
||||
break;
|
||||
case VoiceOPCodes.SPEAKING:
|
||||
|
||||
@@ -41,8 +41,7 @@ client.on('message', m => {
|
||||
const channel = m.guild.channels.get(m.content.split(' ')[1]) || m.member.voice.channel;
|
||||
if (channel && channel.type === 'voice') {
|
||||
channel.join().then(conn => {
|
||||
const receiver = conn.createReceiver();
|
||||
receiver.createStream(m.author, true).on('data', b => console.log(b.toString()));
|
||||
conn.receiver.createStream(m.author, true).on('data', b => console.log(b.toString()));
|
||||
conn.player.on('error', (...e) => console.log('player', ...e));
|
||||
if (!connections.has(m.guild.id)) connections.set(m.guild.id, { conn, queue: [] });
|
||||
m.reply('ok!');
|
||||
|
||||
Reference in New Issue
Block a user