Promisify

This commit is contained in:
Amish Shah
2016-08-23 21:04:15 +01:00
parent e370ccf806
commit d0a76f3f38
3 changed files with 25 additions and 10 deletions

View File

@@ -3,21 +3,32 @@ const VoiceConnectionUDPClient = require('./VoiceConnectionUDPClient');
const EventEmitter = require('events').EventEmitter;
class VoiceConnection extends EventEmitter {
constructor(manager, serverID, token, sessionID, endpoint) {
constructor(manager, serverID, token, sessionID, endpoint, resolve, reject) {
super();
this.manager = manager;
this.endpoint = endpoint;
this.websocket = new VoiceConnectionWebSocket(this, serverID, token, sessionID, endpoint);
this.ready = false;
this._resolve = resolve;
this._reject = reject;
this.bindListeners();
}
_onError(e) {
this._reject(e);
this.emit('error', e);
}
bindListeners() {
this.websocket.on('error', err => this._onError(err));
this.websocket.on('ready-for-udp', data => {
this.udp = new VoiceConnectionUDPClient(this, data);
this.udp.on('error', err => this._onError(err));
});
this.websocket.on('ready', () => {
this.ready = true;
this.emit('ready');
this._resolve(this);
});
}
}