lavacord
Version:
A simple by design lavalink wrapper made for any discord library.
1 lines • 26.6 kB
Source Map (JSON)
{"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,CAAQ,QAAA,EAAU,MAAA,CAAO,cAAA,CAAe,IAAA,EAAM,YAAY,EAAE,KAAA,EAAO,OAAA,CAAQ,QAAA,EAAU,CAAA;AACzF,IAAA,IAAI,OAAA,CAAQ,MAAA,KAAW,MAAA,EAAW,MAAA,CAAO,cAAA,CAAe,IAAA,EAAM,QAAA,EAAU,EAAE,KAAA,EAAO,OAAA,CAAQ,MAAA,EAAQ,CAAA;AACjG,IAAA,IAAI,OAAA,CAAQ,iBAAA,EAAmB,IAAA,CAAK,iBAAA,GAAoB,OAAA,CAAQ,iBAAA;AAChE,IAAA,IAAI,OAAA,CAAQ,SAAA,EAAW,IAAA,CAAK,SAAA,GAAY,OAAA,CAAQ,SAAA;AAChD,IAAA,IAAI,OAAA,CAAQ,QAAA,KAAa,MAAA,EAAW,IAAA,CAAK,WAAW,OAAA,CAAQ,QAAA;AAC5D,IAAA,IAAI,OAAA,CAAQ,aAAA,EAAe,IA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A,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"]}