mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 09:03:29 +01:00
Improve docs a bit
This commit is contained in:
@@ -23,13 +23,13 @@ const WebSocket = (function findWebSocket() {
|
||||
}());
|
||||
|
||||
/**
|
||||
* Abstracts a WebSocket connection with decoding/encoding for the discord gateway
|
||||
* Abstracts a WebSocket connection with decoding/encoding for the Discord gateway.
|
||||
* @private
|
||||
*/
|
||||
class WebSocketConnection extends EventEmitter {
|
||||
/**
|
||||
* @param {WebSocketManager} manager the WebSocket manager
|
||||
* @param {string} gateway Websocket gateway to connect to
|
||||
* @param {WebSocketManager} manager The WebSocket manager
|
||||
* @param {string} gateway WebSocket gateway to connect to
|
||||
*/
|
||||
constructor(manager, gateway) {
|
||||
super();
|
||||
@@ -38,36 +38,43 @@ class WebSocketConnection extends EventEmitter {
|
||||
* @type {WebSocketManager}
|
||||
*/
|
||||
this.manager = manager;
|
||||
|
||||
/**
|
||||
* Client this belongs to
|
||||
* The client this belongs to
|
||||
* @type {Client}
|
||||
*/
|
||||
this.client = manager.client;
|
||||
|
||||
/**
|
||||
* WebSocket connection itself
|
||||
* The WebSocket connection itself
|
||||
* @type {WebSocket}
|
||||
*/
|
||||
this.ws = null;
|
||||
|
||||
/**
|
||||
* Current sequence of the WebSocket
|
||||
* The current sequence of the WebSocket
|
||||
* @type {number}
|
||||
*/
|
||||
this.sequence = -1;
|
||||
|
||||
/**
|
||||
* Current status of the client
|
||||
* The current status of the client
|
||||
* @type {number}
|
||||
*/
|
||||
this.status = Constants.Status.IDLE;
|
||||
|
||||
/**
|
||||
* Packet Manager of the connection
|
||||
* The Packet Manager of the connection
|
||||
* @type {WebSocketPacketManager}
|
||||
*/
|
||||
this.packetManager = new PacketManager(this);
|
||||
|
||||
/**
|
||||
* Last time a ping was sent (a timestamp)
|
||||
* The last time a ping was sent (a timestamp)
|
||||
* @type {number}
|
||||
*/
|
||||
this.lastPingTimestamp = 0;
|
||||
|
||||
/**
|
||||
* Contains the rate limit queue and metadata
|
||||
* @type {Object}
|
||||
@@ -78,13 +85,15 @@ class WebSocketConnection extends EventEmitter {
|
||||
resetTime: -1,
|
||||
};
|
||||
this.connect(gateway);
|
||||
|
||||
/**
|
||||
* Events that are disabled (will not be processed)
|
||||
* @type {Object}
|
||||
*/
|
||||
this.disabledEvents = {};
|
||||
|
||||
/**
|
||||
* Sequence on WebSocket close
|
||||
* The sequence on WebSocket close
|
||||
* @type {number}
|
||||
*/
|
||||
this.closeSequence = 0;
|
||||
@@ -92,7 +101,7 @@ class WebSocketConnection extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Causes the client to be marked as ready and emits the ready event
|
||||
* Causes the client to be marked as ready and emits the ready event.
|
||||
* @returns {void}
|
||||
*/
|
||||
triggerReady() {
|
||||
@@ -106,7 +115,7 @@ class WebSocketConnection extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the client is ready to be marked as ready
|
||||
* Checks whether the client is ready to be marked as ready.
|
||||
* @returns {void}
|
||||
*/
|
||||
checkIfReady() {
|
||||
@@ -132,7 +141,7 @@ class WebSocketConnection extends EventEmitter {
|
||||
|
||||
// Util
|
||||
/**
|
||||
* Emits a debug message
|
||||
* Emits a debug message.
|
||||
* @param {string} message Debug message
|
||||
* @returns {void}
|
||||
*/
|
||||
@@ -142,7 +151,7 @@ class WebSocketConnection extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to serialise data from the WebSocket
|
||||
* Attempts to serialise data from the WebSocket.
|
||||
* @param {string|Object} data Data to unpack
|
||||
* @returns {Object}
|
||||
*/
|
||||
@@ -157,7 +166,7 @@ class WebSocketConnection extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Packs an object ready to be sent
|
||||
* Packs an object ready to be sent.
|
||||
* @param {Object} data Data to pack
|
||||
* @returns {string|Buffer}
|
||||
*/
|
||||
@@ -166,7 +175,7 @@ class WebSocketConnection extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the current WebSocket queue
|
||||
* Processes the current WebSocket queue.
|
||||
*/
|
||||
processQueue() {
|
||||
if (this.ratelimit.remaining === 0) return;
|
||||
@@ -186,7 +195,7 @@ class WebSocketConnection extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends data, bypassing the queue
|
||||
* Sends data, bypassing the queue.
|
||||
* @param {Object} data Packet to send
|
||||
* @returns {void}
|
||||
*/
|
||||
@@ -199,7 +208,7 @@ class WebSocketConnection extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds data to the queue to be sent
|
||||
* Adds data to the queue to be sent.
|
||||
* @param {Object} data Packet to send
|
||||
* @returns {void}
|
||||
*/
|
||||
@@ -213,7 +222,7 @@ class WebSocketConnection extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a connection to a gateway
|
||||
* Creates a connection to a gateway.
|
||||
* @param {string} gateway Gateway to connect to
|
||||
* @param {number} [after=0] How long to wait before connecting
|
||||
* @param {boolean} [force=false] Whether or not to force a new connection even if one already exists
|
||||
@@ -241,7 +250,7 @@ class WebSocketConnection extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys the connection
|
||||
* Destroys the connection.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
destroy() {
|
||||
@@ -259,7 +268,7 @@ class WebSocketConnection extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called whenever a message is received
|
||||
* Called whenever a message is received.
|
||||
* @param {Event} event Event received
|
||||
* @returns {boolean}
|
||||
*/
|
||||
@@ -274,7 +283,7 @@ class WebSocketConnection extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current sequence of the connection
|
||||
* Sets the current sequence of the connection.
|
||||
* @param {number} s New sequence
|
||||
*/
|
||||
setSequence(s) {
|
||||
@@ -282,8 +291,8 @@ class WebSocketConnection extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called whenever a packet is received
|
||||
* @param {Object} packet received packet
|
||||
* Called whenever a packet is received.
|
||||
* @param {Object} packet Received packet
|
||||
* @returns {boolean}
|
||||
*/
|
||||
onPacket(packet) {
|
||||
@@ -311,7 +320,7 @@ class WebSocketConnection extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called whenever a connection is opened to the gateway
|
||||
* Called whenever a connection is opened to the gateway.
|
||||
* @param {Event} event Received open event
|
||||
*/
|
||||
onOpen(event) {
|
||||
@@ -321,7 +330,7 @@ class WebSocketConnection extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Causes a reconnection to the gateway
|
||||
* Causes a reconnection to the gateway.
|
||||
*/
|
||||
reconnect() {
|
||||
this.debug('Attemping to reconnect in 5500ms...');
|
||||
@@ -330,7 +339,7 @@ class WebSocketConnection extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called whenever an error occurs with the WebSocket
|
||||
* Called whenever an error occurs with the WebSocket.
|
||||
* @param {Error} error Error that occurred
|
||||
*/
|
||||
onError(error) {
|
||||
@@ -343,7 +352,7 @@ class WebSocketConnection extends EventEmitter {
|
||||
*/
|
||||
|
||||
/**
|
||||
* Called whenever a connection to the gateway is closed
|
||||
* Called whenever a connection to the gateway is closed.
|
||||
* @param {CloseEvent} event Close event that was received
|
||||
*/
|
||||
onClose(event) {
|
||||
@@ -363,7 +372,7 @@ class WebSocketConnection extends EventEmitter {
|
||||
|
||||
// Heartbeat
|
||||
/**
|
||||
* Acknowledges a heartbeat
|
||||
* Acknowledges a heartbeat.
|
||||
*/
|
||||
ackHeartbeat() {
|
||||
this.debug(`Heartbeat acknowledged, latency of ${Date.now() - this.lastPingTimestamp}ms`);
|
||||
@@ -372,8 +381,8 @@ class WebSocketConnection extends EventEmitter {
|
||||
|
||||
/**
|
||||
* Sends a heartbeat or sets an interval for sending heartbeats.
|
||||
* @param {number} [time] If -1, clears the interval, any other number sets an interval.
|
||||
* If no value is given, a heartbeat will be sent instantly.
|
||||
* @param {number} [time] If -1, clears the interval, any other number sets an interval
|
||||
* If no value is given, a heartbeat will be sent instantly
|
||||
*/
|
||||
heartbeat(time) {
|
||||
if (!isNaN(time)) {
|
||||
@@ -397,7 +406,7 @@ class WebSocketConnection extends EventEmitter {
|
||||
|
||||
// Identification
|
||||
/**
|
||||
* Identifies the client on a connection
|
||||
* Identifies the client on a connection.
|
||||
* @param {number} [after] How long to wait before identifying
|
||||
* @returns {void}
|
||||
*/
|
||||
@@ -407,7 +416,7 @@ class WebSocketConnection extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Identifies as a new connection on the gateway
|
||||
* Identifies as a new connection on the gateway.
|
||||
* @returns {void}
|
||||
*/
|
||||
identifyNew() {
|
||||
@@ -428,7 +437,7 @@ class WebSocketConnection extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Resumes a session on the gateway
|
||||
* Resumes a session on the gateway.
|
||||
* @returns {void}
|
||||
*/
|
||||
identifyResume() {
|
||||
@@ -452,7 +461,7 @@ class WebSocketConnection extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Encoding the WebSocket connections will use
|
||||
* Encoding the WebSocket connections will use.
|
||||
* @type {string}
|
||||
*/
|
||||
WebSocketConnection.ENCODING = erlpack ? 'etf' : 'json';
|
||||
|
||||
@@ -3,20 +3,20 @@ const Constants = require('../../util/Constants');
|
||||
const WebSocketConnection = require('./WebSocketConnection');
|
||||
|
||||
/**
|
||||
* WebSocket Manager of the Client
|
||||
* WebSocket Manager of the client
|
||||
* @private
|
||||
*/
|
||||
class WebSocketManager extends EventEmitter {
|
||||
constructor(client) {
|
||||
super();
|
||||
/**
|
||||
* Client that instantiated this WebSocketManager
|
||||
* The client that instantiated this WebSocketManager
|
||||
* @type {Client}
|
||||
*/
|
||||
this.client = client;
|
||||
|
||||
/**
|
||||
* WebSocket connection of this manager
|
||||
* The WebSocket connection of this manager
|
||||
* @type {?WebSocketConnection}
|
||||
*/
|
||||
this.connection = null;
|
||||
@@ -32,7 +32,7 @@ class WebSocketManager extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Emits a debug event
|
||||
* Emits a debug event.
|
||||
* @param {string} message Debug message
|
||||
* @returns {void}
|
||||
*/
|
||||
@@ -41,7 +41,7 @@ class WebSocketManager extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy the client
|
||||
* Destroy the client.
|
||||
* @returns {void} Whether or not destruction was successful
|
||||
*/
|
||||
destroy() {
|
||||
@@ -53,7 +53,7 @@ class WebSocketManager extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a packet on the available WebSocket
|
||||
* Send a packet on the available WebSocket.
|
||||
* @param {Object} packet Packet to send
|
||||
* @returns {void}
|
||||
*/
|
||||
@@ -66,7 +66,7 @@ class WebSocketManager extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Connects the client to a gateway
|
||||
* Connects the client to a gateway.
|
||||
* @param {string} gateway Gateway to connect to
|
||||
* @returns {boolean}
|
||||
*/
|
||||
|
||||
@@ -24,7 +24,7 @@ class GuildMembersChunkHandler extends AbstractHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
* Emitted whenever a chunk of guild members is received (all members come from the same guild)
|
||||
* Emitted whenever a chunk of guild members is received (all members come from the same guild).
|
||||
* @event Client#guildMembersChunk
|
||||
* @param {Collection<Snowflake, GuildMember>} members The members in the chunk
|
||||
* @param {Guild} guild The guild related to the member chunk
|
||||
|
||||
@@ -11,7 +11,7 @@ class MessageCreateHandler extends AbstractHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
* Emitted whenever a message is created
|
||||
* Emitted whenever a message is created.
|
||||
* @event Client#message
|
||||
* @param {Message} message The created message
|
||||
*/
|
||||
|
||||
@@ -11,7 +11,7 @@ class MessageDeleteHandler extends AbstractHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
* Emitted whenever a message is deleted
|
||||
* Emitted whenever a message is deleted.
|
||||
* @event Client#messageDelete
|
||||
* @param {Message} message The deleted message
|
||||
*/
|
||||
|
||||
@@ -9,7 +9,7 @@ class MessageDeleteBulkHandler extends AbstractHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
* Emitted whenever messages are deleted in bulk
|
||||
* Emitted whenever messages are deleted in bulk.
|
||||
* @event Client#messageDeleteBulk
|
||||
* @param {Collection<Snowflake, Message>} messages The deleted messages, mapped by their ID
|
||||
*/
|
||||
|
||||
@@ -68,7 +68,7 @@ class PresenceUpdateHandler extends AbstractHandler {
|
||||
*/
|
||||
|
||||
/**
|
||||
* Emitted whenever a member becomes available in a large guild
|
||||
* Emitted whenever a member becomes available in a large guild.
|
||||
* @event Client#guildMemberAvailable
|
||||
* @param {GuildMember} member The member that became available
|
||||
*/
|
||||
|
||||
@@ -20,9 +20,9 @@ class ResumedHandler extends AbstractHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
* Emitted whenever a websocket resumes
|
||||
* Emitted whenever a WebSocket resumes.
|
||||
* @event Client#resume
|
||||
* @param {number} replayed Number of events that were replayed
|
||||
* @param {number} replayed The number of events that were replayed
|
||||
*/
|
||||
|
||||
module.exports = ResumedHandler;
|
||||
|
||||
@@ -52,14 +52,14 @@ function tooLate(channel, user) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Emitted whenever a user starts typing in a channel
|
||||
* Emitted whenever a user starts typing in a channel.
|
||||
* @event Client#typingStart
|
||||
* @param {Channel} channel The channel the user started typing in
|
||||
* @param {User} user The user that started typing
|
||||
*/
|
||||
|
||||
/**
|
||||
* Emitted whenever a user stops typing in a channel
|
||||
* Emitted whenever a user stops typing in a channel.
|
||||
* @event Client#typingStop
|
||||
* @param {Channel} channel The channel the user stopped typing in
|
||||
* @param {User} user The user that stopped typing
|
||||
|
||||
@@ -10,7 +10,7 @@ class UserSettingsUpdateHandler extends AbstractHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
* Emitted when the client user's settings update
|
||||
* Emitted when the client user's settings update.
|
||||
* @event Client#clientUserSettingsUpdate
|
||||
* @param {ClientUserSettings} clientUserSettings The new client user settings
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user