more voice stuff

This commit is contained in:
Amish Shah
2016-08-23 16:59:34 +01:00
parent f38aff7523
commit 0edf838474
4 changed files with 29 additions and 2 deletions

File diff suppressed because one or more lines are too long

View File

@@ -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);
}
}

View File

@@ -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);
}

View File

@@ -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;