lavacord 3.0.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,7 +7,7 @@ var Rest_cjs = require('./lib/Rest.cjs');
7
7
  var Types_cjs = require('./lib/Types.cjs');
8
8
 
9
9
  // src/index.ts
10
- var VERSION = "3.0.0";
10
+ var VERSION = "3.0.1";
11
11
 
12
12
  exports.VERSION = VERSION;
13
13
  Object.keys(LavalinkNode_cjs).forEach(function (k) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;AAYO,IAAM,OAAA,GAAkB","file":"index.cjs","sourcesContent":["/**\n * @module Lavacord\n */\nexport * from \"./lib/LavalinkNode\";\nexport * from \"./lib/Player\";\nexport * from \"./lib/Manager\";\nexport * from \"./lib/Rest\";\nexport * from \"./lib/Types\";\n\n// This is a placeholder for the version of the library, which should be injected during build time\n// this need to be explicitly typed as string.\n// eslint-disable-next-line @typescript-eslint/no-inferrable-types\nexport const VERSION: string = \"3.0.0\";\n"]}
1
+ {"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;AAYO,IAAM,OAAA,GAAkB","file":"index.cjs","sourcesContent":["/**\n * @module Lavacord\n */\nexport * from \"./lib/LavalinkNode\";\nexport * from \"./lib/Player\";\nexport * from \"./lib/Manager\";\nexport * from \"./lib/Rest\";\nexport * from \"./lib/Types\";\n\n// This is a placeholder for the version of the library, which should be injected during build time\n// this need to be explicitly typed as string.\n// eslint-disable-next-line @typescript-eslint/no-inferrable-types\nexport const VERSION: string = \"3.0.1\";\n"]}
@@ -203,35 +203,35 @@ var LavalinkNode = class {
203
203
  * @throws {Error} If the connection fails due to network issues, authentication problems, or other errors
204
204
  */
205
205
  async connect() {
206
- if (this.connected) this.ws.close(1e3, "reconnecting");
207
206
  this.version = await Rest_cjs.Rest.version(this).then((str) => str.split(".")[0]).catch(() => "4");
208
- return new Promise((resolve, reject) => {
209
- let isResolved = false;
210
- const headers = {
211
- Authorization: this.password,
212
- "User-Id": this.manager.userId,
213
- "Client-Name": `Lavacord/${index_cjs.VERSION}`
214
- };
215
- if (this.sessionId && this.resuming) headers["Session-Id"] = this.sessionId;
216
- this.ws = new cloudstorm.BetterWs(this.socketURL, { headers, encoding: "json" }).on("ws_open", () => {
217
- isResolved = true;
207
+ const headers = {
208
+ Authorization: this.password,
209
+ "User-Id": this.manager.userId,
210
+ "Client-Name": `Lavacord/${index_cjs.VERSION}`
211
+ };
212
+ if (this.sessionId && this.resuming) headers["Session-Id"] = this.sessionId;
213
+ if (!this.ws) {
214
+ this.ws = new cloudstorm.BetterWs(this.socketURL, { headers, encoding: "json", connectThrottle: 0 });
215
+ this.ws.on("ws_receive", (data) => this.onMessage(data)).on("error", (e) => this.onError(e)).on("ws_close", (code, reason) => this.onClose(code, reason));
216
+ }
217
+ if (["connecting", "upgrading"].includes(this.ws.sm.currentStateName)) {
218
+ await cloudstorm.eventSwitch(this.ws, { ws_open: /* @__PURE__ */ __name(() => void 0, "ws_open") });
219
+ return this.ws;
220
+ }
221
+ if (["connected", "half_close"].includes(this.ws.sm.currentStateName)) await this.ws.close(1e3, "reconnecting");
222
+ this.ws.connect();
223
+ await cloudstorm.eventSwitch(this.ws, {
224
+ ws_open: /* @__PURE__ */ __name(() => {
218
225
  this.onOpen();
219
- resolve(this.ws);
220
- }).on("error", (error) => {
221
- if (!isResolved) {
222
- isResolved = true;
223
- reject(new Error(error));
224
- }
225
- this.onError(new Error(error));
226
- }).on("ws_close", (code, reason) => {
227
- if (!isResolved) {
228
- isResolved = true;
229
- reject(new Error(`WebSocket closed during connection: ${code} ${reason.toString()}`));
230
- }
231
- this.onClose(code, reason);
232
- }).on("ws_receive", this.onMessage.bind(this));
233
- this.ws.connect();
226
+ }, "ws_open"),
227
+ error: /* @__PURE__ */ __name((e) => {
228
+ throw e;
229
+ }, "error"),
230
+ ws_close: /* @__PURE__ */ __name((code, reason) => {
231
+ throw new Error(`WebSocket closed during connection: ${code} ${reason.toString()}`);
232
+ }, "ws_close")
234
233
  });
234
+ return this.ws;
235
235
  }
236
236
  /**
237
237
  * Gracefully closes the connection to the Lavalink server.
@@ -341,7 +341,6 @@ var LavalinkNode = class {
341
341
  if (!error) return;
342
342
  this.manager.emit("error", error, this);
343
343
  this.destroy();
344
- this.reconnect();
345
344
  }
346
345
  /**
347
346
  * Handles WebSocket closure.
@@ -352,8 +351,6 @@ var LavalinkNode = class {
352
351
  onClose(code, reason) {
353
352
  this._sessionUpdated = false;
354
353
  this.manager.emit("disconnect", code, reason, this);
355
- this.ws?.removeAllListeners();
356
- this.ws = null;
357
354
  switch (code) {
358
355
  case 1e3:
359
356
  if (reason.toString() === "destroy") return clearTimeout(this._reconnect);
@@ -376,7 +373,7 @@ var LavalinkNode = class {
376
373
  const delay = Math.min(this.reconnectInterval * Math.pow(2, this._reconnectAttempts - 1), 6e4);
377
374
  this._reconnect = setTimeout(async () => {
378
375
  this.manager.emit("reconnecting", this);
379
- await this.connect().catch((error) => this.manager.emit("error", error, this));
376
+ await this.connect().catch(() => void 0);
380
377
  }, delay);
381
378
  }
382
379
  _handleEvent(data) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/LavalinkNode.ts"],"names":["Rest","VERSION","BetterWs"],"mappings":";;;;;;;;AAsBO,IAAM,eAAN,MAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoLlB,WAAA,CACC,SACP,OAAA,EACC;AAFM,IAAA,IAAA,CAAA,OAAA,GAAA,OAAA;AAGP,IAAA,IAAA,CAAK,KAAK,OAAA,CAAQ,EAAA;AAElB,IAAA,IAAI,OAAA,CAAQ,IAAA,EAAM,MAAA,CAAO,cAAA,CAAe,IAAA,EAAM,QAAQ,EAAE,KAAA,EAAO,OAAA,CAAQ,IAAA,EAAM,CAAA;AAC7E,IAAA,IAAI,OAAA,CAAQ,IAAA,EAAM,MAAA,CAAO,cAAA,CAAe,IA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,CAAO,IAAA,CAAK,cAAc,IAAI,CAAA;AACtE,QAAA,IAAI,IAAA,CAAK,OAAA,CAAQ,aAAA,CAAc,kBAAkB,CAAA,OAAQ,OAAA,CAAQ,IAAA,CAAK,kBAAA,EAAoB,MAAA,EAAQ,IAAI,CAAA;AACtG,QAAA;AAAA,MACD,KAAK,sBAAA;AACJ,QAAA,MAAA,CAAO,KAAA,GAAQ,IAAA;AACf,QAAA,MAAA,CAAO,SAAA,GAAY,IAAA;AACnB,QAAA,IAAI,OAAO,aAAA,CAAc,iBAAiB,GAAG,MAAA,CAAO,IAAA,CAAK,mBAAmB,IAAI,CAAA;AAChF,QAAA,IAAI,IAAA,CAAK,OAAA,CAAQ,aAAA,CAAc,uBAAuB,CAAA,OAAQ,OAAA,CAAQ,IAAA,CAAK,uBAAA,EAAyB,MAAA,EAAQ,IAAI,CAAA;AAChH,QAAA;AAAA,MACD;AACC,QAAA,IAAA,CAAK,QAAQ,IAAA,CAAK,MAAA,EAAQ,CAAA,uBAAA,EAA2B,IAAA,CAA0B,IAAI,CAAA,CAAE,CAAA;AACrF,QAAA;AAAA;AACF;AAEF","file":"LavalinkNode.cjs","sourcesContent":["import { Rest } from \"./Rest\";\n\nimport { BetterWs } from \"cloudstorm\";\n\nimport type { Manager } from \"./Manager\";\nimport type { LavalinkNodeOptions } from \"./Types\";\nimport { VERSION } from \"../index\";\nimport { EventOP, OutboundHandshakeHeaders, Stats, StatsOP, WebsocketMessage } from \"lavalink-types\";\n\n/**\n * The LavalinkNode class handles the connection and communication with a Lavalink server.\n *\n * @summary Manages WebSocket connections to Lavalink servers and processes server events\n *\n * This class is responsible for establishing WebSocket connections to Lavalink,\n * handling reconnection logic, and processing incoming messages from the server.\n *\n * @remarks\n * LavalinkNode instances are typically created and managed by the {@link Manager} class,\n * which handles load balancing across multiple nodes and routing player actions\n * to the appropriate node.\n */\nexport class LavalinkNode {\n\t/**\n\t * The identifier for this Lavalink node. Used to distinguish between multiple nodes.\n\t *\n\t * @summary Unique identifier for the node\n\t * @remarks\n\t * This is a required property that must be unique across all nodes in your application.\n\t * It's used for identifying this node in logs and when selecting nodes for new players.\n\t */\n\tpublic id: string;\n\n\t/**\n\t * The hostname or IP address of the Lavalink server.\n\t *\n\t * @summary Server hostname or IP address\n\t * @remarks\n\t * This can be a domain name, IPv4, or IPv6 address pointing to your Lavalink server.\n\t */\n\tpublic readonly host = \"localhost\";\n\n\t/**\n\t * The port number that the Lavalink server is listening on.\n\t *\n\t * @summary Server port number\n\t * @remarks\n\t * This should match the port configured in your Lavalink server's application.yml.\n\t */\n\tpublic readonly port: number | string = 2333;\n\n\t/**\n\t * The time in milliseconds between reconnection attempts if the connection fails.\n\t *\n\t * @summary Reconnection delay in milliseconds\n\t * @remarks\n\t * Lower values will attempt reconnections more quickly, but might\n\t * cause excessive connection attempts during prolonged server outages.\n\t */\n\tpublic reconnectInterval = 10000;\n\n\t/**\n\t * The password used for authorization with the Lavalink server.\n\t *\n\t * @summary Authorization password for the Lavalink server\n\t * @remarks\n\t * This password must match the one configured in your Lavalink server's application.yml.\n\t * It's used in the Authorization header when establishing the WebSocket connection.\n\t */\n\tpublic readonly password = \"youshallnotpass\";\n\n\t/**\n\t * Whether to use secure connections (HTTPS/WSS) instead of HTTP/WS.\n\t *\n\t * @summary Secure connection flag for SSL/TLS\n\t * @remarks\n\t * When true, WebSocket connections will use WSS and REST requests will use HTTPS.\n\t * This is required when connecting to Lavalink servers behind SSL/TLS.\n\t */\n\tpublic readonly secure = false;\n\n\t/**\n\t * The WebSocket instance used for communication with the Lavalink server.\n\t *\n\t * @summary Active WebSocket connection to the Lavalink server\n\t * @remarks\n\t * When not connected to Lavalink, this property will be null.\n\t * You can check the {@link connected} property to determine connection status.\n\t */\n\tpublic ws: BetterWs | null = null;\n\n\t/**\n\t * The statistics received from the Lavalink server.\n\t *\n\t * @summary Server resource usage and player statistics\n\t * @remarks\n\t * Contains information about system resource usage, player counts, and audio frame statistics.\n\t * This is updated whenever the Lavalink server sends a stats update (typically every minute).\n\t * You can use these stats to implement node selection strategies in your application.\n\t */\n\tpublic stats: Stats = {\n\t\tplayers: 0,\n\t\tplayingPlayers: 0,\n\t\tuptime: 0,\n\t\tmemory: {\n\t\t\tused: 0,\n\t\t\tfree: 0,\n\t\t\tallocated: 0,\n\t\t\treservable: 0\n\t\t},\n\t\tcpu: {\n\t\t\tcores: 0,\n\t\t\tsystemLoad: 0,\n\t\t\tlavalinkLoad: 0\n\t\t},\n\t\tframeStats: {\n\t\t\tsent: 0,\n\t\t\tnulled: 0,\n\t\t\tdeficit: 0\n\t\t}\n\t};\n\n\t/**\n\t * Whether this node should attempt to resume the session when reconnecting.\n\t *\n\t * @summary Session resumption flag\n\t * @remarks\n\t * When true, the node will try to resume the previous session after a disconnect,\n\t * preserving player states and connections. This helps maintain playback during\n\t * brief disconnections or node restarts.\n\t */\n\tpublic resuming = false;\n\n\t/**\n\t * The timeout in seconds after which a disconnected session can no longer be resumed.\n\t *\n\t * @summary Maximum session resumption timeout in seconds\n\t * @remarks\n\t * This value is sent to the Lavalink server when configuring session resuming.\n\t * After this many seconds of disconnection, the session will be fully closed\n\t * and cannot be resumed.\n\t */\n\tpublic resumeTimeout = 60;\n\n\t/**\n\t * Custom data that can be attached to the node instance.\n\t *\n\t * @summary Custom application data storage\n\t * @remarks\n\t * Not used internally by Lavacord, available for application-specific needs.\n\t * You can use this property to store any data relevant to your implementation,\n\t * such as region information, feature flags, or custom metrics.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tpublic state?: any;\n\n\t/**\n\t * The unique session identifier provided by Lavalink on successful connection.\n\t *\n\t * @summary Lavalink session identifier\n\t * @remarks\n\t * This ID is used for resuming sessions and in certain REST API calls.\n\t * It's automatically assigned when connecting to the Lavalink server.\n\t */\n\tpublic sessionId?: string;\n\t/**\n\t * The version of the Lavalink protocol this node is using.\n\t *\n\t * @summary Lavalink protocol version\n\t * @remarks\n\t * This is set automatically when connecting to the Lavalink server.\n\t * It indicates which version of the Lavalink protocol this node supports.\n\t * The default value is \"4\", which corresponds to the latest stable version.\n\t *\n\t * @defaultValue \"4\"\n\t */\n\tpublic version = \"4\";\n\n\t/**\n\t * Timeout reference used for the reconnection mechanism.\n\t * This holds the NodeJS.Timeout instance used to schedule reconnection attempts.\n\t */\n\tprivate _reconnect?: NodeJS.Timeout;\n\n\t/**\n\t * Current reconnection attempt count for exponential backoff.\n\t */\n\tprivate _reconnectAttempts = 0;\n\n\t/**\n\t * Tracks whether the session has been updated with the Lavalink server.\n\t * Used internally to avoid redundant session update requests.\n\t */\n\tprivate _sessionUpdated = false;\n\n\t/**\n\t * Creates a new LavalinkNode instance.\n\t *\n\t * @summary Initializes a new Lavalink node connection\n\t * @param manager - The {@link Manager} instance that controls this node\n\t * @param options - Configuration options for this Lavalink node as defined in {@link LavalinkNodeOptions}\n\t */\n\tpublic constructor(\n\t\tpublic manager: Manager,\n\t\toptions: LavalinkNodeOptions\n\t) {\n\t\tthis.id = options.id;\n\n\t\tif (options.host) Object.defineProperty(this, \"host\", { value: options.host });\n\t\tif (options.port) Object.defineProperty(this, \"port\", { value: options.port });\n\t\tif (options.password) Object.defineProperty(this, \"password\", { value: options.password });\n\t\tif (options.secure !== undefined) Object.defineProperty(this, \"secure\", { value: options.secure });\n\t\tif (options.reconnectInterval) this.reconnectInterval = options.reconnectInterval;\n\t\tif (options.sessionId) this.sessionId = options.sessionId;\n\t\tif (options.resuming !== undefined) this.resuming = options.resuming;\n\t\tif (options.resumeTimeout) this.resumeTimeout = options.resumeTimeout;\n\t\tif (options.state) this.state = options.state;\n\t}\n\n\t/**\n\t * Establishes a connection to the Lavalink server.\n\t *\n\t * This method creates a new WebSocket connection to the configured Lavalink server.\n\t * If the node is already connected, it will close the existing connection first.\n\t * The method sets up event listeners for the WebSocket to handle messages, errors,\n\t * and connection state changes.\n\t *\n\t * Note: This method is primarily used internally by the {@link Manager} class.\n\t * Users typically should not call this method directly as the Manager handles\n\t * node connections automatically.\n\t *\n\t * @returns A promise that resolves when connected or rejects if connection fails\n\t * @throws {Error} If the connection fails due to network issues, authentication problems, or other errors\n\t */\n\tpublic async connect(): Promise<BetterWs> {\n\t\tif (this.connected) this.ws!.close(1000, \"reconnecting\");\n\n\t\tthis.version = await Rest.version(this)\n\t\t\t.then((str) => str.split(\".\")[0])\n\t\t\t.catch(() => \"4\");\n\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tlet isResolved = false;\n\n\t\t\t// Prepare headers for the WebSocket connection\n\t\t\tconst headers: OutboundHandshakeHeaders = {\n\t\t\t\tAuthorization: this.password,\n\t\t\t\t\"User-Id\": this.manager.userId!,\n\t\t\t\t\"Client-Name\": `Lavacord/${VERSION}`\n\t\t\t};\n\n\t\t\tif (this.sessionId && this.resuming) headers[\"Session-Id\"] = this.sessionId;\n\n\t\t\tthis.ws = new BetterWs(this.socketURL, { headers, encoding: \"json\" })\n\t\t\t\t.on(\"ws_open\", () => {\n\t\t\t\t\tisResolved = true;\n\t\t\t\t\tthis.onOpen();\n\t\t\t\t\tresolve(this.ws!);\n\t\t\t\t})\n\t\t\t\t.on(\"error\", (error) => {\n\t\t\t\t\tif (!isResolved) {\n\t\t\t\t\t\tisResolved = true;\n\t\t\t\t\t\treject(new Error(error));\n\t\t\t\t\t}\n\t\t\t\t\tthis.onError(new Error(error));\n\t\t\t\t})\n\t\t\t\t.on(\"ws_close\", (code, reason) => {\n\t\t\t\t\tif (!isResolved) {\n\t\t\t\t\t\tisResolved = true;\n\t\t\t\t\t\treject(new Error(`WebSocket closed during connection: ${code} ${reason.toString()}`));\n\t\t\t\t\t}\n\t\t\t\t\tthis.onClose(code, reason);\n\t\t\t\t})\n\t\t\t\t.on(\"ws_receive\", this.onMessage.bind(this));\n\n\t\t\tthis.ws.connect()\n\t\t});\n\t}\n\n\t/**\n\t * Gracefully closes the connection to the Lavalink server.\n\t *\n\t * This method closes the WebSocket connection with a normal closure code (1000)\n\t * and a reason of \"destroy\", indicating an intentional disconnection rather\n\t * than an error condition.\n\t *\n\t * Note: This method is primarily used internally by the {@link Manager} class.\n\t * Users typically should not call this method directly as the Manager handles\n\t * node disconnections automatically.\n\t *\n\t * @returns void\n\t */\n\tpublic destroy(): void {\n\t\tif (!this.connected) return;\n\t\tthis.ws!.close(1000, \"destroy\");\n\t}\n\n\t/**\n\t * Indicates whether this node is currently connected to the Lavalink server.\n\t *\n\t * @summary Connection status check\n\t * @remarks\n\t * Checks if the {@link ws} instance exists and if its ready state is 1.\n\t * This property is useful for verifying connection status before attempting operations\n\t * or implementing node selection strategies.\n\t *\n\t * @returns `true` if connected, `false` otherwise\n\t */\n\tpublic get connected(): boolean {\n\t\tif (!this.ws) return false;\n\t\treturn this.ws.sm.currentStateName === \"connected\";\n\t}\n\n\t/**\n\t * Gets the WebSocket URL for connecting to the Lavalink server.\n\t *\n\t * @summary WebSocket connection URL\n\t * @remarks\n\t * Returns either a secure (wss://) or insecure (ws://) WebSocket URL\n\t * based on the {@link secure} property configuration.\n\t *\n\t * @returns The complete WebSocket URL including protocol, host, port, and path\n\t */\n\tpublic get socketURL(): string {\n\t\tconst protocol = this.secure ? \"wss\" : \"ws\";\n\t\treturn `${protocol}://${this.host}:${this.port}/v${this.version}/websocket`;\n\t}\n\n\t/**\n\t * Gets the REST API base URL for the Lavalink server.\n\t *\n\t * @summary REST API base URL\n\t * @remarks\n\t * Returns either a secure (https://) or insecure (http://) REST URL\n\t * based on the {@link secure} property configuration.\n\t *\n\t * @returns The complete REST API base URL including protocol, host, port, and path\n\t */\n\tpublic get restURL(): string {\n\t\tconst protocol = this.secure ? \"https\" : \"http\";\n\t\treturn `${protocol}://${this.host}:${this.port}`;\n\t}\n\n\t/**\n\t * Handles the WebSocket 'open' event when a connection is established.\n\t */\n\tprivate onOpen(): void {\n\t\tif (this._reconnect) clearTimeout(this._reconnect);\n\t\tthis._reconnectAttempts = 0;\n\t\tthis.manager.emit(\"ready\", this);\n\t}\n\n\t/**\n\t * Processes incoming WebSocket messages from the Lavalink server.\n\t * @param msg - The raw data received from the WebSocket\n\t */\n\tprivate onMessage(msg: WebsocketMessage): void {\n\t\tswitch (msg.op) {\n\t\t\tcase \"ready\":\n\t\t\t\tif (msg.sessionId) this.sessionId = msg.sessionId;\n\t\t\t\tif (!this._sessionUpdated) {\n\t\t\t\t\tthis._sessionUpdated = true;\n\t\t\t\t\tRest.updateSession(this).catch((e) => this.manager.emit(\"error\", e, this));\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase \"stats\": {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\t\t\t\tconst { op, ...stats } = msg as StatsOP;\n\t\t\t\tthis.stats = stats;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase \"event\":\n\t\t\t\tthis._handleEvent(msg);\n\t\t\t\tbreak;\n\t\t\tcase \"playerUpdate\": {\n\t\t\t\tconst player = this.manager.players.get(msg.guildId);\n\t\t\t\tif (!player) break;\n\t\t\t\tplayer.state = msg.state;\n\t\t\t\tif (player.listenerCount(\"state\")) player.emit(\"state\", msg.state);\n\t\t\t\tif (this.manager.listenerCount(\"playerState\")) this.manager.emit(\"playerState\", player, msg.state);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tdefault:\n\t\t\t\tbreak;\n\t\t}\n\n\t\tthis.manager.emit(\"raw\", msg, this);\n\t}\n\n\t/**\n\t * Handles WebSocket errors.\n\t * @param error - The error received from the WebSocket\n\t */\n\tprivate onError(error: Error): void {\n\t\tif (!error) return;\n\n\t\tthis.manager.emit(\"error\", error, this);\n\t\tthis.destroy();\n\t\tthis.reconnect();\n\t}\n\n\t/**\n\t * Handles WebSocket closure.\n\t *\n\t * @param code - The WebSocket close code (see Lavalink API for code meanings)\n\t * @param reason - The reason why the WebSocket was closed\n\t */\n\tprivate onClose(code: number, reason: string): void {\n\t\tthis._sessionUpdated = false;\n\t\tthis.manager.emit(\"disconnect\", code, reason, this);\n\n\t\tthis.ws?.removeAllListeners();\n\t\tthis.ws = null;\n\n\t\tswitch (code) {\n\t\t\tcase 1000:\n\t\t\t\tif (reason.toString() === \"destroy\") return clearTimeout(this._reconnect);\n\t\t\t\tbreak;\n\n\t\t\tcase 4001:\n\t\t\tcase 4002:\n\t\t\tcase 4003:\n\t\t\tcase 4004:\n\t\t\tcase 4005:\n\t\t\t\tthis.manager.emit(\"error\", new Error(`Lavalink authentication error: ${code} ${reason}`), this);\n\t\t\t\treturn;\n\t\t\tdefault:\n\t\t\t\tbreak;\n\t\t}\n\n\t\tthis.reconnect();\n\t}\n\n\t/**\n\t * Initiates a reconnection attempt after a delay with exponential backoff.\n\t */\n\tprivate reconnect(): void {\n\t\tthis._reconnectAttempts++;\n\t\tconst delay = Math.min(this.reconnectInterval * Math.pow(2, this._reconnectAttempts - 1), 60000);\n\n\t\tthis._reconnect = setTimeout(async () => {\n\t\t\tthis.manager.emit(\"reconnecting\", this);\n\t\t\tawait this.connect().catch((error) => this.manager.emit(\"error\", error, this));\n\t\t}, delay);\n\t}\n\n\tprivate _handleEvent(data: EventOP) {\n\t\tconst player = this.manager.players.get(data.guildId);\n\t\tif (!player) return;\n\n\t\tswitch (data.type) {\n\t\t\tcase \"TrackStartEvent\":\n\t\t\t\tplayer.track = data.track;\n\t\t\t\tplayer.timestamp = Date.now();\n\t\t\t\tif (player.listenerCount(\"trackStart\")) player.emit(\"trackStart\", data);\n\t\t\t\tif (this.manager.listenerCount(\"playerTrackStart\")) this.manager.emit(\"playerTrackStart\", player, data);\n\t\t\t\tbreak;\n\t\t\tcase \"TrackEndEvent\":\n\t\t\t\tif (data.reason !== \"replaced\") {\n\t\t\t\t\tplayer.track = null;\n\t\t\t\t\tplayer.timestamp = null;\n\t\t\t\t}\n\t\t\t\tif (player.listenerCount(\"trackEnd\")) player.emit(\"trackEnd\", data);\n\t\t\t\tif (this.manager.listenerCount(\"playerTrackEnd\")) this.manager.emit(\"playerTrackEnd\", player, data);\n\t\t\t\tbreak;\n\t\t\tcase \"TrackExceptionEvent\":\n\t\t\t\tif (player.listenerCount(\"trackException\")) player.emit(\"trackException\", data);\n\t\t\t\tif (this.manager.listenerCount(\"playerTrackException\")) this.manager.emit(\"playerTrackException\", player, data);\n\t\t\t\tbreak;\n\t\t\tcase \"TrackStuckEvent\":\n\t\t\t\tif (player.listenerCount(\"trackStuck\")) player.emit(\"trackStuck\", data);\n\t\t\t\tif (this.manager.listenerCount(\"playerTrackStuck\")) this.manager.emit(\"playerTrackStuck\", player, data);\n\t\t\t\tbreak;\n\t\t\tcase \"WebSocketClosedEvent\":\n\t\t\t\tplayer.track = null;\n\t\t\t\tplayer.timestamp = null;\n\t\t\t\tif (player.listenerCount(\"webSocketClosed\")) player.emit(\"webSocketClosed\", data);\n\t\t\t\tif (this.manager.listenerCount(\"playerWebSocketClosed\")) this.manager.emit(\"playerWebSocketClosed\", player, data);\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthis.manager.emit(\"warn\", `Unexpected event type: ${(data as { type: string }).type}`);\n\t\t\t\tbreak;\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"sources":["../../../src/lib/LavalinkNode.ts"],"names":["Rest","VERSION","BetterWs","eventSwitch"],"mappings":";;;;;;;;AAsBO,IAAM,eAAN,MAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoLlB,WAAA,CACC,SACP,OAAA,EACC;AAFM,IAAA,IAAA,CAAA,OAAA,GAAA,OAAA;AAGP,IAAA,IAAA,CAAK,KAAK,OAAA,CAAQ,EAAA;AAElB,IAAA,IAAI,OAAA,CAAQ,IAAA,EAAM,MAAA,CAAO,cAAA,CAAe,IAAA,EAAM,QAAQ,EAAE,KAAA,EAAO,OAAA,CAAQ,IAAA,EAAM,CAAA;AAC7E,IAAA,IAAI,OAAA,CAAQ,IAAA,EAAM,MAAA,CAAO,cAAA,CAAe,IAAA,EAAM,QAAQ,EAAE,KAAA,EAAO,OAAA,CAAQ,IAAA,EAAM,CAAA;AAC7E,IAAA,IAAI,OAAA,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AAG,MAAA,CAAO,IAAA,CAAK,cAAc,IAAI,CAAA;AACtE,QAAA,IAAI,IAAA,CAAK,OAAA,CAAQ,aAAA,CAAc,kBAAkB,CAAA,OAAQ,OAAA,CAAQ,IAAA,CAAK,kBAAA,EAAoB,MAAA,EAAQ,IAAI,CAAA;AACtG,QAAA;AAAA,MACD,KAAK,sBAAA;AACJ,QAAA,MAAA,CAAO,KAAA,GAAQ,IAAA;AACf,QAAA,MAAA,CAAO,SAAA,GAAY,IAAA;AACnB,QAAA,IAAI,OAAO,aAAA,CAAc,iBAAiB,GAAG,MAAA,CAAO,IAAA,CAAK,mBAAmB,IAAI,CAAA;AAChF,QAAA,IAAI,IAAA,CAAK,OAAA,CAAQ,aAAA,CAAc,uBAAuB,CAAA,OAAQ,OAAA,CAAQ,IAAA,CAAK,uBAAA,EAAyB,MAAA,EAAQ,IAAI,CAAA;AAChH,QAAA;AAAA,MACD;AACC,QAAA,IAAA,CAAK,QAAQ,IAAA,CAAK,MAAA,EAAQ,CAAA,uBAAA,EAA2B,IAAA,CAA0B,IAAI,CAAA,CAAE,CAAA;AACrF,QAAA;AAAA;AACF;AAEF","file":"LavalinkNode.cjs","sourcesContent":["import { Rest } from \"./Rest\";\n\nimport { BetterWs, eventSwitch } from \"cloudstorm\";\n\nimport type { Manager } from \"./Manager\";\nimport type { LavalinkNodeOptions } from \"./Types\";\nimport { VERSION } from \"../index\";\nimport { EventOP, OutboundHandshakeHeaders, Stats, StatsOP, WebsocketMessage } from \"lavalink-types\";\n\n/**\n * The LavalinkNode class handles the connection and communication with a Lavalink server.\n *\n * @summary Manages WebSocket connections to Lavalink servers and processes server events\n *\n * This class is responsible for establishing WebSocket connections to Lavalink,\n * handling reconnection logic, and processing incoming messages from the server.\n *\n * @remarks\n * LavalinkNode instances are typically created and managed by the {@link Manager} class,\n * which handles load balancing across multiple nodes and routing player actions\n * to the appropriate node.\n */\nexport class LavalinkNode {\n\t/**\n\t * The identifier for this Lavalink node. Used to distinguish between multiple nodes.\n\t *\n\t * @summary Unique identifier for the node\n\t * @remarks\n\t * This is a required property that must be unique across all nodes in your application.\n\t * It's used for identifying this node in logs and when selecting nodes for new players.\n\t */\n\tpublic id: string;\n\n\t/**\n\t * The hostname or IP address of the Lavalink server.\n\t *\n\t * @summary Server hostname or IP address\n\t * @remarks\n\t * This can be a domain name, IPv4, or IPv6 address pointing to your Lavalink server.\n\t */\n\tpublic readonly host = \"localhost\";\n\n\t/**\n\t * The port number that the Lavalink server is listening on.\n\t *\n\t * @summary Server port number\n\t * @remarks\n\t * This should match the port configured in your Lavalink server's application.yml.\n\t */\n\tpublic readonly port: number | string = 2333;\n\n\t/**\n\t * The time in milliseconds between reconnection attempts if the connection fails.\n\t *\n\t * @summary Reconnection delay in milliseconds\n\t * @remarks\n\t * Lower values will attempt reconnections more quickly, but might\n\t * cause excessive connection attempts during prolonged server outages.\n\t */\n\tpublic reconnectInterval = 10000;\n\n\t/**\n\t * The password used for authorization with the Lavalink server.\n\t *\n\t * @summary Authorization password for the Lavalink server\n\t * @remarks\n\t * This password must match the one configured in your Lavalink server's application.yml.\n\t * It's used in the Authorization header when establishing the WebSocket connection.\n\t */\n\tpublic readonly password = \"youshallnotpass\";\n\n\t/**\n\t * Whether to use secure connections (HTTPS/WSS) instead of HTTP/WS.\n\t *\n\t * @summary Secure connection flag for SSL/TLS\n\t * @remarks\n\t * When true, WebSocket connections will use WSS and REST requests will use HTTPS.\n\t * This is required when connecting to Lavalink servers behind SSL/TLS.\n\t */\n\tpublic readonly secure = false;\n\n\t/**\n\t * The WebSocket instance used for communication with the Lavalink server.\n\t *\n\t * @summary Active WebSocket connection to the Lavalink server\n\t * @remarks\n\t * When not connected to Lavalink, this property will be null.\n\t * You can check the {@link connected} property to determine connection status.\n\t */\n\tpublic ws: BetterWs | null = null;\n\n\t/**\n\t * The statistics received from the Lavalink server.\n\t *\n\t * @summary Server resource usage and player statistics\n\t * @remarks\n\t * Contains information about system resource usage, player counts, and audio frame statistics.\n\t * This is updated whenever the Lavalink server sends a stats update (typically every minute).\n\t * You can use these stats to implement node selection strategies in your application.\n\t */\n\tpublic stats: Stats = {\n\t\tplayers: 0,\n\t\tplayingPlayers: 0,\n\t\tuptime: 0,\n\t\tmemory: {\n\t\t\tused: 0,\n\t\t\tfree: 0,\n\t\t\tallocated: 0,\n\t\t\treservable: 0\n\t\t},\n\t\tcpu: {\n\t\t\tcores: 0,\n\t\t\tsystemLoad: 0,\n\t\t\tlavalinkLoad: 0\n\t\t},\n\t\tframeStats: {\n\t\t\tsent: 0,\n\t\t\tnulled: 0,\n\t\t\tdeficit: 0\n\t\t}\n\t};\n\n\t/**\n\t * Whether this node should attempt to resume the session when reconnecting.\n\t *\n\t * @summary Session resumption flag\n\t * @remarks\n\t * When true, the node will try to resume the previous session after a disconnect,\n\t * preserving player states and connections. This helps maintain playback during\n\t * brief disconnections or node restarts.\n\t */\n\tpublic resuming = false;\n\n\t/**\n\t * The timeout in seconds after which a disconnected session can no longer be resumed.\n\t *\n\t * @summary Maximum session resumption timeout in seconds\n\t * @remarks\n\t * This value is sent to the Lavalink server when configuring session resuming.\n\t * After this many seconds of disconnection, the session will be fully closed\n\t * and cannot be resumed.\n\t */\n\tpublic resumeTimeout = 60;\n\n\t/**\n\t * Custom data that can be attached to the node instance.\n\t *\n\t * @summary Custom application data storage\n\t * @remarks\n\t * Not used internally by Lavacord, available for application-specific needs.\n\t * You can use this property to store any data relevant to your implementation,\n\t * such as region information, feature flags, or custom metrics.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tpublic state?: any;\n\n\t/**\n\t * The unique session identifier provided by Lavalink on successful connection.\n\t *\n\t * @summary Lavalink session identifier\n\t * @remarks\n\t * This ID is used for resuming sessions and in certain REST API calls.\n\t * It's automatically assigned when connecting to the Lavalink server.\n\t */\n\tpublic sessionId?: string;\n\t/**\n\t * The version of the Lavalink protocol this node is using.\n\t *\n\t * @summary Lavalink protocol version\n\t * @remarks\n\t * This is set automatically when connecting to the Lavalink server.\n\t * It indicates which version of the Lavalink protocol this node supports.\n\t * The default value is \"4\", which corresponds to the latest stable version.\n\t *\n\t * @defaultValue \"4\"\n\t */\n\tpublic version = \"4\";\n\n\t/**\n\t * Timeout reference used for the reconnection mechanism.\n\t * This holds the NodeJS.Timeout instance used to schedule reconnection attempts.\n\t */\n\tprivate _reconnect?: NodeJS.Timeout;\n\n\t/**\n\t * Current reconnection attempt count for exponential backoff.\n\t */\n\tprivate _reconnectAttempts = 0;\n\n\t/**\n\t * Tracks whether the session has been updated with the Lavalink server.\n\t * Used internally to avoid redundant session update requests.\n\t */\n\tprivate _sessionUpdated = false;\n\n\t/**\n\t * Creates a new LavalinkNode instance.\n\t *\n\t * @summary Initializes a new Lavalink node connection\n\t * @param manager - The {@link Manager} instance that controls this node\n\t * @param options - Configuration options for this Lavalink node as defined in {@link LavalinkNodeOptions}\n\t */\n\tpublic constructor(\n\t\tpublic manager: Manager,\n\t\toptions: LavalinkNodeOptions\n\t) {\n\t\tthis.id = options.id;\n\n\t\tif (options.host) Object.defineProperty(this, \"host\", { value: options.host });\n\t\tif (options.port) Object.defineProperty(this, \"port\", { value: options.port });\n\t\tif (options.password) Object.defineProperty(this, \"password\", { value: options.password });\n\t\tif (options.secure !== undefined) Object.defineProperty(this, \"secure\", { value: options.secure });\n\t\tif (options.reconnectInterval) this.reconnectInterval = options.reconnectInterval;\n\t\tif (options.sessionId) this.sessionId = options.sessionId;\n\t\tif (options.resuming !== undefined) this.resuming = options.resuming;\n\t\tif (options.resumeTimeout) this.resumeTimeout = options.resumeTimeout;\n\t\tif (options.state) this.state = options.state;\n\t}\n\n\t/**\n\t * Establishes a connection to the Lavalink server.\n\t *\n\t * This method creates a new WebSocket connection to the configured Lavalink server.\n\t * If the node is already connected, it will close the existing connection first.\n\t * The method sets up event listeners for the WebSocket to handle messages, errors,\n\t * and connection state changes.\n\t *\n\t * Note: This method is primarily used internally by the {@link Manager} class.\n\t * Users typically should not call this method directly as the Manager handles\n\t * node connections automatically.\n\t *\n\t * @returns A promise that resolves when connected or rejects if connection fails\n\t * @throws {Error} If the connection fails due to network issues, authentication problems, or other errors\n\t */\n\tpublic async connect(): Promise<BetterWs> {\n\t\tthis.version = await Rest.version(this)\n\t\t\t.then((str) => str.split(\".\")[0])\n\t\t\t.catch(() => \"4\");\n\n\t\t// Prepare headers for the WebSocket connection\n\t\tconst headers: OutboundHandshakeHeaders = {\n\t\t\tAuthorization: this.password,\n\t\t\t\"User-Id\": this.manager.userId!,\n\t\t\t\"Client-Name\": `Lavacord/${VERSION}`\n\t\t};\n\n\t\tif (this.sessionId && this.resuming) headers[\"Session-Id\"] = this.sessionId;\n\t\tif (!this.ws) {\n\t\t\tthis.ws = new BetterWs(this.socketURL, { headers, encoding: \"json\", connectThrottle: 0 });\n\t\t\tthis.ws\n\t\t\t\t.on(\"ws_receive\", data => this.onMessage(data))\n\t\t\t\t.on(\"error\", e => this.onError(e))\n\t\t\t\t.on(\"ws_close\", (code, reason) => this.onClose(code, reason));\n\t\t}\n\n\t\tif ([\"connecting\", \"upgrading\"].includes(this.ws.sm.currentStateName)) {\n\t\t\tawait eventSwitch(this.ws, { ws_open: () => void 0 });\n\t\t\treturn this.ws;\n\t\t}\n\t\tif ([\"connected\", \"half_close\"].includes(this.ws.sm.currentStateName)) await this.ws.close(1000, \"reconnecting\");\n\n\t\tthis.ws.connect();\n\n\t\tawait eventSwitch(this.ws, {\n\t\t\tws_open: () => {\n\t\t\t\tthis.onOpen();\n\t\t\t},\n\t\t\terror: e => {\n\t\t\t\tthrow e;\n\t\t\t},\n\t\t\tws_close: (code: number, reason: string) => {\n\t\t\t\tthrow new Error(`WebSocket closed during connection: ${code} ${reason.toString()}`);\n\t\t\t}\n\t\t});\n\n\t\treturn this.ws;\n\t}\n\n\t/**\n\t * Gracefully closes the connection to the Lavalink server.\n\t *\n\t * This method closes the WebSocket connection with a normal closure code (1000)\n\t * and a reason of \"destroy\", indicating an intentional disconnection rather\n\t * than an error condition.\n\t *\n\t * Note: This method is primarily used internally by the {@link Manager} class.\n\t * Users typically should not call this method directly as the Manager handles\n\t * node disconnections automatically.\n\t *\n\t * @returns void\n\t */\n\tpublic destroy(): void {\n\t\tif (!this.connected) return;\n\t\tthis.ws!.close(1000, \"destroy\");\n\t}\n\n\t/**\n\t * Indicates whether this node is currently connected to the Lavalink server.\n\t *\n\t * @summary Connection status check\n\t * @remarks\n\t * Checks if the {@link ws} instance exists and if its ready state is 1.\n\t * This property is useful for verifying connection status before attempting operations\n\t * or implementing node selection strategies.\n\t *\n\t * @returns `true` if connected, `false` otherwise\n\t */\n\tpublic get connected(): boolean {\n\t\tif (!this.ws) return false;\n\t\treturn this.ws.sm.currentStateName === \"connected\";\n\t}\n\n\t/**\n\t * Gets the WebSocket URL for connecting to the Lavalink server.\n\t *\n\t * @summary WebSocket connection URL\n\t * @remarks\n\t * Returns either a secure (wss://) or insecure (ws://) WebSocket URL\n\t * based on the {@link secure} property configuration.\n\t *\n\t * @returns The complete WebSocket URL including protocol, host, port, and path\n\t */\n\tpublic get socketURL(): string {\n\t\tconst protocol = this.secure ? \"wss\" : \"ws\";\n\t\treturn `${protocol}://${this.host}:${this.port}/v${this.version}/websocket`;\n\t}\n\n\t/**\n\t * Gets the REST API base URL for the Lavalink server.\n\t *\n\t * @summary REST API base URL\n\t * @remarks\n\t * Returns either a secure (https://) or insecure (http://) REST URL\n\t * based on the {@link secure} property configuration.\n\t *\n\t * @returns The complete REST API base URL including protocol, host, port, and path\n\t */\n\tpublic get restURL(): string {\n\t\tconst protocol = this.secure ? \"https\" : \"http\";\n\t\treturn `${protocol}://${this.host}:${this.port}`;\n\t}\n\n\t/**\n\t * Handles the WebSocket 'open' event when a connection is established.\n\t */\n\tprivate onOpen(): void {\n\t\tif (this._reconnect) clearTimeout(this._reconnect);\n\t\tthis._reconnectAttempts = 0;\n\t\tthis.manager.emit(\"ready\", this);\n\t}\n\n\t/**\n\t * Processes incoming WebSocket messages from the Lavalink server.\n\t * @param msg - The raw data received from the WebSocket\n\t */\n\tprivate onMessage(msg: WebsocketMessage): void {\n\t\tswitch (msg.op) {\n\t\t\tcase \"ready\":\n\t\t\t\tif (msg.sessionId) this.sessionId = msg.sessionId;\n\t\t\t\tif (!this._sessionUpdated) {\n\t\t\t\t\tthis._sessionUpdated = true;\n\t\t\t\t\tRest.updateSession(this).catch((e) => this.manager.emit(\"error\", e, this));\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase \"stats\": {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\t\t\t\tconst { op, ...stats } = msg as StatsOP;\n\t\t\t\tthis.stats = stats;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase \"event\":\n\t\t\t\tthis._handleEvent(msg);\n\t\t\t\tbreak;\n\t\t\tcase \"playerUpdate\": {\n\t\t\t\tconst player = this.manager.players.get(msg.guildId);\n\t\t\t\tif (!player) break;\n\t\t\t\tplayer.state = msg.state;\n\t\t\t\tif (player.listenerCount(\"state\")) player.emit(\"state\", msg.state);\n\t\t\t\tif (this.manager.listenerCount(\"playerState\")) this.manager.emit(\"playerState\", player, msg.state);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tdefault:\n\t\t\t\tbreak;\n\t\t}\n\n\t\tthis.manager.emit(\"raw\", msg, this);\n\t}\n\n\t/**\n\t * Handles WebSocket errors.\n\t * @param error - The error received from the WebSocket\n\t */\n\tprivate onError(error: Error): void {\n\t\tif (!error) return;\n\n\t\tthis.manager.emit(\"error\", error, this);\n\t\tthis.destroy();\n\t}\n\n\t/**\n\t * Handles WebSocket closure.\n\t *\n\t * @param code - The WebSocket close code (see Lavalink API for code meanings)\n\t * @param reason - The reason why the WebSocket was closed\n\t */\n\tprivate onClose(code: number, reason: string): void {\n\t\tthis._sessionUpdated = false;\n\t\tthis.manager.emit(\"disconnect\", code, reason, this);\n\n\t\tswitch (code) {\n\t\t\tcase 1000:\n\t\t\t\tif (reason.toString() === \"destroy\") return clearTimeout(this._reconnect);\n\t\t\t\tbreak;\n\n\t\t\tcase 4001:\n\t\t\tcase 4002:\n\t\t\tcase 4003:\n\t\t\tcase 4004:\n\t\t\tcase 4005:\n\t\t\t\tthis.manager.emit(\"error\", new Error(`Lavalink authentication error: ${code} ${reason}`), this);\n\t\t\t\treturn;\n\t\t\tdefault:\n\t\t\t\tbreak;\n\t\t}\n\n\t\tthis.reconnect();\n\t}\n\n\t/**\n\t * Initiates a reconnection attempt after a delay with exponential backoff.\n\t */\n\tprivate reconnect(): void {\n\t\tthis._reconnectAttempts++;\n\t\tconst delay = Math.min(this.reconnectInterval * Math.pow(2, this._reconnectAttempts - 1), 60000);\n\n\t\tthis._reconnect = setTimeout(async () => {\n\t\t\tthis.manager.emit(\"reconnecting\", this);\n\t\t\tawait this.connect().catch(() => void 0); // the error is already forwarded lol\n\t\t}, delay);\n\t}\n\n\tprivate _handleEvent(data: EventOP) {\n\t\tconst player = this.manager.players.get(data.guildId);\n\t\tif (!player) return;\n\n\t\tswitch (data.type) {\n\t\t\tcase \"TrackStartEvent\":\n\t\t\t\tplayer.track = data.track;\n\t\t\t\tplayer.timestamp = Date.now();\n\t\t\t\tif (player.listenerCount(\"trackStart\")) player.emit(\"trackStart\", data);\n\t\t\t\tif (this.manager.listenerCount(\"playerTrackStart\")) this.manager.emit(\"playerTrackStart\", player, data);\n\t\t\t\tbreak;\n\t\t\tcase \"TrackEndEvent\":\n\t\t\t\tif (data.reason !== \"replaced\") {\n\t\t\t\t\tplayer.track = null;\n\t\t\t\t\tplayer.timestamp = null;\n\t\t\t\t}\n\t\t\t\tif (player.listenerCount(\"trackEnd\")) player.emit(\"trackEnd\", data);\n\t\t\t\tif (this.manager.listenerCount(\"playerTrackEnd\")) this.manager.emit(\"playerTrackEnd\", player, data);\n\t\t\t\tbreak;\n\t\t\tcase \"TrackExceptionEvent\":\n\t\t\t\tif (player.listenerCount(\"trackException\")) player.emit(\"trackException\", data);\n\t\t\t\tif (this.manager.listenerCount(\"playerTrackException\")) this.manager.emit(\"playerTrackException\", player, data);\n\t\t\t\tbreak;\n\t\t\tcase \"TrackStuckEvent\":\n\t\t\t\tif (player.listenerCount(\"trackStuck\")) player.emit(\"trackStuck\", data);\n\t\t\t\tif (this.manager.listenerCount(\"playerTrackStuck\")) this.manager.emit(\"playerTrackStuck\", player, data);\n\t\t\t\tbreak;\n\t\t\tcase \"WebSocketClosedEvent\":\n\t\t\t\tplayer.track = null;\n\t\t\t\tplayer.timestamp = null;\n\t\t\t\tif (player.listenerCount(\"webSocketClosed\")) player.emit(\"webSocketClosed\", data);\n\t\t\t\tif (this.manager.listenerCount(\"playerWebSocketClosed\")) this.manager.emit(\"playerWebSocketClosed\", player, data);\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthis.manager.emit(\"warn\", `Unexpected event type: ${(data as { type: string }).type}`);\n\t\t\t\tbreak;\n\t\t}\n\t}\n}\n"]}
@@ -5,7 +5,7 @@ export * from './lib/Manager.mjs';
5
5
  export * from './lib/Rest.mjs';
6
6
  export * from './lib/Types.mjs';
7
7
 
8
- var VERSION = "3.0.0";
8
+ var VERSION = "3.0.1";
9
9
 
10
10
  export { VERSION };
11
11
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;AAYO,IAAM,OAAA,GAAkB","file":"index.mjs","sourcesContent":["/**\n * @module Lavacord\n */\nexport * from \"./lib/LavalinkNode\";\nexport * from \"./lib/Player\";\nexport * from \"./lib/Manager\";\nexport * from \"./lib/Rest\";\nexport * from \"./lib/Types\";\n\n// This is a placeholder for the version of the library, which should be injected during build time\n// this need to be explicitly typed as string.\n// eslint-disable-next-line @typescript-eslint/no-inferrable-types\nexport const VERSION: string = \"3.0.0\";\n"]}
1
+ {"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;AAYO,IAAM,OAAA,GAAkB","file":"index.mjs","sourcesContent":["/**\n * @module Lavacord\n */\nexport * from \"./lib/LavalinkNode\";\nexport * from \"./lib/Player\";\nexport * from \"./lib/Manager\";\nexport * from \"./lib/Rest\";\nexport * from \"./lib/Types\";\n\n// This is a placeholder for the version of the library, which should be injected during build time\n// this need to be explicitly typed as string.\n// eslint-disable-next-line @typescript-eslint/no-inferrable-types\nexport const VERSION: string = \"3.0.1\";\n"]}
@@ -1,6 +1,6 @@
1
1
  import { __name } from '../chunk-PAWJFY3S.mjs';
