mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-12 09:33:32 +01:00
Improve docs a bit
This commit is contained in:
@@ -10,7 +10,7 @@ try {
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a Voice Connection's WebSocket
|
||||
* Represents a Voice Connection's WebSocket.
|
||||
* @extends {EventEmitter}
|
||||
* @private
|
||||
*/
|
||||
@@ -18,6 +18,12 @@ class VoiceWebSocket extends EventEmitter {
|
||||
constructor(voiceConnection) {
|
||||
super();
|
||||
|
||||
/**
|
||||
* The client of this voice WebSocket
|
||||
* @type {Client}
|
||||
*/
|
||||
this.client = voiceConnection.voiceManager.client;
|
||||
|
||||
/**
|
||||
* The Voice Connection that this WebSocket serves
|
||||
* @type {VoiceConnection}
|
||||
@@ -41,16 +47,7 @@ class VoiceWebSocket extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* The client of this voice websocket
|
||||
* @type {Client}
|
||||
* @readonly
|
||||
*/
|
||||
get client() {
|
||||
return this.voiceConnection.voiceManager.client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the current WebSocket
|
||||
* Resets the current WebSocket.
|
||||
*/
|
||||
reset() {
|
||||
if (this.ws) {
|
||||
@@ -86,7 +83,7 @@ class VoiceWebSocket extends EventEmitter {
|
||||
|
||||
/**
|
||||
* Sends data to the WebSocket if it is open.
|
||||
* @param {string} data the data to send to the WebSocket
|
||||
* @param {string} data The data to send to the WebSocket
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
send(data) {
|
||||
@@ -102,7 +99,7 @@ class VoiceWebSocket extends EventEmitter {
|
||||
|
||||
/**
|
||||
* JSON.stringify's a packet and then sends it to the WebSocket Server.
|
||||
* @param {Object} packet the packet to send
|
||||
* @param {Object} packet The packet to send
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
sendPacket(packet) {
|
||||
@@ -115,7 +112,7 @@ class VoiceWebSocket extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called whenever the WebSocket opens
|
||||
* Called whenever the WebSocket opens.
|
||||
*/
|
||||
onOpen() {
|
||||
this.sendPacket({
|
||||
@@ -132,8 +129,8 @@ class VoiceWebSocket extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called whenever a message is received from the WebSocket
|
||||
* @param {MessageEvent} event the message event that was received
|
||||
* Called whenever a message is received from the WebSocket.
|
||||
* @param {MessageEvent} event The message event that was received
|
||||
* @returns {void}
|
||||
*/
|
||||
onMessage(event) {
|
||||
@@ -145,7 +142,7 @@ class VoiceWebSocket extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called whenever the connection to the WebSocket Server is lost
|
||||
* Called whenever the connection to the WebSocket server is lost.
|
||||
*/
|
||||
onClose() {
|
||||
if (!this.dead) this.client.setTimeout(this.connect.bind(this), this.attempts * 1000);
|
||||
@@ -160,7 +157,7 @@ class VoiceWebSocket extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called whenever a valid packet is received from the WebSocket
|
||||
* Called whenever a valid packet is received from the WebSocket.
|
||||
* @param {Object} packet The received packet
|
||||
*/
|
||||
onPacket(packet) {
|
||||
@@ -168,7 +165,7 @@ class VoiceWebSocket extends EventEmitter {
|
||||
case Constants.VoiceOPCodes.READY:
|
||||
this.setHeartbeat(packet.d.heartbeat_interval);
|
||||
/**
|
||||
* Emitted once the voice websocket receives the ready packet
|
||||
* Emitted once the voice WebSocket receives the ready packet.
|
||||
* @param {Object} packet The received packet
|
||||
* @event VoiceWebSocket#ready
|
||||
*/
|
||||
@@ -176,7 +173,7 @@ class VoiceWebSocket extends EventEmitter {
|
||||
break;
|
||||
case Constants.VoiceOPCodes.SESSION_DESCRIPTION:
|
||||
/**
|
||||
* Emitted once the Voice Websocket receives a description of this voice session
|
||||
* Emitted once the Voice Websocket receives a description of this voice session.
|
||||
* @param {string} encryptionMode The type of encryption being used
|
||||
* @param {SecretKey} secretKey The secret key used for encryption
|
||||
* @event VoiceWebSocket#sessionDescription
|
||||
@@ -185,7 +182,7 @@ class VoiceWebSocket extends EventEmitter {
|
||||
break;
|
||||
case Constants.VoiceOPCodes.SPEAKING:
|
||||
/**
|
||||
* Emitted whenever a speaking packet is received
|
||||
* Emitted whenever a speaking packet is received.
|
||||
* @param {Object} data
|
||||
* @event VoiceWebSocket#speaking
|
||||
*/
|
||||
@@ -193,7 +190,7 @@ class VoiceWebSocket extends EventEmitter {
|
||||
break;
|
||||
default:
|
||||
/**
|
||||
* Emitted when an unhandled packet is received
|
||||
* Emitted when an unhandled packet is received.
|
||||
* @param {Object} packet
|
||||
* @event VoiceWebSocket#unknownPacket
|
||||
*/
|
||||
@@ -203,7 +200,7 @@ class VoiceWebSocket extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an interval at which to send a heartbeat packet to the WebSocket
|
||||
* Sets an interval at which to send a heartbeat packet to the WebSocket.
|
||||
* @param {number} interval The interval at which to send a heartbeat packet
|
||||
*/
|
||||
setHeartbeat(interval) {
|
||||
@@ -213,7 +210,7 @@ class VoiceWebSocket extends EventEmitter {
|
||||
}
|
||||
if (this.heartbeatInterval) {
|
||||
/**
|
||||
* Emitted whenver the voice websocket encounters a non-fatal error
|
||||
* Emitted whenver the voice WebSocket encounters a non-fatal error.
|
||||
* @param {string} warn The warning
|
||||
* @event VoiceWebSocket#warn
|
||||
*/
|
||||
@@ -224,7 +221,7 @@ class VoiceWebSocket extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears a heartbeat interval, if one exists
|
||||
* Clears a heartbeat interval, if one exists.
|
||||
*/
|
||||
clearHeartbeat() {
|
||||
if (!this.heartbeatInterval) {
|
||||
@@ -236,7 +233,7 @@ class VoiceWebSocket extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a heartbeat packet
|
||||
* Sends a heartbeat packet.
|
||||
*/
|
||||
sendHeartbeat() {
|
||||
this.sendPacket({ op: Constants.VoiceOPCodes.HEARTBEAT, d: null }).catch(() => {
|
||||
|
||||
Reference in New Issue
Block a user