Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
connect(data) {
if (this.connecting) {
return;
}
this.connecting = true;
if (this.ws && this.ws.readyState !== WebSocket.CLOSED) {
this.disconnect(undefined, true);
return setTimeout(() => this.connect(data), 500);
}
if (!data.endpoint || !data.token || !data.session_id || !data.user_id) {
this.disconnect(new Error('Malformed voice server update: ' + JSON.stringify(data)));
return;
}
this.channelID = data.channel_id;
this.endpoint = data.endpoint.split(':')[0];
this.ws = new WebSocket('wss://' + this.endpoint);
let connectionTimeout = setTimeout(() => {
if (this.connecting) {
this.disconnect(new Error('Voice connection timeout'));
}
connectionTimeout = null;
}, this.shard.client ? this.shard.client.options.connectionTimeout : 30000);