UNPKG

leref.ts

Version:

Something upcoming for aoi.js and npm packages uses

79 lines (78 loc) 2.62 kB
import WebSocket from "ws"; import { Pool } from "undici"; import { LerefLava } from "./lerefLava"; import { TypedEmitter } from "tiny-typed-emitter"; import { NodeOptions, NodeStats } from "../utils"; import { IncomingPayloads, EventPayloads, PlayerUpdatePayload, OutgoingPayloads } from "../utils"; import { ResponseData } from "undici/types/dispatcher"; import { LerefRoutes } from "./lerefRoutes"; export interface NodeEvents { /** Emitted when node is destroyed */ destroy(): void; /** Emitted when node connects */ connect(): void; /** Emitted when node reconnects */ reconnect(): void; /** Emitted when node disconnects */ disconnect(reason: { code: number; reason: string; }): void; /** Emitted when node has an error */ error(error: Error): void; /** Emitted whenever any Lavalink incoming message is received */ raw(payload: IncomingPayloads): void; /** Emitted whenever any Lavalink event is received */ event(payload: EventPayloads): void; /** Emitted whenever playerUpdate is received */ playerUpdate(guildID: string, state: PlayerUpdatePayload["state"]): void; } export declare class LerefNodes extends TypedEmitter<NodeEvents> { readonly lava: LerefLava; /** The node options */ options: NodeOptions; /** The node stats */ stats: NodeStats; /** The node websocket if connected */ socket?: WebSocket; /** Sums of http request calls since created */ calls: number; /** Whether the node already connected via websocket */ connected: boolean; /** Whether the node is resumed from previous session */ resumed: boolean; /** The http clients pool for http calls */ readonly http: Pool; /** THe routePlanner instance to manage route planners */ readonly routePlanner: LerefRoutes; private reconnectTimeout?; private reconnectAttempts; constructor(lava: LerefLava, options: NodeOptions); /** * Do http(s) request to the node */ request<T>(endpoint: string): Promise<T>; /** * Do http(s) post request to the node */ post(endpoint: string, body?: unknown, raw?: boolean): Promise<ResponseData | unknown>; /** * Connect to the node via socket */ connect(): void; /** * Destroy the node connection */ destroy(): void; /** * Send data to the node */ send(data: OutgoingPayloads): Promise<boolean>; /** Configure the resume config */ configResume(): void; private reconnect; private open; private close; private error; private message; }