mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-16 03:23:29 +01:00
voice: start using provided IP rather than manually resolving
This commit is contained in:
1
krypton
Submodule
1
krypton
Submodule
Submodule krypton added at 63551eb93b
@@ -252,6 +252,11 @@ class VoiceConnection extends EventEmitter {
|
|||||||
*/
|
*/
|
||||||
this.emit('failed', new Error(reason));
|
this.emit('failed', new Error(reason));
|
||||||
} else {
|
} else {
|
||||||
|
/**
|
||||||
|
* Emitted whenever the connection encounters an error.
|
||||||
|
* @event VoiceConnection#error
|
||||||
|
* @param {Error} error The encountered error
|
||||||
|
*/
|
||||||
this.emit('error', new Error(reason));
|
this.emit('error', new Error(reason));
|
||||||
}
|
}
|
||||||
this.status = VoiceStatus.DISCONNECTED;
|
this.status = VoiceStatus.DISCONNECTED;
|
||||||
@@ -377,20 +382,10 @@ class VoiceConnection extends EventEmitter {
|
|||||||
* @param {Object} data The received data
|
* @param {Object} data The received data
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
onReady({ port, ssrc }) {
|
onReady({ port, ssrc, ip }) {
|
||||||
this.authentication.port = port;
|
this.authentication.port = port;
|
||||||
this.authentication.ssrc = ssrc;
|
this.authentication.ssrc = ssrc;
|
||||||
|
this.sockets.udp.createUDPSocket(ip);
|
||||||
const udp = this.sockets.udp;
|
|
||||||
/**
|
|
||||||
* Emitted whenever the connection encounters an error.
|
|
||||||
* @event VoiceConnection#error
|
|
||||||
* @param {Error} error The encountered error
|
|
||||||
*/
|
|
||||||
udp.findEndpointAddress()
|
|
||||||
.then(address => {
|
|
||||||
udp.createUDPSocket(address);
|
|
||||||
}, e => this.emit('error', e));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
const udp = require('dgram');
|
const udp = require('dgram');
|
||||||
const dns = require('dns');
|
|
||||||
const { VoiceOPCodes } = require('../../../util/Constants');
|
const { VoiceOPCodes } = require('../../../util/Constants');
|
||||||
const EventEmitter = require('events');
|
const EventEmitter = require('events');
|
||||||
const { Error } = require('../../../errors');
|
const { Error } = require('../../../errors');
|
||||||
@@ -66,23 +65,6 @@ class VoiceConnectionUDPClient extends EventEmitter {
|
|||||||
return this.voiceConnection.authentication.port;
|
return this.voiceConnection.authentication.port;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Tries to resolve the voice server endpoint to an address.
|
|
||||||
* @returns {Promise<string>}
|
|
||||||
*/
|
|
||||||
findEndpointAddress() {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
dns.lookup(this.voiceConnection.authentication.endpoint, (error, address) => {
|
|
||||||
if (error) {
|
|
||||||
reject(error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.discordAddress = address;
|
|
||||||
resolve(address);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a packet to the UDP client.
|
* Send a packet to the UDP client.
|
||||||
* @param {Object} packet The packet to send
|
* @param {Object} packet The packet to send
|
||||||
|
|||||||
Reference in New Issue
Block a user