2
2
  import { Rest } from './Rest.mjs';
3
- import { BetterWs } from 'cloudstorm';
3
+ import { BetterWs, eventSwitch } from 'cloudstorm';
4
4
  import { VERSION } from '../index.mjs';
5
5
 
6
6
  var LavalinkNode = class {
@@ -200,35 +200,35 @@ var LavalinkNode = class {
200
200
  * @throws {Error} If the connection fails due to network issues, authentication problems, or other errors
201
201
  */
202
202
  async connect() {
203
- if (this.connected) this.ws.close(1e3, "reconnecting");
204
203
  this.version = await Rest.version(this).then((str) => str.split(".")[0]).catch(() => "4");
205
- return new Promise((resolve, reject) => {
206
- let isResolved = false;
207
- const headers = {
208
- Authorization: this.password,
209
- "User-Id": this.manager.userId,
210
- "Client-Name": `Lavacord/${VERSION}`
211
- };
212
- if (this.sessionId && this.resuming) headers["Session-Id"] = this.sessionId;
213
- this.ws = new BetterWs(this.socketURL, { headers, encoding: "json" }).on("ws_open", () => {
214
- isResolved = true;
204
+ const headers = {
205
+ Authorization: this.password,
206
+ "User-Id": this.manager.userId,
207
+ "Client-Name": `Lavacord/${VERSION}`
208
+ };
209
+ if (this.sessionId && this.resuming) headers["Session-Id"] = this.sessionId;
210
+ if (!this.ws) {
211
+ this.ws = new BetterWs(this.socketURL, { headers, encoding: "json", connectThrottle: 0 });
212
+ this.ws.on("ws_receive", (data) => this.onMessage(data)).on("error", (e) => this.onError(e)).on("ws_close", (code, reason) => this.onClose(code, reason));
213
+ }
214
+ if (["connecting", "upgrading"].includes(this.ws.sm.currentStateName)) {
215
+ await eventSwitch(this.ws, { ws_open: /* @__PURE__ */ __name(() => void 0, "ws_open") });
216
+ return this.ws;
217
+ }
218
+ if (["connected", "half_close"].includes(this.ws.sm.currentStateName)) await this.ws.close(1e3, "reconnecting");
219
+ this.ws.connect();
220
+ await eventSwitch(this.ws, {
221
+ ws_open: /* @__PURE__ */ __name(() => {
215
222
  this.onOpen();
216
- resolve(this.ws);
217
- }).on("error", (error) => {
218
- if (!isResolved) {
219
- isResolved = true;
220
- reject(new Error(error));
221
- }
222
- this.onError(new Error(error));
223
- }).on("ws_close", (code, reason) => {
224
- if (!isResolved) {
225
- isResolved = true;
226
- reject(new Error(`WebSocket closed during connection: ${code} ${reason.toString()}`));
227
- }
228
- this.onClose(code, reason);
229
- }).on("ws_receive", this.onMessage.bind(this));
230
- this.ws.connect();
223
+ }, "ws_open"),
224
+ error: /* @__PURE__ */ __name((e) => {
225
+ throw e;
226
+ }, "error"),
227
+ ws_close: /* @__PURE__ */ __name((code, reason) => {
228
+ throw new Error(`WebSocket closed during connection: ${code} ${reason.toString()}`);
229
+ }, "ws_close")
231
230
  });
231
+ return this.ws;
232
232
  }
233
233
  /**
234
234
  * Gracefully closes the connection to the Lavalink server.
@@ -338,7 +338,6 @@ var LavalinkNode = class {
338
338
  if (!error) return;
339
339
  this.manager.emit("error", error, this);
340
340
  this.destroy();
341
- this.reconnect();
342
341
  }
343
342
  /**
344
343
  * Handles WebSocket closure.
@@ -349,8 +348,6 @@ var LavalinkNode = class {
349
348
  onClose(code, reason) {
350
349
  this._sessionUpdated = false;
351
350
  this.manager.emit("disconnect", code, reason, this);
352
- this.ws?.removeAllListeners();
353
- this.ws = null;
354
351
  switch (code) {
355
352
  case 1e3:
356
353
  if (reason.toString() === "destroy") return clearTimeout(this._reconnect);
@@ -373,7 +370,7 @@ var LavalinkNode = class {
373
370
  const delay = Math.min(this.reconnectInterval * Math.pow(2, this._reconnectAttempts - 1), 6e4);
374
371
  this._reconnect = setTimeout(async () => {
375
372
  this.manager.emit("reconnecting", this);
376
- await this.connect().catch((error) => this.manager.emit("error", error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A;AACF;AAEF","file":"LavalinkNode.mjs","sourcesContent":["import { Rest } from \"./Rest\";\n\nimport { BetterWs } from \"cloudstorm\";\n\nimport type { Manager } from \"./Manager\";\nimport type { LavalinkNodeOptions } from \"./Types\";\nimport { VERSION } from \"../index\";\nimport { EventOP, OutboundHandshakeHeaders, Stats, StatsOP, WebsocketMessage } from \"lavalink-types\";\n\n/**\n * The LavalinkNode class handles the connection and communication with a Lavalink server.\n *\n * @summary Manages WebSocket connections to Lavalink servers and processes server events\n *\n * This class is responsible for establishing WebSocket connections to Lavalink,\n * handling reconnection logic, and processing incoming messages from the server.\n *\n * @remarks\n * LavalinkNode instances are typically created and managed by the {@link Manager} class,\n * which handles load balancing across multiple nodes and routing player actions\n * to the appropriate node.\n */\nexport class LavalinkNode {\n\t/**\n\t * The identifier for this Lavalink node. Used to distinguish between multiple nodes.\n\t *\n\t * @summary Unique identifier for the node\n\t * @remarks\n\t * This is a required property that must be unique across all nodes in your application.\n\t * It's used for identifying this node in logs and when selecting nodes for new players.\n\t */\n\tpublic id: string;\n\n\t/**\n\t * The hostname or IP address of the Lavalink server.\n\t *\n\t * @summary Server hostname or IP address\n\t * @remarks\n\t * This can be a domain name, IPv4, or IPv6 address pointing to your Lavalink server.\n\t */\n\tpublic readonly host = \"localhost\";\n\n\t/**\n\t * The port number that the Lavalink server is listening on.\n\t *\n\t * @summary Server port number\n\t * @remarks\n\t * This should match the port configured in your Lavalink server's application.yml.\n\t */\n\tpublic readonly port: number | string = 2333;\n\n\t/**\n\t * The time in milliseconds between reconnection attempts if the connection fails.\n\t *\n\t * @summary Reconnection delay in milliseconds\n\t * @remarks\n\t * Lower values will attempt reconnections more quickly, but might\n\t * cause excessive connection attempts during prolonged server outages.\n\t */\n\tpublic reconnectInterval = 10000;\n\n\t/**\n\t * The password used for authorization with the Lavalink server.\n\t *\n\t * @summary Authorization password for the Lavalink server\n\t * @remarks\n\t * This password must match the one configured in your Lavalink server's application.yml.\n\t * It's used in the Authorization header when establishing the WebSocket connection.\n\t */\n\tpublic readonly password = \"youshallnotpass\";\n\n\t/**\n\t * Whether to use secure connections (HTTPS/WSS) instead of HTTP/WS.\n\t *\n\t * @summary Secure connection flag for SSL/TLS\n\t * @remarks\n\t * When true, WebSocket connections will use WSS and REST requests will use HTTPS.\n\t * This is required when connecting to Lavalink servers behind SSL/TLS.\n\t */\n\tpublic readonly secure = false;\n\n\t/**\n\t * The WebSocket instance used for communication with the Lavalink server.\n\t *\n\t * @summary Active WebSocket connection to the Lavalink server\n\t * @remarks\n\t * When not connected to Lavalink, this property will be null.\n\t * You can check the {@link connected} property to determine connection status.\n\t */\n\tpublic ws: BetterWs | null = null;\n\n\t/**\n\t * The statistics received from the Lavalink server.\n\t *\n\t * @summary Server resource usage and player statistics\n\t * @remarks\n\t * Contains information about system resource usage, player counts, and audio frame statistics.\n\t * This is updated whenever the Lavalink server sends a stats update (typically every minute).\n\t * You can use these stats to implement node selection strategies in your application.\n\t */\n\tpublic stats: Stats = {\n\t\tplayers: 0,\n\t\tplayingPlayers: 0,\n\t\tuptime: 0,\n\t\tmemory: {\n\t\t\tused: 0,\n\t\t\tfree: 0,\n\t\t\tallocated: 0,\n\t\t\treservable: 0\n\t\t},\n\t\tcpu: {\n\t\t\tcores: 0,\n\t\t\tsystemLoad: 0,\n\t\t\tlavalinkLoad: 0\n\t\t},\n\t\tframeStats: {\n\t\t\tsent: 0,\n\t\t\tnulled: 0,\n\t\t\tdeficit: 0\n\t\t}\n\t};\n\n\t/**\n\t * Whether this node should attempt to resume the session when reconnecting.\n\t *\n\t * @summary Session resumption flag\n\t * @remarks\n\t * When true, the node will try to resume the previous session after a disconnect,\n\t * preserving player states and connections. This helps maintain playback during\n\t * brief disconnections or node restarts.\n\t */\n\tpublic resuming = false;\n\n\t/**\n\t * The timeout in seconds after which a disconnected session can no longer be resumed.\n\t *\n\t * @summary Maximum session resumption timeout in seconds\n\t * @remarks\n\t * This value is sent to the Lavalink server when configuring session resuming.\n\t * After this many seconds of disconnection, the session will be fully closed\n\t * and cannot be resumed.\n\t */\n\tpublic resumeTimeout = 60;\n\n\t/**\n\t * Custom data that can be attached to the node instance.\n\t *\n\t * @summary Custom application data storage\n\t * @remarks\n\t * Not used internally by Lavacord, available for application-specific needs.\n\t * You can use this property to store any data relevant to your implementation,\n\t * such as region information, feature flags, or custom metrics.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tpublic state?: any;\n\n\t/**\n\t * The unique session identifier provided by Lavalink on successful connection.\n\t *\n\t * @summary Lavalink session identifier\n\t * @remarks\n\t * This ID is used for resuming sessions and in certain REST API calls.\n\t * It's automatically assigned when connecting to the Lavalink server.\n\t */\n\tpublic sessionId?: string;\n\t/**\n\t * The version of the Lavalink protocol this node is using.\n\t *\n\t * @summary Lavalink protocol version\n\t * @remarks\n\t * This is set automatically when connecting to the Lavalink server.\n\t * It indicates which version of the Lavalink protocol this node supports.\n\t * The default value is \"4\", which corresponds to the latest stable version.\n\t *\n\t * @defaultValue \"4\"\n\t */\n\tpublic version = \"4\";\n\n\t/**\n\t * Timeout reference used for the reconnection mechanism.\n\t * This holds the NodeJS.Timeout instance used to schedule reconnection attempts.\n\t */\n\tprivate _reconnect?: NodeJS.Timeout;\n\n\t/**\n\t * Current reconnection attempt count for exponential backoff.\n\t */\n\tprivate _reconnectAttempts = 0;\n\n\t/**\n\t * Tracks whether the session has been updated with the Lavalink server.\n\t * Used internally to avoid redundant session update requests.\n\t */\n\tprivate _sessionUpdated = false;\n\n\t/**\n\t * Creates a new LavalinkNode instance.\n\t *\n\t * @summary Initializes a new Lavalink node connection\n\t * @param manager - The {@link Manager} instance that controls this node\n\t * @param options - Configuration options for this Lavalink node as defined in {@link LavalinkNodeOptions}\n\t */\n\tpublic constructor(\n\t\tpublic manager: Manager,\n\t\toptions: LavalinkNodeOptions\n\t) {\n\t\tthis.id = options.id;\n\n\t\tif (options.host) Object.defineProperty(this, \"host\", { value: options.host });\n\t\tif (options.port) Object.defineProperty(this, \"port\", { value: options.port });\n\t\tif (options.password) Object.defineProperty(this, \"password\", { value: options.password });\n\t\tif (options.secure !== undefined) Object.defineProperty(this, \"secure\", { value: options.secure });\n\t\tif (options.reconnectInterval) this.reconnectInterval = options.reconnectInterval;\n\t\tif (options.sessionId) this.sessionId = options.sessionId;\n\t\tif (options.resuming !== undefined) this.resuming = options.resuming;\n\t\tif (options.resumeTimeout) this.resumeTimeout = options.resumeTimeout;\n\t\tif (options.state) this.state = options.state;\n\t}\n\n\t/**\n\t * Establishes a connection to the Lavalink server.\n\t *\n\t * This method creates a new WebSocket connection to the configured Lavalink server.\n\t * If the node is already connected, it will close the existing connection first.\n\t * The method sets up event listeners for the WebSocket to handle messages, errors,\n\t * and connection state changes.\n\t *\n\t * Note: This method is primarily used internally by the {@link Manager} class.\n\t * Users typically should not call this method directly as the Manager handles\n\t * node connections automatically.\n\t *\n\t * @returns A promise that resolves when connected or rejects if connection fails\n\t * @throws {Error} If the connection fails due to network issues, authentication problems, or other errors\n\t */\n\tpublic async connect(): Promise<BetterWs> {\n\t\tif (this.connected) this.ws!.close(1000, \"reconnecting\");\n\n\t\tthis.version = await Rest.version(this)\n\t\t\t.then((str) => str.split(\".\")[0])\n\t\t\t.catch(() => \"4\");\n\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tlet isResolved = false;\n\n\t\t\t// Prepare headers for the WebSocket connection\n\t\t\tconst headers: OutboundHandshakeHeaders = {\n\t\t\t\tAuthorization: this.password,\n\t\t\t\t\"User-Id\": this.manager.userId!,\n\t\t\t\t\"Client-Name\": `Lavacord/${VERSION}`\n\t\t\t};\n\n\t\t\tif (this.sessionId && this.resuming) headers[\"Session-Id\"] = this.sessionId;\n\n\t\t\tthis.ws = new BetterWs(this.socketURL, { headers, encoding: \"json\" })\n\t\t\t\t.on(\"ws_open\", () => {\n\t\t\t\t\tisResolved = true;\n\t\t\t\t\tthis.onOpen();\n\t\t\t\t\tresolve(this.ws!);\n\t\t\t\t})\n\t\t\t\t.on(\"error\", (error) => {\n\t\t\t\t\tif (!isResolved) {\n\t\t\t\t\t\tisResolved = true;\n\t\t\t\t\t\treject(new Error(error));\n\t\t\t\t\t}\n\t\t\t\t\tthis.onError(new Error(error));\n\t\t\t\t})\n\t\t\t\t.on(\"ws_close\", (code, reason) => {\n\t\t\t\t\tif (!isResolved) {\n\t\t\t\t\t\tisResolved = true;\n\t\t\t\t\t\treject(new Error(`WebSocket closed during connection: ${code} ${reason.toString()}`));\n\t\t\t\t\t}\n\t\t\t\t\tthis.onClose(code, reason);\n\t\t\t\t})\n\t\t\t\t.on(\"ws_receive\", this.onMessage.bind(this));\n\n\t\t\tthis.ws.connect()\n\t\t});\n\t}\n\n\t/**\n\t * Gracefully closes the connection to the Lavalink server.\n\t *\n\t * This method closes the WebSocket connection with a normal closure code (1000)\n\t * and a reason of \"destroy\", indicating an intentional disconnection rather\n\t * than an error condition.\n\t *\n\t * Note: This method is primarily used internally by the {@link Manager} class.\n\t * Users typically should not call this method directly as the Manager handles\n\t * node disconnections automatically.\n\t *\n\t * @returns void\n\t */\n\tpublic destroy(): void {\n\t\tif (!this.connected) return;\n\t\tthis.ws!.close(1000, \"destroy\");\n\t}\n\n\t/**\n\t * Indicates whether this node is currently connected to the Lavalink server.\n\t *\n\t * @summary Connection status check\n\t * @remarks\n\t * Checks if the {@link ws} instance exists and if its ready state is 1.\n\t * This property is useful for verifying connection status before attempting operations\n\t * or implementing node selection strategies.\n\t *\n\t * @returns `true` if connected, `false` otherwise\n\t */\n\tpublic get connected(): boolean {\n\t\tif (!this.ws) return false;\n\t\treturn this.ws.sm.currentStateName === \"connected\";\n\t}\n\n\t/**\n\t * Gets the WebSocket URL for connecting to the Lavalink server.\n\t *\n\t * @summary WebSocket connection URL\n\t * @remarks\n\t * Returns either a secure (wss://) or insecure (ws://) WebSocket URL\n\t * based on the {@link secure} property configuration.\n\t *\n\t * @returns The complete WebSocket URL including protocol, host, port, and path\n\t */\n\tpublic get socketURL(): string {\n\t\tconst protocol = this.secure ? \"wss\" : \"ws\";\n\t\treturn `${protocol}://${this.host}:${this.port}/v${this.version}/websocket`;\n\t}\n\n\t/**\n\t * Gets the REST API base URL for the Lavalink server.\n\t *\n\t * @summary REST API base URL\n\t * @remarks\n\t * Returns either a secure (https://) or insecure (http://) REST URL\n\t * based on the {@link secure} property configuration.\n\t *\n\t * @returns The complete REST API base URL including protocol, host, port, and path\n\t */\n\tpublic get restURL(): string {\n\t\tconst protocol = this.secure ? \"https\" : \"http\";\n\t\treturn `${protocol}://${this.host}:${this.port}`;\n\t}\n\n\t/**\n\t * Handles the WebSocket 'open' event when a connection is established.\n\t */\n\tprivate onOpen(): void {\n\t\tif (this._reconnect) clearTimeout(this._reconnect);\n\t\tthis._reconnectAttempts = 0;\n\t\tthis.manager.emit(\"ready\", this);\n\t}\n\n\t/**\n\t * Processes incoming WebSocket messages from the Lavalink server.\n\t * @param msg - The raw data received from the WebSocket\n\t */\n\tprivate onMessage(msg: WebsocketMessage): void {\n\t\tswitch (msg.op) {\n\t\t\tcase \"ready\":\n\t\t\t\tif (msg.sessionId) this.sessionId = msg.sessionId;\n\t\t\t\tif (!this._sessionUpdated) {\n\t\t\t\t\tthis._sessionUpdated = true;\n\t\t\t\t\tRest.updateSession(this).catch((e) => this.manager.emit(\"error\", e, this));\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase \"stats\": {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\t\t\t\tconst { op, ...stats } = msg as StatsOP;\n\t\t\t\tthis.stats = stats;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase \"event\":\n\t\t\t\tthis._handleEvent(msg);\n\t\t\t\tbreak;\n\t\t\tcase \"playerUpdate\": {\n\t\t\t\tconst player = this.manager.players.get(msg.guildId);\n\t\t\t\tif (!player) break;\n\t\t\t\tplayer.state = msg.state;\n\t\t\t\tif (player.listenerCount(\"state\")) player.emit(\"state\", msg.state);\n\t\t\t\tif (this.manager.listenerCount(\"playerState\")) this.manager.emit(\"playerState\", player, msg.state);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tdefault:\n\t\t\t\tbreak;\n\t\t}\n\n\t\tthis.manager.emit(\"raw\", msg, this);\n\t}\n\n\t/**\n\t * Handles WebSocket errors.\n\t * @param error - The error received from the WebSocket\n\t */\n\tprivate onError(error: Error): void {\n\t\tif (!error) return;\n\n\t\tthis.manager.emit(\"error\", error, this);\n\t\tthis.destroy();\n\t\tthis.reconnect();\n\t}\n\n\t/**\n\t * Handles WebSocket closure.\n\t *\n\t * @param code - The WebSocket close code (see Lavalink API for code meanings)\n\t * @param reason - The reason why the WebSocket was closed\n\t */\n\tprivate onClose(code: number, reason: string): void {\n\t\tthis._sessionUpdated = false;\n\t\tthis.manager.emit(\"disconnect\", code, reason, this);\n\n\t\tthis.ws?.removeAllListeners();\n\t\tthis.ws = null;\n\n\t\tswitch (code) {\n\t\t\tcase 1000:\n\t\t\t\tif (reason.toString() === \"destroy\") return clearTimeout(this._reconnect);\n\t\t\t\tbreak;\n\n\t\t\tcase 4001:\n\t\t\tcase 4002:\n\t\t\tcase 4003:\n\t\t\tcase 4004:\n\t\t\tcase 4005:\n\t\t\t\tthis.manager.emit(\"error\", new Error(`Lavalink authentication error: ${code} ${reason}`), this);\n\t\t\t\treturn;\n\t\t\tdefault:\n\t\t\t\tbreak;\n\t\t}\n\n\t\tthis.reconnect();\n\t}\n\n\t/**\n\t * Initiates a reconnection attempt after a delay with exponential backoff.\n\t */\n\tprivate reconnect(): void {\n\t\tthis._reconnectAttempts++;\n\t\tconst delay = Math.min(this.reconnectInterval * Math.pow(2, this._reconnectAttempts - 1), 60000);\n\n\t\tthis._reconnect = setTimeout(async () => {\n\t\t\tthis.manager.emit(\"reconnecting\", this);\n\t\t\tawait this.connect().catch((error) => this.manager.emit(\"error\", error, this));\n\t\t}, delay);\n\t}\n\n\tprivate _handleEvent(data: EventOP) {\n\t\tconst player = this.manager.players.get(data.guildId);\n\t\tif (!player) return;\n\n\t\tswitch (data.type) {\n\t\t\tcase \"TrackStartEvent\":\n\t\t\t\tplayer.track = data.track;\n\t\t\t\tplayer.timestamp = Date.now();\n\t\t\t\tif (player.listenerCount(\"trackStart\")) player.emit(\"trackStart\", data);\n\t\t\t\tif (this.manager.listenerCount(\"playerTrackStart\")) this.manager.emit(\"playerTrackStart\", player, data);\n\t\t\t\tbreak;\n\t\t\tcase \"TrackEndEvent\":\n\t\t\t\tif (data.reason !== \"replaced\") {\n\t\t\t\t\tplayer.track = null;\n\t\t\t\t\tplayer.timestamp = null;\n\t\t\t\t}\n\t\t\t\tif (player.listenerCount(\"trackEnd\")) player.emit(\"trackEnd\", data);\n\t\t\t\tif (this.manager.listenerCount(\"playerTrackEnd\")) this.manager.emit(\"playerTrackEnd\", player, data);\n\t\t\t\tbreak;\n\t\t\tcase \"TrackExceptionEvent\":\n\t\t\t\tif (player.listenerCount(\"trackException\")) player.emit(\"trackException\", data);\n\t\t\t\tif (this.manager.listenerCount(\"playerTrackException\")) this.manager.emit(\"playerTrackException\", player, data);\n\t\t\t\tbreak;\n\t\t\tcase \"TrackStuckEvent\":\n\t\t\t\tif (player.listenerCount(\"trackStuck\")) player.emit(\"trackStuck\", data);\n\t\t\t\tif (this.manager.listenerCount(\"playerTrackStuck\")) this.manager.emit(\"playerTrackStuck\", player, data);\n\t\t\t\tbreak;\n\t\t\tcase \"WebSocketClosedEvent\":\n\t\t\t\tplayer.track = null;\n\t\t\t\tplayer.timestamp = null;\n\t\t\t\tif (player.listenerCount(\"webSocketClosed\")) player.emit(\"webSocketClosed\", data);\n\t\t\t\tif (this.manager.listenerCount(\"playerWebSocketClosed\")) this.manager.emit(\"playerWebSocketClosed\", player, data);\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthis.manager.emit(\"warn\", `Unexpected event type: ${(data as { type: string }).type}`);\n\t\t\t\tbreak;\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"sources":["../../../src/lib/LavalinkNode.ts"],"names":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ourcesContent":["import { Rest } from \"./Rest\";\n\nimport { BetterWs, eventSwitch } from \"cloudstorm\";\n\nimport type { Manager } from \"./Manager\";\nimport type { LavalinkNodeOptions } from \"./Types\";\nimport { VERSION } from \"../index\";\nimport { EventOP, OutboundHandshakeHeaders, Stats, StatsOP, WebsocketMessage } from \"lavalink-types\";\n\n/**\n * The LavalinkNode class handles the connection and communication with a Lavalink server.\n *\n * @summary Manages WebSocket connections to Lavalink servers and processes server events\n *\n * This class is responsible for establishing WebSocket connections to Lavalink,\n * handling reconnection logic, and processing incoming messages from the server.\n *\n * @remarks\n * LavalinkNode instances are typically created and managed by the {@link Manager} class,\n * which handles load balancing across multiple nodes and routing player actions\n * to the appropriate node.\n */\nexport class LavalinkNode {\n\t/**\n\t * The identifier for this Lavalink node. Used to distinguish between multiple nodes.\n\t *\n\t * @summary Unique identifier for the node\n\t * @remarks\n\t * This is a required property that must be unique across all nodes in your application.\n\t * It's used for identifying this node in logs and when selecting nodes for new players.\n\t */\n\tpublic id: string;\n\n\t/**\n\t * The hostname or IP address of the Lavalink server.\n\t *\n\t * @summary Server hostname or IP address\n\t * @remarks\n\t * This can be a domain name, IPv4, or IPv6 address pointing to your Lavalink server.\n\t */\n\tpublic readonly host = \"localhost\";\n\n\t/**\n\t * The port number that the Lavalink server is listening on.\n\t *\n\t * @summary Server port number\n\t * @remarks\n\t * This should match the port configured in your Lavalink server's application.yml.\n\t */\n\tpublic readonly port: number | string = 2333;\n\n\t/**\n\t * The time in milliseconds between reconnection attempts if the connection fails.\n\t *\n\t * @summary Reconnection delay in milliseconds\n\t * @remarks\n\t * Lower values will attempt reconnections more quickly, but might\n\t * cause excessive connection attempts during prolonged server outages.\n\t */\n\tpublic reconnectInterval = 10000;\n\n\t/**\n\t * The password used for authorization with the Lavalink server.\n\t *\n\t * @summary Authorization password for the Lavalink server\n\t * @remarks\n\t * This password must match the one configured in your Lavalink server's application.yml.\n\t * It's used in the Authorization header when establishing the WebSocket connection.\n\t */\n\tpublic readonly password = \"youshallnotpass\";\n\n\t/**\n\t * Whether to use secure connections (HTTPS/WSS) instead of HTTP/WS.\n\t *\n\t * @summary Secure connection flag for SSL/TLS\n\t * @remarks\n\t * When true, WebSocket connections will use WSS and REST requests will use HTTPS.\n\t * This is required when connecting to Lavalink servers behind SSL/TLS.\n\t */\n\tpublic readonly secure = false;\n\n\t/**\n\t * The WebSocket instance used for communication with the Lavalink server.\n\t *\n\t * @summary Active WebSocket connection to the Lavalink server\n\t * @remarks\n\t * When not connected to Lavalink, this property will be null.\n\t * You can check the {@link connected} property to determine connection status.\n\t */\n\tpublic ws: BetterWs | null = null;\n\n\t/**\n\t * The statistics received from the Lavalink server.\n\t *\n\t * @summary Server resource usage and player statistics\n\t * @remarks\n\t * Contains information about system resource usage, player counts, and audio frame statistics.\n\t * This is updated whenever the Lavalink server sends a stats update (typically every minute).\n\t * You can use these stats to implement node selection strategies in your application.\n\t */\n\tpublic stats: Stats = {\n\t\tplayers: 0,\n\t\tplayingPlayers: 0,\n\t\tuptime: 0,\n\t\tmemory: {\n\t\t\tused: 0,\n\t\t\tfree: 0,\n\t\t\tallocated: 0,\n\t\t\treservable: 0\n\t\t},\n\t\tcpu: {\n\t\t\tcores: 0,\n\t\t\tsystemLoad: 0,\n\t\t\tlavalinkLoad: 0\n\t\t},\n\t\tframeStats: {\n\t\t\tsent: 0,\n\t\t\tnulled: 0,\n\t\t\tdeficit: 0\n\t\t}\n\t};\n\n\t/**\n\t * Whether this node should attempt to resume the session when reconnecting.\n\t *\n\t * @summary Session resumption flag\n\t * @remarks\n\t * When true, the node will try to resume the previous session after a disconnect,\n\t * preserving player states and connections. This helps maintain playback during\n\t * brief disconnections or node restarts.\n\t */\n\tpublic resuming = false;\n\n\t/**\n\t * The timeout in seconds after which a disconnected session can no longer be resumed.\n\t *\n\t * @summary Maximum session resumption timeout in seconds\n\t * @remarks\n\t * This value is sent to the Lavalink server when configuring session resuming.\n\t * After this many seconds of disconnection, the session will be fully closed\n\t * and cannot be resumed.\n\t */\n\tpublic resumeTimeout = 60;\n\n\t/**\n\t * Custom data that can be attached to the node instance.\n\t *\n\t * @summary Custom application data storage\n\t * @remarks\n\t * Not used internally by Lavacord, available for application-specific needs.\n\t * You can use this property to store any data relevant to your implementation,\n\t * such as region information, feature flags, or custom metrics.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tpublic state?: any;\n\n\t/**\n\t * The unique session identifier provided by Lavalink on successful connection.\n\t *\n\t * @summary Lavalink session identifier\n\t * @remarks\n\t * This ID is used for resuming sessions and in certain REST API calls.\n\t * It's automatically assigned when connecting to the Lavalink server.\n\t */\n\tpublic sessionId?: string;\n\t/**\n\t * The version of the Lavalink protocol this node is using.\n\t *\n\t * @summary Lavalink protocol version\n\t * @remarks\n\t * This is set automatically when connecting to the Lavalink server.\n\t * It indicates which version of the Lavalink protocol this node supports.\n\t * The default value is \"4\", which corresponds to the latest stable version.\n\t *\n\t * @defaultValue \"4\"\n\t */\n\tpublic version = \"4\";\n\n\t/**\n\t * Timeout reference used for the reconnection mechanism.\n\t * This holds the NodeJS.Timeout instance used to schedule reconnection attempts.\n\t */\n\tprivate _reconnect?: NodeJS.Timeout;\n\n\t/**\n\t * Current reconnection attempt count for exponential backoff.\n\t */\n\tprivate _reconnectAttempts = 0;\n\n\t/**\n\t * Tracks whether the session has been updated with the Lavalink server.\n\t * Used internally to avoid redundant session update requests.\n\t */\n\tprivate _sessionUpdated = false;\n\n\t/**\n\t * Creates a new LavalinkNode instance.\n\t *\n\t * @summary Initializes a new Lavalink node connection\n\t * @param manager - The {@link Manager} instance that controls this node\n\t * @param options - Configuration options for this Lavalink node as defined in {@link LavalinkNodeOptions}\n\t */\n\tpublic constructor(\n\t\tpublic manager: Manager,\n\t\toptions: LavalinkNodeOptions\n\t) {\n\t\tthis.id = options.id;\n\n\t\tif (options.host) Object.defineProperty(this, \"host\", { value: options.host });\n\t\tif (options.port) Object.defineProperty(this, \"port\", { value: options.port });\n\t\tif (options.password) Object.defineProperty(this, \"password\", { value: options.password });\n\t\tif (options.secure !== undefined) Object.defineProperty(this, \"secure\", { value: options.secure });\n\t\tif (options.reconnectInterval) this.reconnectInterval = options.reconnectInterval;\n\t\tif (options.sessionId) this.sessionId = options.sessionId;\n\t\tif (options.resuming !== undefined) this.resuming = options.resuming;\n\t\tif (options.resumeTimeout) this.resumeTimeout = options.resumeTimeout;\n\t\tif (options.state) this.state = options.state;\n\t}\n\n\t/**\n\t * Establishes a connection to the Lavalink server.\n\t *\n\t * This method creates a new WebSocket connection to the configured Lavalink server.\n\t * If the node is already connected, it will close the existing connection first.\n\t * The method sets up event listeners for the WebSocket to handle messages, errors,\n\t * and connection state changes.\n\t *\n\t * Note: This method is primarily used internally by the {@link Manager} class.\n\t * Users typically should not call this method directly as the Manager handles\n\t * node connections automatically.\n\t *\n\t * @returns A promise that resolves when connected or rejects if connection fails\n\t * @throws {Error} If the connection fails due to network issues, authentication problems, or other errors\n\t */\n\tpublic async connect(): Promise<BetterWs> {\n\t\tthis.version = await Rest.version(this)\n\t\t\t.then((str) => str.split(\".\")[0])\n\t\t\t.catch(() => \"4\");\n\n\t\t// Prepare headers for the WebSocket connection\n\t\tconst headers: OutboundHandshakeHeaders = {\n\t\t\tAuthorization: this.password,\n\t\t\t\"User-Id\": this.manager.userId!,\n\t\t\t\"Client-Name\": `Lavacord/${VERSION}`\n\t\t};\n\n\t\tif (this.sessionId && this.resuming) headers[\"Session-Id\"] = this.sessionId;\n\t\tif (!this.ws) {\n\t\t\tthis.ws = new BetterWs(this.socketURL, { headers, encoding: \"json\", connectThrottle: 0 });\n\t\t\tthis.ws\n\t\t\t\t.on(\"ws_receive\", data => this.onMessage(data))\n\t\t\t\t.on(\"error\", e => this.onError(e))\n\t\t\t\t.on(\"ws_close\", (code, reason) => this.onClose(code, reason));\n\t\t}\n\n\t\tif ([\"connecting\", \"upgrading\"].includes(this.ws.sm.currentStateName)) {\n\t\t\tawait eventSwitch(this.ws, { ws_open: () => void 0 });\n\t\t\treturn this.ws;\n\t\t}\n\t\tif ([\"connected\", \"half_close\"].includes(this.ws.sm.currentStateName)) await this.ws.close(1000, \"reconnecting\");\n\n\t\tthis.ws.connect();\n\n\t\tawait eventSwitch(this.ws, {\n\t\t\tws_open: () => {\n\t\t\t\tthis.onOpen();\n\t\t\t},\n\t\t\terror: e => {\n\t\t\t\tthrow e;\n\t\t\t},\n\t\t\tws_close: (code: number, reason: string) => {\n\t\t\t\tthrow new Error(`WebSocket closed during connection: ${code} ${reason.toString()}`);\n\t\t\t}\n\t\t});\n\n\t\treturn this.ws;\n\t}\n\n\t/**\n\t * Gracefully closes the connection to the Lavalink server.\n\t *\n\t * This method closes the WebSocket connection with a normal closure code (1000)\n\t * and a reason of \"destroy\", indicating an intentional disconnection rather\n\t * than an error condition.\n\t *\n\t * Note: This method is primarily used internally by the {@link Manager} class.\n\t * Users typically should not call this method directly as the Manager handles\n\t * node disconnections automatically.\n\t *\n\t * @returns void\n\t */\n\tpublic destroy(): void {\n\t\tif (!this.connected) return;\n\t\tthis.ws!.close(1000, \"destroy\");\n\t}\n\n\t/**\n\t * Indicates whether this node is currently connected to the Lavalink server.\n\t *\n\t * @summary Connection status check\n\t * @remarks\n\t * Checks if the {@link ws} instance exists and if its ready state is 1.\n\t * This property is useful for verifying connection status before attempting operations\n\t * or implementing node selection strategies.\n\t *\n\t * @returns `true` if connected, `false` otherwise\n\t */\n\tpublic get connected(): boolean {\n\t\tif (!this.ws) return false;\n\t\treturn this.ws.sm.currentStateName === \"connected\";\n\t}\n\n\t/**\n\t * Gets the WebSocket URL for connecting to the Lavalink server.\n\t *\n\t * @summary WebSocket connection URL\n\t * @remarks\n\t * Returns either a secure (wss://) or insecure (ws://) WebSocket URL\n\t * based on the {@link secure} property configuration.\n\t *\n\t * @returns The complete WebSocket URL including protocol, host, port, and path\n\t */\n\tpublic get socketURL(): string {\n\t\tconst protocol = this.secure ? \"wss\" : \"ws\";\n\t\treturn `${protocol}://${this.host}:${this.port}/v${this.version}/websocket`;\n\t}\n\n\t/**\n\t * Gets the REST API base URL for the Lavalink server.\n\t *\n\t * @summary REST API base URL\n\t * @remarks\n\t * Returns either a secure (https://) or insecure (http://) REST URL\n\t * based on the {@link secure} property configuration.\n\t *\n\t * @returns The complete REST API base URL including protocol, host, port, and path\n\t */\n\tpublic get restURL(): string {\n\t\tconst protocol = this.secure ? \"https\" : \"http\";\n\t\treturn `${protocol}://${this.host}:${this.port}`;\n\t}\n\n\t/**\n\t * Handles the WebSocket 'open' event when a connection is established.\n\t */\n\tprivate onOpen(): void {\n\t\tif (this._reconnect) clearTimeout(this._reconnect);\n\t\tthis._reconnectAttempts = 0;\n\t\tthis.manager.emit(\"ready\", this);\n\t}\n\n\t/**\n\t * Processes incoming WebSocket messages from the Lavalink server.\n\t * @param msg - The raw data received from the WebSocket\n\t */\n\tprivate onMessage(msg: WebsocketMessage): void {\n\t\tswitch (msg.op) {\n\t\t\tcase \"ready\":\n\t\t\t\tif (msg.sessionId) this.sessionId = msg.sessionId;\n\t\t\t\tif (!this._sessionUpdated) {\n\t\t\t\t\tthis._sessionUpdated = true;\n\t\t\t\t\tRest.updateSession(this).catch((e) => this.manager.emit(\"error\", e, this));\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase \"stats\": {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\t\t\t\tconst { op, ...stats } = msg as StatsOP;\n\t\t\t\tthis.stats = stats;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase \"event\":\n\t\t\t\tthis._handleEvent(msg);\n\t\t\t\tbreak;\n\t\t\tcase \"playerUpdate\": {\n\t\t\t\tconst player = this.manager.players.get(msg.guildId);\n\t\t\t\tif (!player) break;\n\t\t\t\tplayer.state = msg.state;\n\t\t\t\tif (player.listenerCount(\"state\")) player.emit(\"state\", msg.state);\n\t\t\t\tif (this.manager.listenerCount(\"playerState\")) this.manager.emit(\"playerState\", player, msg.state);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tdefault:\n\t\t\t\tbreak;\n\t\t}\n\n\t\tthis.manager.emit(\"raw\", msg, this);\n\t}\n\n\t/**\n\t * Handles WebSocket errors.\n\t * @param error - The error received from the WebSocket\n\t */\n\tprivate onError(error: Error): void {\n\t\tif (!error) return;\n\n\t\tthis.manager.emit(\"error\", error, this);\n\t\tthis.destroy();\n\t}\n\n\t/**\n\t * Handles WebSocket closure.\n\t *\n\t * @param code - The WebSocket close code (see Lavalink API for code meanings)\n\t * @param reason - The reason why the WebSocket was closed\n\t */\n\tprivate onClose(code: number, reason: string): void {\n\t\tthis._sessionUpdated = false;\n\t\tthis.manager.emit(\"disconnect\", code, reason, this);\n\n\t\tswitch (code) {\n\t\t\tcase 1000:\n\t\t\t\tif (reason.toString() === \"destroy\") return clearTimeout(this._reconnect);\n\t\t\t\tbreak;\n\n\t\t\tcase 4001:\n\t\t\tcase 4002:\n\t\t\tcase 4003:\n\t\t\tcase 4004:\n\t\t\tcase 4005:\n\t\t\t\tthis.manager.emit(\"error\", new Error(`Lavalink authentication error: ${code} ${reason}`), this);\n\t\t\t\treturn;\n\t\t\tdefault:\n\t\t\t\tbreak;\n\t\t}\n\n\t\tthis.reconnect();\n\t}\n\n\t/**\n\t * Initiates a reconnection attempt after a delay with exponential backoff.\n\t */\n\tprivate reconnect(): void {\n\t\tthis._reconnectAttempts++;\n\t\tconst delay = Math.min(this.reconnectInterval * Math.pow(2, this._reconnectAttempts - 1), 60000);\n\n\t\tthis._reconnect = setTimeout(async () => {\n\t\t\tthis.manager.emit(\"reconnecting\", this);\n\t\t\tawait this.connect().catch(() => void 0); // the error is already forwarded lol\n\t\t}, delay);\n\t}\n\n\tprivate _handleEvent(data: EventOP) {\n\t\tconst player = this.manager.players.get(data.guildId);\n\t\tif (!player) return;\n\n\t\tswitch (data.type) {\n\t\t\tcase \"TrackStartEvent\":\n\t\t\t\tplayer.track = data.track;\n\t\t\t\tplayer.timestamp = Date.now();\n\t\t\t\tif (player.listenerCount(\"trackStart\")) player.emit(\"trackStart\", data);\n\t\t\t\tif (this.manager.listenerCount(\"playerTrackStart\")) this.manager.emit(\"playerTrackStart\", player, data);\n\t\t\t\tbreak;\n\t\t\tcase \"TrackEndEvent\":\n\t\t\t\tif (data.reason !== \"replaced\") {\n\t\t\t\t\tplayer.track = null;\n\t\t\t\t\tplayer.timestamp = null;\n\t\t\t\t}\n\t\t\t\tif (player.listenerCount(\"trackEnd\")) player.emit(\"trackEnd\", data);\n\t\t\t\tif (this.manager.listenerCount(\"playerTrackEnd\")) this.manager.emit(\"playerTrackEnd\", player, data);\n\t\t\t\tbreak;\n\t\t\tcase \"TrackExceptionEvent\":\n\t\t\t\tif (player.listenerCount(\"trackException\")) player.emit(\"trackException\", data);\n\t\t\t\tif (this.manager.listenerCount(\"playerTrackException\")) this.manager.emit(\"playerTrackException\", player, data);\n\t\t\t\tbreak;\n\t\t\tcase \"TrackStuckEvent\":\n\t\t\t\tif (player.listenerCount(\"trackStuck\")) player.emit(\"trackStuck\", data);\n\t\t\t\tif (this.manager.listenerCount(\"playerTrackStuck\")) this.manager.emit(\"playerTrackStuck\", player, data);\n\t\t\t\tbreak;\n\t\t\tcase \"WebSocketClosedEvent\":\n\t\t\t\tplayer.track = null;\n\t\t\t\tplayer.timestamp = null;\n\t\t\t\tif (player.listenerCount(\"webSocketClosed\")) player.emit(\"webSocketClosed\", data);\n\t\t\t\tif (this.manager.listenerCount(\"playerWebSocketClosed\")) this.manager.emit(\"playerWebSocketClosed\", player, data);\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthis.manager.emit(\"warn\", `Unexpected event type: ${(data as { type: string }).type}`);\n\t\t\t\tbreak;\n\t\t}\n\t}\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lavacord",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "A simple by design lavalink wrapper made for any discord library.",
5
5
  "main": "./dist/cjs/index.cjs",
6
6
  "module": "./dist/esm/index.mjs",
@@ -83,23 +83,23 @@
83
83
  },
84
84
  "homepage": "https://github.com/lavacord/lavacord#readme",
85
85
  "dependencies": {
86
- "cloudstorm": "^0.16.x",
87
- "discord-api-types": "^0.38.38",
86
+ "cloudstorm": "^0.17.0",
87
+ "discord-api-types": "^0.38.40",
88
88
  "lavalink-types": "^3.0.0"
89
89
  },
90
90
  "devDependencies": {
91
- "@eslint/js": "^9.29.2",
91
+ "@eslint/js": "^9.39.3",
92
92
  "@favware/rollup-type-bundler": "^4.0.0",
93
- "@types/node": "^25.2.3",
93
+ "@types/node": "^25.3.2",
94
94
  "esbuild-plugin-file-path-extensions": "^2.1.4",
95
95
  "esbuild-plugin-version-injector": "^1.2.1",
96
- "eslint": "^9.39.2",
96
+ "eslint": "^9.39.3",
97
97
  "prettier": "^3.8.1",
98
98
  "tsup": "^8.5.1",
99
- "typedoc": "^0.28.16",
100
- "typedoc-github-theme": "^0.3.1",
99
+ "typedoc": "^0.28.17",
100
+ "typedoc-github-theme": "^0.4.0",
101
101
  "typescript": "^5.9.3",
102
- "typescript-eslint": "^8.55.0"
102
+ "typescript-eslint": "^8.56.1"
103
103
  },
104
104
  "optionalDependencies": {
105
105
  "detritus-client": "0.16.x",
@@ -107,5 +107,5 @@
107
107
  "eris": "0.18.x",
108
108
  "oceanic.js": "1.13.0"
109
109
  },
110
- "packageManager": "yarn@4.9.2"
110
+ "packageManager": "yarn@4.12.0"
111
111
  }