diff --git a/.gitignore b/.gitignore index c5491be..12bf8ef 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ node_modules/ yarn.lock -yarn-error.log \ No newline at end of file +yarn-error.log + +.vscode \ No newline at end of file diff --git a/README.md b/README.md index 56f9fa9..6c0a498 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,42 @@ lavadeno banner -

Lavadeno

+
+
+ A powerful lavalink client built on the Deno Runtime +

Discord ServerGithub

+
-A powerful lavalink client built on the [Deno](https://deno.land/) Runtime +- **Flexible**: Lavadeno is not restricted to a specific discord library. Meaning you only need a connection to the discord gateway for it to work. +- **Easy-to-Use**: Lavadeno has a neat and user-friendly promise-based api. +- **Lightweight**: Designed to be small and performant, it's a great choice for any sized project. + +

Setup

+ +- Deno 1.3.x +- Lavalink + - [Official](https://github.com/frederikam/lavalink) + - [With Filters (Unofficial)](https://github.com/melike2d/lavalink/) +- Connection to the Discord Gateway. + +```ts +import { Manager } from "https://deno.land/x/lavadeno/mod.ts"; + +const nodes = [ + { + id: "main", + host: "localhost", + port: 2333, + password: "youshallnotpass" + } +] + +const manager = new Manager(nodes, { + send(id, payload) { + sendPayloadToDiscord(); + } +}); +``` + +--- + +

melike2d © 2020

diff --git a/mod.ts b/mod.ts index 1b64dd3..b423e35 100644 --- a/mod.ts +++ b/mod.ts @@ -1,5 +1,5 @@ -export * from "./src/@types/track.d.ts"; -export * from "./src/@types/player.d.ts"; +export type { Track, TrackInfo, LoadTracksException, LoadTracksResponse, LoadType } from "./src/@types/track.d.ts"; +export type { PlayTrack, PlayerEvent, PlayerEventType, PlayerRequest, PlayerState, PlayerUpdate } from "./src/@types/player.d.ts"; export * from "./src/api/Socket.ts"; export * from "./src/api/Player.ts"; export * from "./src/Manager.ts"; diff --git a/src/@types/track.d.ts b/src/@types/track.d.ts index d9a8f48..4abf573 100644 --- a/src/@types/track.d.ts +++ b/src/@types/track.d.ts @@ -1,4 +1,4 @@ -import { Severity } from "./misc"; +import { Severity } from "./player.d.ts"; export type LoadType = "TRACK_LOADED" | "PLAYLIST_LOADED" | "SEARCH_RESULT" | "NO_MATCHES" | "LOAD_FAILED" @@ -33,4 +33,4 @@ export interface TrackInfo { position: number; title: string; uri: string; -} \ No newline at end of file +} diff --git a/src/Manager.ts b/src/Manager.ts index c3a53f0..4e51265 100644 --- a/src/Manager.ts +++ b/src/Manager.ts @@ -1,10 +1,9 @@ import { EventEmitter } from "https://deno.land/std@0.66.0/node/events.ts"; import { WebSocketCloseEvent } from "https://deno.land/std@0.66.0/ws/mod.ts"; -import { soxa } from "https://deno.land/x/soxa/mod.ts" import { Socket, SocketData } from "./api/Socket.ts"; import { Player } from "./api/Player.ts"; -import type { LoadTracksResponse } from "./@types"; +import type { LoadTracksResponse } from "./@types/track.d.ts"; const defaults = { resuming: { key: Math.random().toString(32), timeout: 60000 }, @@ -184,15 +183,17 @@ export class Manager extends EventEmitter { * @param query The search query. */ public async search(query: string): Promise { - return new Promise(async (resolve, reject) => { - const socket = this.ideal[0]; - if (!socket) - throw new Error("Manager#create(): No available sockets.") - - soxa.get(`http${socket.secure ? "s" : ""}://${socket.address}/loadtracks?identifier=${query}`) - .then((r) => resolve(r.data)) - .catch(e => reject(e)); + const socket = this.ideal[0]; + if (!socket) + throw new Error("Manager#create(): No available sockets.") + + const resp = await fetch(`http${socket.secure ? "s" : ""}://${socket.address}/loadtracks?identifier=${encodeURIComponent(query ?? '')}`, { + headers: { Authorization: socket.password ?? 'youshallnotpass' }, + method: 'GET', }); + + const data = await resp.json(); + return data; } } @@ -247,7 +248,7 @@ export interface ManagerOptions { reconnect?: ReconnectOptions; } -export interface ReconnectOptions { +interface ReconnectOptions { /** * The total amount of reconnect tries */ diff --git a/src/api/Player.ts b/src/api/Player.ts index 43bc478..db7baa8 100644 --- a/src/api/Player.ts +++ b/src/api/Player.ts @@ -12,7 +12,7 @@ import type { TrackStartEvent, TrackStuckEvent, WebSocketClosedEvent -} from "../@types"; +} from "../@types/index.d.ts"; export class Player extends EventEmitter { /** diff --git a/src/api/Socket.ts b/src/api/Socket.ts index 2318e49..c509c0b 100644 --- a/src/api/Socket.ts +++ b/src/api/Socket.ts @@ -9,7 +9,23 @@ import { import { Buffer } from "https://deno.land/std@0.66.0/node/buffer.ts"; import type { Manager } from "../Manager.ts"; -import type { ReconnectOptions } from "../../../lavaclient/src"; + +export interface ReconnectOptions { + /** + * The total amount of reconnect tries + */ + maxTries?: number; + + /** + * Whether or not reconnection's are automatically done. + */ + auto?: boolean; + + /** + * The delay between socket reconnection's. + */ + delay?: number; +} export enum Status { CONNECTED, @@ -397,4 +413,4 @@ export interface NodeStats { nulled?: number; deficit?: number; }; -} \ No newline at end of file +}