mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 00:23:30 +01:00
more voice stuff
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -1,4 +1,6 @@
|
||||
const Collection = require('../util/Collection');
|
||||
const mergeDefault = require('../util/MergeDefault');
|
||||
const Constants = require('../util/Constants');
|
||||
|
||||
/**
|
||||
* Manages all the voice stuff for the Client
|
||||
@@ -16,13 +18,31 @@ class ClientVoiceManager {
|
||||
this.connections = new Collection();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a request to the main gateway to join a voice channel
|
||||
* @param {VoiceChannel} channel the channel to join
|
||||
* @param {Object} [options] the options to provide
|
||||
*/
|
||||
_sendWSJoin(channel, options = {}) {
|
||||
options = mergeDefault({
|
||||
guild_id: channel.guild.id,
|
||||
channel_id: channel.id,
|
||||
self_mute: false,
|
||||
self_deaf: false,
|
||||
}, options);
|
||||
this.client.ws.send({
|
||||
op: Constants.OPCodes.VOICE_STATE_UPDATE,
|
||||
d: options,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up a request to join a voice channel
|
||||
* @param {VoiceChannel} channel the voice channel to join
|
||||
* @returns {null}
|
||||
*/
|
||||
joinChannel(channel) {
|
||||
return channel;
|
||||
this._sendWSJoin(channel);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -127,6 +127,7 @@ class WebSocketManager {
|
||||
* @returns {null}
|
||||
*/
|
||||
eventClose(event) {
|
||||
console.log('close', event.code);
|
||||
if (event.code === 4004) {
|
||||
throw Constants.Errors.BAD_LOGIN;
|
||||
}
|
||||
@@ -154,6 +155,8 @@ class WebSocketManager {
|
||||
return this.eventError(Constants.Errors.BAD_WS_MESSAGE);
|
||||
}
|
||||
|
||||
this.client.emit('raw', packet);
|
||||
|
||||
if (packet.op === 10) {
|
||||
this.client.manager.setupKeepAlive(packet.d.heartbeat_interval);
|
||||
}
|
||||
|
||||
@@ -42,6 +42,10 @@ class VoiceChannel extends GuildChannel {
|
||||
setBitrate(bitrate) {
|
||||
return this.rest.client.rest.methods.updateChannel(this, { bitrate });
|
||||
}
|
||||
|
||||
join() {
|
||||
return this.client.voice.joinChannel(this);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = VoiceChannel;
|
||||
|
||||
Reference in New Issue
Block a user