Skip to content

Commit a34461c

Browse files
author
2D
authored
🔀 Merge pull request #4 from lavaclient/rewrite
Lavadeno's long-awaited rewrite
2 parents 97a29e9 + 6d8c46d commit a34461c

27 files changed

+1801
-1303
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ node_modules/
33
yarn.lock
44
yarn-error.log
55

6-
.vscode
6+
.vscode
7+
8+
*config.ts

.prettierrc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"arrowParens": "avoid",
3+
"endOfLine": "lf",
4+
"parser": "typescript",
5+
"semi": true,
6+
"quoteProps": "as-needed",
7+
"trailingComma": "es5",
8+
"useTabs": false,
9+
"bracketSpacing": true,
10+
"singleQuote": false,
11+
"tabWidth": 4,
12+
"printWidth": 100,
13+
"proseWrap": "preserve"
14+
}

README.md

Lines changed: 70 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,88 @@
55
<p><a href="https://discord.gg/CH9ubGPMV6">Discord Server</a> &bull; <a href="https://github.com/lavaclient/lavadeno">Github</a></p>
66
</blockquote>
77

8-
- **Flexible**: Lavadeno is not restricted to a specific discord library. Meaning you only need a connection to the discord gateway for it to work.
8+
- **Flexible:** Lavadeno is a generic library, meaning you can use it with just a connection to the discord gateway, no library restriction.
99
- **Easy-to-Use**: Lavadeno has a neat and user-friendly promise-based api.
10-
- **Lightweight**: Designed to be small and performant, it's a great choice for any sized project.
11-
10+
- **Lightweight:** Designed to be small and performant, it's a great choice for any sized project.
1211

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

15-
- Deno 1.3.x
14+
- Deno Runtime
1615
- Lavalink
1716
- [Official](https://github.com/freyacodes/lavalink)
1817
- [With Filters (Unofficial)](https://github.com/melike2d/lavalink/)
1918
- Connection to the Discord Gateway.
2019

20+
#### Single Node
21+
22+
```ts
23+
import { Node } from "https://deno.land/x/lavadeno/mod.ts";
24+
25+
const node = new Node({
26+
connection: {
27+
host: "localhost",
28+
port: 2333,
29+
password: "youshallnotpass",
30+
},
31+
sendGatewayPayload: (id, payload) => sendPayloadToDiscord(),
32+
});
33+
34+
node.on("connect", node => console.log(`now connected...`));
35+
36+
node.connect(870267613635309618n);
37+
```
38+
#### Multiple Nodes
39+
2140
```ts
22-
import { Manager } from "https://deno.land/x/lavadeno/mod.ts";
23-
24-
const nodes = [
25-
{
26-
id: "main",
27-
host: "localhost",
28-
port: 2333,
29-
password: "youshallnotpass"
30-
}
31-
]
32-
33-
const manager = new Manager(nodes, {
34-
send(id, payload) {
35-
sendPayloadToDiscord();
36-
}
41+
import { Cluster } from "https://deno.land/x/lavadeno/mod.ts";
42+
43+
const cluster = new Cluster({
44+
nodes: [
45+
{
46+
id: "main",
47+
host: "localhost",
48+
port: 2333,
49+
password: "youshallnotpass",
50+
},
51+
],
52+
sendGatewayPayload: (id, payload) => sendPayloadToDiscord(),
3753
});
54+
55+
cluster.on("nodeConnect", node => console.log(`node "${node.id}" is now connected...`));
56+
57+
cluster.init(870267613635309618n);
58+
```
59+
60+
### Resuming / Reconnecting
61+
62+
LavaDeno supports exponential backoff and basic reconnection types, along with *manual* reconnecting as reconnecting isn't automatic.
63+
64+
```ts
65+
const node = new Node({
66+
connection: {
67+
// resuming, a key must be supplied or else it wont work.
68+
resuming: {
69+
key: "lavad3n0ftw"
70+
},
71+
72+
// exponential backoff
73+
reconnect: {
74+
type: "exponential",
75+
maxDelay: 15000,
76+
initialDelay: 1000,
77+
tries: -1 // unlimited
78+
},
79+
80+
// basic
81+
reconnect: {
82+
type: "basic",
83+
delay: 5000.
84+
tries: 5
85+
},
86+
}
87+
})
3888
```
3989

4090
---
4191

42-
<p align="center"><a href="https://dimensional.fun">melike2d</a> &copy; 2020</p>
92+
<p align="center"><a href="https://dimensional.fun">melike2d</a> &copy; 2018 - 2021</p>

deps.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
export { EventEmitter } from "https://deno.land/[email protected]/node/events.ts";
2-
export type { WebSocketCloseEvent } from "https://deno.land/[email protected]/ws/mod.ts";
1+
export * as Lavalink from "https://deno.land/x/[email protected]/mod.ts";
2+
export * from "https://deno.land/x/[email protected]/mod.ts";
3+
export * from "https://deno.land/[email protected]/ws/mod.ts";

mod.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1-
export type { Track, TrackInfo, LoadTracksException, LoadTracksResponse, LoadType } from "./src/@types/track.d.ts";
2-
export type { PlayTrack, PlayerEvent, PlayerEventType, PlayerRequest, PlayerState, PlayerUpdate } from "./src/@types/player.d.ts";
3-
export * from "./src/api/Socket.ts";
4-
export * from "./src/api/Player.ts";
5-
export * from "./src/Manager.ts";
1+
export * from "./src/cluster.ts";
2+
export * from "./src/clusternode.ts";
3+
export * from "./src/connection.ts";
4+
export * from "./src/player.ts";
5+
export * from "./src/node.ts";
6+
export * from "./src/rest.ts";
7+
export * from "./src/routeplanner.ts";
8+
9+
export * from "./src/util/functions.ts";
10+
export * from "./src/util/nodestate.ts";
11+
export * from "./src/util/backoff.ts";
12+
export { default as constants } from "./src/util/constants.ts";

package.json

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/@types/index.d.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/@types/player.d.ts

Lines changed: 0 additions & 92 deletions
This file was deleted.

src/@types/track.d.ts

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)