get voice sort of working

This commit is contained in:
Amish Shah
2016-10-24 14:26:24 +01:00
parent 9b3dd540ef
commit e13e2447d4
8 changed files with 81 additions and 15 deletions

View File

@@ -2,8 +2,8 @@ const VoiceWebSocket = require('./VoiceWebSocket');
const VoiceUDP = require('./VoiceUDPClient');
const VoiceReceiver = require('./receiver/VoiceReceiver');
const Constants = require('../../util/Constants');
const AudioPlayer = require('./player/AudioPlayer');
const EventEmitter = require('events').EventEmitter;
const DefaultPlayer = require('./player/DefaultPlayer');
/**
* Represents a connection to a Voice Channel in Discord.
@@ -37,6 +37,8 @@ class VoiceConnection extends EventEmitter {
*/
this.authentication = pendingConnection.data;
this.player = new AudioPlayer(this);
/**
* Object that wraps contains the `ws` and `udp` sockets of this voice connection
* @type {object}
@@ -45,6 +47,18 @@ class VoiceConnection extends EventEmitter {
this.connect();
}
setSpeaking(value) {
if (this.speaking === value) return;
this.speaking = value;
this.sockets.ws.sendPacket({
op: Constants.VoiceOPCodes.SPEAKING,
d: {
speaking: true,
delay: 0,
},
});
}
connect() {
if (this.sockets.ws) {
throw new Error('There is already an existing WebSocket connection!');
@@ -58,6 +72,7 @@ class VoiceConnection extends EventEmitter {
this.sockets.udp.on('error', e => this.emit('error', e));
this.sockets.ws.once('ready', d => {
this.authentication.port = d.port;
this.authentication.ssrc = d.ssrc;
this.sockets.udp.findEndpointAddress()
.then(address => {
this.sockets.udp.createUDPSocket(address);