Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Lavaclient/lavadeno
Browse files Browse the repository at this point in the history
  • Loading branch information
MeLike2D committed Mar 1, 2021
2 parents 0467827 + d3d22db commit a14afa2
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 21 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
node_modules/

yarn.lock
yarn-error.log
yarn-error.log

.vscode
41 changes: 39 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,42 @@
<img align="center" src="./assets/banner.png" alt="lavadeno banner">
<h1 align="center">Lavadeno</h1>
<hr />
<blockquote>
A powerful lavalink client built on the <strong>Deno</strong> Runtime
<p><a href="https://discord.gg/vuJxnYk">Discord Server</a> &bull; <a href="https://github.com/lavaclient/lavadeno">Github</a></p>
</blockquote>

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.


<h2 align="center">Setup</h2>

- 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();
}
});
```

---

<p align="center"><a href="https://melike2d.me">melike2d</a> &copy; 2020</p>
4 changes: 2 additions & 2 deletions mod.ts
Original file line number Diff line number Diff line change
@@ -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";
4 changes: 2 additions & 2 deletions src/@types/track.d.ts
Original file line number Diff line number Diff line change
@@ -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"

Expand Down Expand Up @@ -33,4 +33,4 @@ export interface TrackInfo {
position: number;
title: string;
uri: string;
}
}
23 changes: 12 additions & 11 deletions src/Manager.ts
Original file line number Diff line number Diff line change
@@ -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 },
Expand Down Expand Up @@ -184,15 +183,17 @@ export class Manager extends EventEmitter {
* @param query The search query.
*/
public async search(query: string): Promise<LoadTracksResponse> {
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;
}
}

Expand Down Expand Up @@ -247,7 +248,7 @@ export interface ManagerOptions {
reconnect?: ReconnectOptions;
}

export interface ReconnectOptions {
interface ReconnectOptions {
/**
* The total amount of reconnect tries
*/
Expand Down
2 changes: 1 addition & 1 deletion src/api/Player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type {
TrackStartEvent,
TrackStuckEvent,
WebSocketClosedEvent
} from "../@types";
} from "../@types/index.d.ts";

export class Player extends EventEmitter {
/**
Expand Down
20 changes: 18 additions & 2 deletions src/api/Socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -397,4 +413,4 @@ export interface NodeStats {
nulled?: number;
deficit?: number;
};
}
}

0 comments on commit a14afa2

Please sign in to comment.