Add voice connection timeout

This commit is contained in:
abalabahaha
2016-05-20 20:50:49 -07:00
parent 3fa3b0238e
commit 48595ddd19
2 changed files with 22 additions and 4 deletions

View File

@@ -367,11 +367,13 @@ var InternalClient = (function () {
server = channel.server,
endpoint;
var timeout = null;
var check = function check(m) {
var data = JSON.parse(m);
if (data.d.guild_id !== server.id) return; // ensure it is the right server
if (data.t === "VOICE_SERVER_UPDATE") {
if (data.d.guild_id !== server.id) return; // ensure it is the right server
token = data.d.token;
endpoint = data.d.endpoint;
var chan = new _VoiceVoiceConnection2["default"](channel, _this5.client, session, token, server, endpoint);
@@ -383,11 +385,18 @@ var InternalClient = (function () {
chan.on("error", reject);
chan.on("close", reject);
_this5.client.emit("debug", "removed temporary voice websocket listeners");
if (timeout) {
clearTimeout(timeout);
}
_this5.websocket.removeListener("message", check);
}
};
timeout = setTimeout(function () {
_this5.websocket.removeListener("message", check);
reject(new Error("No voice server details within 10 seconds"));
}, 10000);
_this5.websocket.on("message", check);
joinSendWS();
});

View File

@@ -287,11 +287,13 @@ export default class InternalClient {
return new Promise((resolve, reject) => {
var session = this.sessionID, token, server = channel.server, endpoint;
var timeout = null;
var check = m => {
var data = JSON.parse(m);
if (data.d.guild_id !== server.id) return // ensure it is the right server
if (data.t === "VOICE_SERVER_UPDATE") {
if (data.d.guild_id !== server.id) return // ensure it is the right server
token = data.d.token;
endpoint = data.d.endpoint;
var chan = new VoiceConnection(
@@ -303,11 +305,18 @@ export default class InternalClient {
chan.on("error", reject);
chan.on("close", reject);
this.client.emit("debug", "removed temporary voice websocket listeners");
if(timeout) {
clearTimeout(timeout);
}
this.websocket.removeListener("message", check);
}
};
timeout = setTimeout(() => {
this.websocket.removeListener("message", check);
reject(new Error("No voice server details within 10 seconds"));
}, 10000);
this.websocket.on("message", check);
joinSendWS();
});