mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 00:53:31 +01:00
Improve docs a bit
This commit is contained in:
@@ -347,7 +347,7 @@ class Client extends EventEmitter {
|
||||
* Sweeps all text-based channels' messages and removes the ones older than the max message lifetime.
|
||||
* If the message has been edited, the time of the edit is used rather than the time of the original message.
|
||||
* @param {number} [lifetime=this.options.messageCacheLifetime] Messages that are older than this (in seconds)
|
||||
* will be removed from the caches. The default is based on {@link ClientOptions#messageCacheLifetime}.
|
||||
* will be removed from the caches. The default is based on {@link ClientOptions#messageCacheLifetime}
|
||||
* @returns {number} Amount of messages that were removed from the caches,
|
||||
* or -1 if the message cache lifetime is unlimited
|
||||
*/
|
||||
@@ -535,13 +535,13 @@ class Client extends EventEmitter {
|
||||
module.exports = Client;
|
||||
|
||||
/**
|
||||
* Emitted for general warnings
|
||||
* Emitted for general warnings.
|
||||
* @event Client#warn
|
||||
* @param {string} info The warning
|
||||
*/
|
||||
|
||||
/**
|
||||
* Emitted for general debugging information
|
||||
* Emitted for general debugging information.
|
||||
* @event Client#debug
|
||||
* @param {string} info The debug information
|
||||
*/
|
||||
|
||||
@@ -36,7 +36,7 @@ class ClientDataResolver {
|
||||
*/
|
||||
|
||||
/**
|
||||
* Resolves a UserResolvable to a User object
|
||||
* Resolves a UserResolvable to a User object.
|
||||
* @param {UserResolvable} user The UserResolvable to identify
|
||||
* @returns {?User}
|
||||
*/
|
||||
@@ -50,7 +50,7 @@ class ClientDataResolver {
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves a UserResolvable to a user ID string
|
||||
* Resolves a UserResolvable to a user ID string.
|
||||
* @param {UserResolvable} user The UserResolvable to identify
|
||||
* @returns {?Snowflake}
|
||||
*/
|
||||
@@ -70,7 +70,7 @@ class ClientDataResolver {
|
||||
*/
|
||||
|
||||
/**
|
||||
* Resolves a GuildResolvable to a Guild object
|
||||
* Resolves a GuildResolvable to a Guild object.
|
||||
* @param {GuildResolvable} guild The GuildResolvable to identify
|
||||
* @returns {?Guild}
|
||||
*/
|
||||
@@ -88,7 +88,7 @@ class ClientDataResolver {
|
||||
*/
|
||||
|
||||
/**
|
||||
* Resolves a GuildMemberResolvable to a GuildMember object
|
||||
* Resolves a GuildMemberResolvable to a GuildMember object.
|
||||
* @param {GuildResolvable} guild The guild that the member is part of
|
||||
* @param {UserResolvable} user The user that is part of the guild
|
||||
* @returns {?GuildMember}
|
||||
@@ -111,7 +111,7 @@ class ClientDataResolver {
|
||||
*/
|
||||
|
||||
/**
|
||||
* Resolves a ChannelResolvable to a Channel object
|
||||
* Resolves a ChannelResolvable to a Channel object.
|
||||
* @param {ChannelResolvable} channel The channel resolvable to resolve
|
||||
* @returns {?Channel}
|
||||
*/
|
||||
@@ -124,7 +124,7 @@ class ClientDataResolver {
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves a ChannelResolvable to a channel ID
|
||||
* Resolves a ChannelResolvable to a channel ID.
|
||||
* @param {ChannelResolvable} channel The channel resolvable to resolve
|
||||
* @returns {?Snowflake}
|
||||
*/
|
||||
@@ -144,7 +144,7 @@ class ClientDataResolver {
|
||||
*/
|
||||
|
||||
/**
|
||||
* Resolves InviteResolvable to an invite code
|
||||
* Resolves InviteResolvable to an invite code.
|
||||
* @param {InviteResolvable} data The invite resolvable to resolve
|
||||
* @returns {string}
|
||||
*/
|
||||
@@ -164,7 +164,7 @@ class ClientDataResolver {
|
||||
*/
|
||||
|
||||
/**
|
||||
* Resolves a StringResolvable to a string
|
||||
* Resolves a StringResolvable to a string.
|
||||
* @param {StringResolvable} data The string resolvable to resolve
|
||||
* @returns {string}
|
||||
*/
|
||||
@@ -182,7 +182,7 @@ class ClientDataResolver {
|
||||
*/
|
||||
|
||||
/**
|
||||
* Resolves a Base64Resolvable to a Base 64 image
|
||||
* Resolves a Base64Resolvable to a Base 64 image.
|
||||
* @param {Base64Resolvable} data The base 64 resolvable you want to resolve
|
||||
* @returns {?string}
|
||||
*/
|
||||
@@ -200,7 +200,7 @@ class ClientDataResolver {
|
||||
*/
|
||||
|
||||
/**
|
||||
* Resolves a BufferResolvable to a Buffer
|
||||
* Resolves a BufferResolvable to a Buffer.
|
||||
* @param {BufferResolvable} resource The buffer resolvable to resolve
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
@@ -244,7 +244,7 @@ class ClientDataResolver {
|
||||
*/
|
||||
|
||||
/**
|
||||
* Resolves an EmojiResolvable to an emoji identifier
|
||||
* Resolves an EmojiResolvable to an emoji identifier.
|
||||
* @param {EmojiIdentifierResolvable} emoji The emoji resolvable to resolve
|
||||
* @returns {?string}
|
||||
*/
|
||||
@@ -295,7 +295,7 @@ class ClientDataResolver {
|
||||
*/
|
||||
|
||||
/**
|
||||
* Resolves a ColorResolvable into a color number
|
||||
* Resolves a ColorResolvable into a color number.
|
||||
* @param {ColorResolvable} color Color to resolve
|
||||
* @returns {number} A color
|
||||
*/
|
||||
|
||||
@@ -2,19 +2,19 @@ const Constants = require('../util/Constants');
|
||||
const WebSocketConnection = require('./websocket/WebSocketConnection');
|
||||
|
||||
/**
|
||||
* Manages the State and Background Tasks of the Client
|
||||
* Manages the state and background tasks of the client.
|
||||
* @private
|
||||
*/
|
||||
class ClientManager {
|
||||
constructor(client) {
|
||||
/**
|
||||
* The Client that instantiated this Manager
|
||||
* The client that instantiated this Manager
|
||||
* @type {Client}
|
||||
*/
|
||||
this.client = client;
|
||||
|
||||
/**
|
||||
* The heartbeat interval, null if not yet set
|
||||
* The heartbeat interval
|
||||
* @type {?number}
|
||||
*/
|
||||
this.heartbeatInterval = null;
|
||||
@@ -29,7 +29,7 @@ class ClientManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Connects the Client to the WebSocket
|
||||
* Connects the client to the WebSocket.
|
||||
* @param {string} token The authorization token
|
||||
* @param {Function} resolve Function to run when connection is successful
|
||||
* @param {Function} reject Function to run when connection fails
|
||||
|
||||
@@ -5,7 +5,7 @@ const Constants = require('../util/Constants');
|
||||
const Util = require('../util/Util');
|
||||
|
||||
/**
|
||||
* The Webhook Client
|
||||
* The webhook client.
|
||||
* @extends {Webhook}
|
||||
*/
|
||||
class WebhookClient extends Webhook {
|
||||
@@ -14,7 +14,7 @@ class WebhookClient extends Webhook {
|
||||
* @param {string} token Token of the webhook
|
||||
* @param {ClientOptions} [options] Options for the client
|
||||
* @example
|
||||
* // create a new webhook and send a message
|
||||
* // Create a new webhook and send a message
|
||||
* const hook = new Discord.WebhookClient('1234', 'abcdef');
|
||||
* hook.sendMessage('This will send a message').catch(console.error);
|
||||
*/
|
||||
|
||||
@@ -47,7 +47,7 @@ class GuildDeleteAction extends Action {
|
||||
/**
|
||||
* Emitted whenever a guild becomes unavailable, likely due to a server outage.
|
||||
* @event Client#guildUnavailable
|
||||
* @param {Guild} guild The guild that has become unavailable.
|
||||
* @param {Guild} guild The guild that has become unavailable
|
||||
*/
|
||||
|
||||
module.exports = GuildDeleteAction;
|
||||
|
||||
@@ -9,9 +9,9 @@ class GuildEmojiCreateAction extends Action {
|
||||
}
|
||||
|
||||
/**
|
||||
* Emitted whenever a custom emoji is created in a guild
|
||||
* Emitted whenever a custom emoji is created in a guild.
|
||||
* @event Client#emojiCreate
|
||||
* @param {Emoji} emoji The emoji that was created.
|
||||
* @param {Emoji} emoji The emoji that was created
|
||||
*/
|
||||
|
||||
module.exports = GuildEmojiCreateAction;
|
||||
|
||||
@@ -9,9 +9,9 @@ class GuildEmojiDeleteAction extends Action {
|
||||
}
|
||||
|
||||
/**
|
||||
* Emitted whenever a custom guild emoji is deleted
|
||||
* Emitted whenever a custom guild emoji is deleted.
|
||||
* @event Client#emojiDelete
|
||||
* @param {Emoji} emoji The emoji that was deleted.
|
||||
* @param {Emoji} emoji The emoji that was deleted
|
||||
*/
|
||||
|
||||
module.exports = GuildEmojiDeleteAction;
|
||||
|
||||
@@ -8,7 +8,7 @@ class GuildEmojiUpdateAction extends Action {
|
||||
}
|
||||
|
||||
/**
|
||||
* Emitted whenever a custom guild emoji is updated
|
||||
* Emitted whenever a custom guild emoji is updated.
|
||||
* @event Client#emojiUpdate
|
||||
* @param {Emoji} oldEmoji The old emoji
|
||||
* @param {Emoji} newEmoji The new emoji
|
||||
|
||||
@@ -34,7 +34,7 @@ class GuildMemberRemoveAction extends Action {
|
||||
/**
|
||||
* Emitted whenever a member leaves a guild, or is kicked.
|
||||
* @event Client#guildMemberRemove
|
||||
* @param {GuildMember} member The member that has left/been kicked from the guild.
|
||||
* @param {GuildMember} member The member that has left/been kicked from the guild
|
||||
*/
|
||||
|
||||
module.exports = GuildMemberRemoveAction;
|
||||
|
||||
@@ -20,7 +20,7 @@ class GuildRoleCreate extends Action {
|
||||
/**
|
||||
* Emitted whenever a role is created.
|
||||
* @event Client#roleCreate
|
||||
* @param {Role} role The role that was created.
|
||||
* @param {Role} role The role that was created
|
||||
*/
|
||||
|
||||
module.exports = GuildRoleCreate;
|
||||
|
||||
@@ -35,7 +35,7 @@ class GuildRoleDeleteAction extends Action {
|
||||
/**
|
||||
* Emitted whenever a guild role is deleted.
|
||||
* @event Client#roleDelete
|
||||
* @param {Role} role The role that was deleted.
|
||||
* @param {Role} role The role that was deleted
|
||||
*/
|
||||
|
||||
module.exports = GuildRoleDeleteAction;
|
||||
|
||||
@@ -34,8 +34,8 @@ class GuildRoleUpdateAction extends Action {
|
||||
/**
|
||||
* Emitted whenever a guild role is updated.
|
||||
* @event Client#roleUpdate
|
||||
* @param {Role} oldRole The role before the update.
|
||||
* @param {Role} newRole The role after the update.
|
||||
* @param {Role} oldRole The role before the update
|
||||
* @param {Role} newRole The role after the update
|
||||
*/
|
||||
|
||||
module.exports = GuildRoleUpdateAction;
|
||||
|
||||
@@ -27,8 +27,8 @@ class GuildUpdateAction extends Action {
|
||||
/**
|
||||
* Emitted whenever a guild is updated - e.g. name change.
|
||||
* @event Client#guildUpdate
|
||||
* @param {Guild} oldGuild The guild before the update.
|
||||
* @param {Guild} newGuild The guild after the update.
|
||||
* @param {Guild} oldGuild The guild before the update
|
||||
* @param {Guild} newGuild The guild after the update
|
||||
*/
|
||||
|
||||
module.exports = GuildUpdateAction;
|
||||
|
||||
@@ -30,8 +30,8 @@ class MessageReactionAdd extends Action {
|
||||
/**
|
||||
* Emitted whenever a reaction is added to a message.
|
||||
* @event Client#messageReactionAdd
|
||||
* @param {MessageReaction} messageReaction The reaction object.
|
||||
* @param {User} user The user that applied the emoji or reaction emoji.
|
||||
* @param {MessageReaction} messageReaction The reaction object
|
||||
* @param {User} user The user that applied the emoji or reaction emoji
|
||||
*/
|
||||
|
||||
module.exports = MessageReactionAdd;
|
||||
|
||||
@@ -30,8 +30,8 @@ class MessageReactionRemove extends Action {
|
||||
/**
|
||||
* Emitted whenever a reaction is removed from a message.
|
||||
* @event Client#messageReactionRemove
|
||||
* @param {MessageReaction} messageReaction The reaction object.
|
||||
* @param {User} user The user that removed the emoji or reaction emoji.
|
||||
* @param {MessageReaction} messageReaction The reaction object
|
||||
* @param {User} user The user that removed the emoji or reaction emoji
|
||||
*/
|
||||
|
||||
module.exports = MessageReactionRemove;
|
||||
|
||||
@@ -19,7 +19,7 @@ class MessageReactionRemoveAll extends Action {
|
||||
/**
|
||||
* Emitted whenever all reactions are removed from a message.
|
||||
* @event Client#messageReactionRemoveAll
|
||||
* @param {Message} message The message the reactions were removed from.
|
||||
* @param {Message} message The message the reactions were removed from
|
||||
*/
|
||||
|
||||
module.exports = MessageReactionRemoveAll;
|
||||
|
||||
@@ -33,8 +33,8 @@ class MessageUpdateAction extends Action {
|
||||
/**
|
||||
* Emitted whenever a message is updated - e.g. embed or content change.
|
||||
* @event Client#messageUpdate
|
||||
* @param {Message} oldMessage The message before the update.
|
||||
* @param {Message} newMessage The message after the update.
|
||||
* @param {Message} oldMessage The message before the update
|
||||
* @param {Message} newMessage The message after the update
|
||||
*/
|
||||
|
||||
module.exports = MessageUpdateAction;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Represents an error from the Discord API
|
||||
* Represents an error from the Discord API.
|
||||
*/
|
||||
class DiscordAPIError extends Error {
|
||||
constructor(error) {
|
||||
@@ -16,7 +16,7 @@ class DiscordAPIError extends Error {
|
||||
}
|
||||
|
||||
/**
|
||||
* Flattens an errors object returned from the API into an array
|
||||
* Flattens an errors object returned from the API into an array.
|
||||
* @param {Object} obj Discord errors object
|
||||
* @param {string} [key] idklol
|
||||
* @returns {string[]}
|
||||
|
||||
@@ -14,14 +14,14 @@ class RequestHandler {
|
||||
this.restManager = restManager;
|
||||
|
||||
/**
|
||||
* A list of requests that have yet to be processed.
|
||||
* A list of requests that have yet to be processed
|
||||
* @type {APIRequest[]}
|
||||
*/
|
||||
this.queue = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not the client is being rate limited on every endpoint.
|
||||
* Whether or not the client is being rate limited on every endpoint
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
*/
|
||||
@@ -34,7 +34,7 @@ class RequestHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
* Push a new API request into this bucket
|
||||
* Push a new API request into this bucket.
|
||||
* @param {APIRequest} request The new request to push into the queue
|
||||
*/
|
||||
push(request) {
|
||||
@@ -42,7 +42,7 @@ class RequestHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to get this RequestHandler to process its current queue
|
||||
* Attempts to get this RequestHandler to process its current queue.
|
||||
*/
|
||||
handle() {} // eslint-disable-line no-empty-function
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ class SequentialRequestHandler extends RequestHandler {
|
||||
|
||||
/**
|
||||
* The time difference between Discord's Dates and the local computer's Dates. A positive number means the local
|
||||
* computer's time is ahead of Discord's.
|
||||
* computer's time is ahead of Discord's
|
||||
* @type {number}
|
||||
*/
|
||||
this.timeDifference = 0;
|
||||
@@ -42,7 +42,7 @@ class SequentialRequestHandler extends RequestHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a request then resolves a promise to indicate its readiness for a new request
|
||||
* Performs a request then resolves a promise to indicate its readiness for a new request.
|
||||
* @param {APIRequest} item The item to execute
|
||||
* @returns {Promise<?Object|Error>}
|
||||
*/
|
||||
|
||||
@@ -2,7 +2,7 @@ const Collection = require('../../util/Collection');
|
||||
const VoiceConnection = require('./VoiceConnection');
|
||||
|
||||
/**
|
||||
* Manages all the voice stuff for the Client
|
||||
* Manages all the voice stuff for the client.
|
||||
* @private
|
||||
*/
|
||||
class ClientVoiceManager {
|
||||
@@ -37,7 +37,7 @@ class ClientVoiceManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up a request to join a voice channel
|
||||
* Sets up a request to join a voice channel.
|
||||
* @param {VoiceChannel} channel The voice channel to join
|
||||
* @returns {Promise<VoiceConnection>}
|
||||
*/
|
||||
|
||||
@@ -64,7 +64,7 @@ class VoiceBroadcast extends VolumeInterface {
|
||||
const volume = old || dispatcher.volume;
|
||||
|
||||
/**
|
||||
* Emitted whenever a stream dispatcher unsubscribes from the broadcast
|
||||
* Emitted whenever a stream dispatcher unsubscribes from the broadcast.
|
||||
* @event VoiceBroadcast#unsubscribe
|
||||
* @param {StreamDispatcher} dispatcher The unsubscribed dispatcher
|
||||
*/
|
||||
@@ -98,7 +98,7 @@ class VoiceBroadcast extends VolumeInterface {
|
||||
this._dispatchers.get(n).add(dispatcher);
|
||||
});
|
||||
/**
|
||||
* Emitted whenever a stream dispatcher subscribes to the broadcast
|
||||
* Emitted whenever a stream dispatcher subscribes to the broadcast.
|
||||
* @event VoiceBroadcast#subscribe
|
||||
* @param {StreamDispatcher} dispatcher The subscribed dispatcher
|
||||
*/
|
||||
@@ -115,7 +115,7 @@ class VoiceBroadcast extends VolumeInterface {
|
||||
}
|
||||
|
||||
/**
|
||||
* Plays any audio stream across the broadcast
|
||||
* Plays any audio stream across the broadcast.
|
||||
* @param {ReadableStream} stream The audio stream to play
|
||||
* @param {StreamOptions} [options] Options for playing the stream
|
||||
* @returns {VoiceBroadcast}
|
||||
@@ -169,21 +169,21 @@ class VoiceBroadcast extends VolumeInterface {
|
||||
ffmpegArguments: ffmpegArguments.concat(['-ss', String(options.seek)]),
|
||||
});
|
||||
/**
|
||||
* Emitted whenever an error occurs
|
||||
* Emitted whenever an error occurs.
|
||||
* @event VoiceBroadcast#error
|
||||
* @param {Error} error the error that occurred
|
||||
* @param {Error} error The error that occurred
|
||||
*/
|
||||
transcoder.once('error', e => {
|
||||
if (this.listenerCount('error') > 0) this.emit('error', e);
|
||||
/**
|
||||
* Emitted whenever the VoiceBroadcast has any warnings
|
||||
* Emitted whenever the VoiceBroadcast has any warnings.
|
||||
* @event VoiceBroadcast#warn
|
||||
* @param {string|Error} warning the warning that was raised
|
||||
* @param {string|Error} warning The warning that was raised
|
||||
*/
|
||||
else this.emit('warn', e);
|
||||
});
|
||||
/**
|
||||
* Emitted once the broadcast (the audio stream) ends
|
||||
* Emitted once the broadcast (the audio stream) ends.
|
||||
* @event VoiceBroadcast#end
|
||||
*/
|
||||
transcoder.once('end', () => this.killCurrentTranscoder());
|
||||
@@ -197,7 +197,7 @@ class VoiceBroadcast extends VolumeInterface {
|
||||
|
||||
/**
|
||||
* Plays a stream of 16-bit signed stereo PCM at 48KHz.
|
||||
* @param {ReadableStream} stream The audio stream to play.
|
||||
* @param {ReadableStream} stream The audio stream to play
|
||||
* @param {StreamOptions} [options] Options for playing the stream
|
||||
* @returns {VoiceBroadcast}
|
||||
*/
|
||||
@@ -227,7 +227,7 @@ class VoiceBroadcast extends VolumeInterface {
|
||||
|
||||
/**
|
||||
* Play an arbitrary input that can be [handled by ffmpeg](https://ffmpeg.org/ffmpeg-protocols.html#Description)
|
||||
* @param {string} input the arbitrary input
|
||||
* @param {string} input The arbitrary input
|
||||
* @param {StreamOptions} [options] Options for playing the stream
|
||||
* @returns {VoiceBroadcast}
|
||||
*/
|
||||
@@ -239,7 +239,7 @@ class VoiceBroadcast extends VolumeInterface {
|
||||
}
|
||||
|
||||
/**
|
||||
* Pauses the entire broadcast - all dispatchers also pause
|
||||
* Pauses the entire broadcast - all dispatchers also pause.
|
||||
*/
|
||||
pause() {
|
||||
this.paused = true;
|
||||
@@ -251,7 +251,7 @@ class VoiceBroadcast extends VolumeInterface {
|
||||
}
|
||||
|
||||
/**
|
||||
* Resumes the entire broadcast - all dispatchers also resume
|
||||
* Resumes the entire broadcast - all dispatchers also resume.
|
||||
*/
|
||||
resume() {
|
||||
this.paused = false;
|
||||
@@ -351,7 +351,7 @@ class VoiceBroadcast extends VolumeInterface {
|
||||
}
|
||||
|
||||
/**
|
||||
* End the current broadcast, all subscribed dispatchers will also end
|
||||
* End the current broadcast, all subscribed dispatchers will also end.
|
||||
*/
|
||||
destroy() {
|
||||
this.end();
|
||||
|
||||
@@ -83,18 +83,18 @@ class VoiceConnection extends EventEmitter {
|
||||
|
||||
this.player.on('debug', m => {
|
||||
/**
|
||||
* Debug info from the connection
|
||||
* Debug info from the connection.
|
||||
* @event VoiceConnection#debug
|
||||
* @param {string} message the debug message
|
||||
* @param {string} message The debug message
|
||||
*/
|
||||
this.emit('debug', `audio player - ${m}`);
|
||||
});
|
||||
|
||||
this.player.on('error', e => {
|
||||
/**
|
||||
* Warning info from the connection
|
||||
* Warning info from the connection.
|
||||
* @event VoiceConnection#warn
|
||||
* @param {string|Error} warning the warning
|
||||
* @param {string|Error} warning The warning
|
||||
*/
|
||||
this.emit('warn', e);
|
||||
});
|
||||
@@ -126,8 +126,8 @@ class VoiceConnection extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether the voice connection should display as "speaking" or not
|
||||
* @param {boolean} value whether or not to speak
|
||||
* Sets whether the voice connection should display as "speaking" or not.
|
||||
* @param {boolean} value Whether or not to speak
|
||||
* @private
|
||||
*/
|
||||
setSpeaking(value) {
|
||||
@@ -145,7 +145,7 @@ class VoiceConnection extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a request to the main gateway to join a voice channel
|
||||
* Sends a request to the main gateway to join a voice channel.
|
||||
* @param {Object} [options] The options to provide
|
||||
*/
|
||||
sendVoiceStateUpdate(options = {}) {
|
||||
@@ -163,7 +163,7 @@ class VoiceConnection extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the token and endpoint required to connect to the the voice servers
|
||||
* Set the token and endpoint required to connect to the the voice servers.
|
||||
* @param {string} token The voice token
|
||||
* @param {string} endpoint The voice endpoint
|
||||
* @returns {void}
|
||||
@@ -195,7 +195,7 @@ class VoiceConnection extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Session ID for the connection
|
||||
* Sets the Session ID for the connection.
|
||||
* @param {string} sessionID The voice session ID
|
||||
*/
|
||||
setSessionID(sessionID) {
|
||||
@@ -210,7 +210,7 @@ class VoiceConnection extends EventEmitter {
|
||||
} else if (sessionID !== this.authentication.sessionID) {
|
||||
this.authentication.sessionID = sessionID;
|
||||
/**
|
||||
* Emitted when a new session ID is received
|
||||
* Emitted when a new session ID is received.
|
||||
* @event VoiceConnection#newSession
|
||||
* @private
|
||||
*/
|
||||
@@ -219,7 +219,7 @@ class VoiceConnection extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the voice connection is authenticated
|
||||
* Checks whether the voice connection is authenticated.
|
||||
* @private
|
||||
*/
|
||||
checkAuthenticated() {
|
||||
@@ -229,7 +229,7 @@ class VoiceConnection extends EventEmitter {
|
||||
clearTimeout(this.connectTimeout);
|
||||
this.status = Constants.VoiceStatus.CONNECTING;
|
||||
/**
|
||||
* Emitted when we successfully initiate a voice connection
|
||||
* Emitted when we successfully initiate a voice connection.
|
||||
* @event VoiceConnection#authenticated
|
||||
*/
|
||||
this.emit('authenticated');
|
||||
@@ -238,7 +238,7 @@ class VoiceConnection extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked when we fail to initiate a voice connection
|
||||
* Invoked when we fail to initiate a voice connection.
|
||||
* @param {string} reason The reason for failure
|
||||
* @private
|
||||
*/
|
||||
@@ -247,7 +247,7 @@ class VoiceConnection extends EventEmitter {
|
||||
this.status = Constants.VoiceStatus.DISCONNECTED;
|
||||
if (this.status === Constants.VoiceStatus.AUTHENTICATING) {
|
||||
/**
|
||||
* Emitted when we fail to initiate a voice connection
|
||||
* Emitted when we fail to initiate a voice connection.
|
||||
* @event VoiceConnection#failed
|
||||
* @param {Error} error The encountered error
|
||||
*/
|
||||
@@ -258,7 +258,7 @@ class VoiceConnection extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Move to a different voice channel in the same guild
|
||||
* Move to a different voice channel in the same guild.
|
||||
* @param {VoiceChannel} channel The channel to move to
|
||||
* @private
|
||||
*/
|
||||
@@ -268,7 +268,7 @@ class VoiceConnection extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to authenticate to the voice server
|
||||
* Attempts to authenticate to the voice server.
|
||||
* @private
|
||||
*/
|
||||
authenticate() {
|
||||
@@ -278,7 +278,7 @@ class VoiceConnection extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to reconnect to the voice server (typically after a region change)
|
||||
* Attempts to reconnect to the voice server (typically after a region change).
|
||||
* @param {string} token The voice token
|
||||
* @param {string} endpoint The voice endpoint
|
||||
* @private
|
||||
@@ -289,7 +289,7 @@ class VoiceConnection extends EventEmitter {
|
||||
|
||||
this.status = Constants.VoiceStatus.RECONNECTING;
|
||||
/**
|
||||
* Emitted when the voice connection is reconnecting (typically after a region change)
|
||||
* Emitted when the voice connection is reconnecting (typically after a region change).
|
||||
* @event VoiceConnection#reconnecting
|
||||
*/
|
||||
this.emit('reconnecting');
|
||||
@@ -308,14 +308,14 @@ class VoiceConnection extends EventEmitter {
|
||||
this.cleanup();
|
||||
this.status = Constants.VoiceStatus.DISCONNECTED;
|
||||
/**
|
||||
* Emitted when the voice connection disconnects
|
||||
* Emitted when the voice connection disconnects.
|
||||
* @event VoiceConnection#disconnect
|
||||
*/
|
||||
this.emit('disconnect');
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans up after disconnect
|
||||
* Cleans up after disconnect.
|
||||
* @private
|
||||
*/
|
||||
cleanup() {
|
||||
@@ -335,7 +335,7 @@ class VoiceConnection extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect the voice connection
|
||||
* Connect the voice connection.
|
||||
* @private
|
||||
*/
|
||||
connect() {
|
||||
@@ -360,7 +360,7 @@ class VoiceConnection extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked when the voice websocket is ready
|
||||
* Invoked when the voice websocket is ready.
|
||||
* @param {Object} data The received data
|
||||
* @private
|
||||
*/
|
||||
@@ -381,7 +381,7 @@ class VoiceConnection extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked when a session description is received
|
||||
* Invoked when a session description is received.
|
||||
* @param {string} mode The encryption mode
|
||||
* @param {string} secret The secret key
|
||||
* @private
|
||||
@@ -400,7 +400,7 @@ class VoiceConnection extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked when a speaking event is received
|
||||
* Invoked when a speaking event is received.
|
||||
* @param {Object} data The received data
|
||||
* @private
|
||||
*/
|
||||
@@ -414,7 +414,7 @@ class VoiceConnection extends EventEmitter {
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Emitted whenever a user starts/stops speaking
|
||||
* Emitted whenever a user starts/stops speaking.
|
||||
* @event VoiceConnection#speaking
|
||||
* @param {User} user The user that has started/stopped speaking
|
||||
* @param {boolean} speaking Whether or not the user is speaking
|
||||
@@ -500,8 +500,8 @@ class VoiceConnection extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Plays a voice broadcast
|
||||
* @param {VoiceBroadcast} broadcast the broadcast to play
|
||||
* Plays a voice broadcast.
|
||||
* @param {VoiceBroadcast} broadcast The broadcast to play
|
||||
* @returns {StreamDispatcher}
|
||||
* @example
|
||||
* // Play a broadcast
|
||||
|
||||
@@ -4,7 +4,7 @@ const Constants = require('../../util/Constants');
|
||||
const EventEmitter = require('events').EventEmitter;
|
||||
|
||||
/**
|
||||
* Represents a UDP Client for a Voice Connection
|
||||
* Represents a UDP client for a Voice Connection.
|
||||
* @extends {EventEmitter}
|
||||
* @private
|
||||
*/
|
||||
@@ -25,7 +25,7 @@ class VoiceConnectionUDPClient extends EventEmitter {
|
||||
this.socket = null;
|
||||
|
||||
/**
|
||||
* The address of the discord voice server
|
||||
* The address of the Discord voice server
|
||||
* @type {?string}
|
||||
*/
|
||||
this.discordAddress = null;
|
||||
@@ -57,7 +57,7 @@ class VoiceConnectionUDPClient extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* The port of the discord voice server
|
||||
* The port of the Discord voice server
|
||||
* @type {number}
|
||||
* @readonly
|
||||
*/
|
||||
@@ -66,7 +66,7 @@ class VoiceConnectionUDPClient extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to resolve the voice server endpoint to an address
|
||||
* Tries to resolve the voice server endpoint to an address.
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
findEndpointAddress() {
|
||||
@@ -83,7 +83,7 @@ class VoiceConnectionUDPClient extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a packet to the UDP client
|
||||
* Send a packet to the UDP client.
|
||||
* @param {Object} packet The packet to send
|
||||
* @returns {Promise<Object>}
|
||||
*/
|
||||
|
||||
@@ -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(() => {
|
||||
|
||||
@@ -53,7 +53,7 @@ class StreamDispatcher extends VolumeInterface {
|
||||
|
||||
/**
|
||||
* How many passes the dispatcher should take when sending packets to reduce packet loss. Values over 5
|
||||
* aren't recommended, as it means you are using 5x more bandwidth. You _can_ edit this at runtime.
|
||||
* aren't recommended, as it means you are using 5x more bandwidth. You _can_ edit this at runtime
|
||||
* @type {number}
|
||||
* @readonly
|
||||
*/
|
||||
@@ -100,7 +100,7 @@ class StreamDispatcher extends VolumeInterface {
|
||||
|
||||
/**
|
||||
* Stops the current stream permanently and emits an `end` event.
|
||||
* @param {string} [reason='user'] An optional reason for stopping the dispatcher.
|
||||
* @param {string} [reason='user'] An optional reason for stopping the dispatcher
|
||||
*/
|
||||
end(reason = 'user') {
|
||||
this.destroy('end', reason);
|
||||
@@ -110,7 +110,7 @@ class StreamDispatcher extends VolumeInterface {
|
||||
if (this.speaking === value) return;
|
||||
this.speaking = value;
|
||||
/**
|
||||
* Emitted when the dispatcher starts/stops speaking
|
||||
* Emitted when the dispatcher starts/stops speaking.
|
||||
* @event StreamDispatcher#speaking
|
||||
* @param {boolean} value Whether or not the dispatcher is speaking
|
||||
*/
|
||||
@@ -126,7 +126,7 @@ class StreamDispatcher extends VolumeInterface {
|
||||
sendPacket(packet) {
|
||||
let repeats = this.passes;
|
||||
/**
|
||||
* Emitted whenever the dispatcher has debug information
|
||||
* Emitted whenever the dispatcher has debug information.
|
||||
* @event StreamDispatcher#debug
|
||||
* @param {string} info the debug info
|
||||
*/
|
||||
@@ -260,7 +260,7 @@ class StreamDispatcher extends VolumeInterface {
|
||||
|
||||
if (!data.startTime) {
|
||||
/**
|
||||
* Emitted once the dispatcher starts streaming
|
||||
* Emitted once the dispatcher starts streaming.
|
||||
* @event StreamDispatcher#start
|
||||
*/
|
||||
this.emit('start');
|
||||
@@ -281,7 +281,7 @@ class StreamDispatcher extends VolumeInterface {
|
||||
this.setSpeaking(false);
|
||||
this.emit(type, reason);
|
||||
/**
|
||||
* Emitted once the dispatcher ends
|
||||
* Emitted once the dispatcher ends.
|
||||
* @param {string} [reason] the reason the dispatcher ended
|
||||
* @event StreamDispatcher#end
|
||||
*/
|
||||
@@ -291,9 +291,9 @@ class StreamDispatcher extends VolumeInterface {
|
||||
startStreaming() {
|
||||
if (!this.stream) {
|
||||
/**
|
||||
* Emitted if the dispatcher encounters an error
|
||||
* Emitted if the dispatcher encounters an error.
|
||||
* @event StreamDispatcher#error
|
||||
* @param {string} error the error message
|
||||
* @param {string} error The error message
|
||||
*/
|
||||
this.emit('error', 'No stream');
|
||||
return;
|
||||
|
||||
@@ -13,7 +13,7 @@ const ffmpegArguments = [
|
||||
];
|
||||
|
||||
/**
|
||||
* An Audio Player for a Voice Connection
|
||||
* An Audio Player for a Voice Connection.
|
||||
* @private
|
||||
* @extends {EventEmitter}
|
||||
*/
|
||||
|
||||
@@ -21,7 +21,7 @@ class VoiceReceiver extends EventEmitter {
|
||||
super();
|
||||
/*
|
||||
Need a queue because we don't get the ssrc of the user speaking until after the first few packets,
|
||||
so we queue up unknown SSRCs until they become known, then empty the queue.
|
||||
so we queue up unknown SSRCs until they become known, then empty the queue
|
||||
*/
|
||||
this.queues = new Map();
|
||||
this.pcmStreams = new Map();
|
||||
@@ -29,7 +29,7 @@ class VoiceReceiver extends EventEmitter {
|
||||
this.opusEncoders = new Map();
|
||||
|
||||
/**
|
||||
* Whether or not this receiver has been destroyed.
|
||||
* Whether or not this receiver has been destroyed
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.destroyed = false;
|
||||
@@ -91,7 +91,7 @@ class VoiceReceiver extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked when a user stops speaking
|
||||
* Invoked when a user stops speaking.
|
||||
* @param {User} user The user that stopped speaking
|
||||
* @private
|
||||
*/
|
||||
@@ -153,7 +153,7 @@ class VoiceReceiver extends EventEmitter {
|
||||
* @event VoiceReceiver#warn
|
||||
* @param {string} reason The reason for the warning. If it happened because the voice packet could not be
|
||||
* decrypted, this would be `decrypt`. If it happened because the voice packet could not be decoded into
|
||||
* PCM, this would be `decode`.
|
||||
* PCM, this would be `decode`
|
||||
* @param {string} message The warning message
|
||||
*/
|
||||
this.emit('warn', 'decrypt', 'Failed to decrypt voice packet');
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Represents a Secret Key used in encryption over voice
|
||||
* Represents a Secret Key used in encryption over voice.
|
||||
* @private
|
||||
*/
|
||||
class SecretKey {
|
||||
|
||||
@@ -10,51 +10,6 @@ class VolumeInterface extends EventEmitter {
|
||||
this.setVolume(volume || 1);
|
||||
}
|
||||
|
||||
applyVolume(buffer, volume) {
|
||||
volume = volume || this._volume;
|
||||
if (volume === 1) return buffer;
|
||||
|
||||
const out = new Buffer(buffer.length);
|
||||
for (let i = 0; i < buffer.length; i += 2) {
|
||||
if (i >= buffer.length - 1) break;
|
||||
const uint = Math.min(32767, Math.max(-32767, Math.floor(volume * buffer.readInt16LE(i))));
|
||||
out.writeInt16LE(uint, i);
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the volume relative to the input stream - i.e. 1 is normal, 0.5 is half, 2 is double.
|
||||
* @param {number} volume The volume that you want to set
|
||||
*/
|
||||
setVolume(volume) {
|
||||
/**
|
||||
* Emitted when the volume of this interface changes
|
||||
* @event VolumeInterface#volumeChange
|
||||
* @param {number} oldVolume The old volume of this interface
|
||||
* @param {number} newVolume The new volume of this interface
|
||||
*/
|
||||
this.emit('volumeChange', this._volume, volume);
|
||||
this._volume = volume;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the volume in decibels
|
||||
* @param {number} db The decibels
|
||||
*/
|
||||
setVolumeDecibels(db) {
|
||||
this.setVolume(Math.pow(10, db / 20));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the volume so that a perceived value of 0.5 is half the perceived volume etc.
|
||||
* @param {number} value The value for the volume
|
||||
*/
|
||||
setVolumeLogarithmic(value) {
|
||||
this.setVolume(Math.pow(value, 1.660964));
|
||||
}
|
||||
|
||||
/**
|
||||
* The current volume of the broadcast
|
||||
* @readonly
|
||||
@@ -81,6 +36,51 @@ class VolumeInterface extends EventEmitter {
|
||||
get volumeLogarithmic() {
|
||||
return Math.pow(this._volume, 1 / 1.660964);
|
||||
}
|
||||
|
||||
applyVolume(buffer, volume) {
|
||||
volume = volume || this._volume;
|
||||
if (volume === 1) return buffer;
|
||||
|
||||
const out = new Buffer(buffer.length);
|
||||
for (let i = 0; i < buffer.length; i += 2) {
|
||||
if (i >= buffer.length - 1) break;
|
||||
const uint = Math.min(32767, Math.max(-32767, Math.floor(volume * buffer.readInt16LE(i))));
|
||||
out.writeInt16LE(uint, i);
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the volume relative to the input stream - i.e. 1 is normal, 0.5 is half, 2 is double.
|
||||
* @param {number} volume The volume that you want to set
|
||||
*/
|
||||
setVolume(volume) {
|
||||
/**
|
||||
* Emitted when the volume of this interface changes.
|
||||
* @event VolumeInterface#volumeChange
|
||||
* @param {number} oldVolume The old volume of this interface
|
||||
* @param {number} newVolume The new volume of this interface
|
||||
*/
|
||||
this.emit('volumeChange', this._volume, volume);
|
||||
this._volume = volume;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the volume in decibels.
|
||||
* @param {number} db The decibels
|
||||
*/
|
||||
setVolumeDecibels(db) {
|
||||
this.setVolume(Math.pow(10, db / 20));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the volume so that a perceived value of 0.5 is half the perceived volume etc.
|
||||
* @param {number} value The value for the volume
|
||||
*/
|
||||
setVolumeLogarithmic(value) {
|
||||
this.setVolume(Math.pow(value, 1.660964));
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = VolumeInterface;
|
||||
|
||||
@@ -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