Comparing version 0.2.2 to 1.0.0
@@ -141,4 +141,4 @@ declare module 'shoukaku' { | ||
public timeout: number; | ||
public auth: string; | ||
public url: string; | ||
private auth: string; | ||
public resolve(identifier: string, search: Source): Promise<LoadTrackResponse | Track | Track[] | null>; | ||
@@ -242,3 +242,3 @@ public decode(track: Base64String): Promise<unknown>; | ||
public name: string; | ||
private url: string; | ||
public url: string; | ||
private auth: string; | ||
@@ -250,4 +250,4 @@ private resumed: boolean; | ||
public resumable: boolean; | ||
public resumableTimeout: number; | ||
private resumable: boolean; | ||
private resumableTimeout: number; | ||
public penalties: number; | ||
@@ -296,6 +296,5 @@ public connect(id: string, shardCount: number, resumable: boolean | string): void; | ||
public options: ShoukakuOptions; | ||
public init: boolean; | ||
private options: ShoukakuOptions; | ||
public build(nodes: ShoukakuNodeOptions[], options: ShoukakuBuildOptions): void; | ||
public start(nodes: ShoukakuNodeOptions[], options: ShoukakuBuildOptions): void; | ||
public addNode(nodeOptions: ShoukakuNodeOptions): void; | ||
@@ -302,0 +301,0 @@ public removeNode(name: string, libraryInvoked?: boolean): void; |
{ | ||
"name": "shoukaku", | ||
"version": "0.2.2", | ||
"version": "1.0.0", | ||
"description": "A lavalink client for Discord.js v12 only", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# Shoukaku | ||
<p align="center"> | ||
<img src="https://vignette.wikia.nocookie.net/kancolle/images/b/b3/Shoukaku_Christmas_Full_Damaged.png/revision/latest/"> | ||
<img src="https://vignette.wikia.nocookie.net/kancolle/images/c/c8/Shoukaku_Full.png/revision/latest"> | ||
</p> | ||
@@ -40,3 +40,15 @@ | ||
### 0.1.1 -> 0.2.0 Migration | ||
### 0.2.x -> 1.0.x Migration | ||
> 0.2.x and earlier | ||
```js | ||
<Shoukaku>.build({ /* buildOptions here */ }); | ||
``` | ||
> 1.0.0 and newer | ||
```js | ||
<Shoukaku>.start({ /* buildOptions here */ }); | ||
``` | ||
### 0.1.x -> 0.2.x Migration | ||
> ShoukakuLink is now a property of ShoukakuPlayer, meaning all link related getters are changed to player getters. | ||
@@ -65,11 +77,15 @@ | ||
> You don't disconnect / clean the player on ShoukakuLink but on ShoukakuPlayer now making your code more clean and better | ||
> 0.1.1 and earlier | ||
```js | ||
// 0.1.1 and earlier versions | ||
ShoukakuLink.player.playTrack(); | ||
ShoukakuLink.disconnect(); | ||
// 0.2.0 | ||
ShoukakuPlayer.playTrack(); | ||
ShoukakuPlayer.disconnect(); | ||
<ShoukakuLink>.player.playTrack(); | ||
<ShoukakuLink>.disconnect(); | ||
``` | ||
> 0.2.x and newer | ||
```js | ||
<ShoukakuPlayer>.playTrack(); | ||
<ShoukakuPlayer>.disconnect(); | ||
``` | ||
You can see more of the changes on updated example below. | ||
@@ -88,12 +104,2 @@ | ||
### Task List | ||
- [x] Base Logic | ||
- [x] Player & Voice Logic | ||
- [x] Load Balancing Logic | ||
- [x] Node Removal Logic | ||
- [x] Reconnect Logic | ||
- [x] Resuming Logic | ||
- [x] Documentation | ||
- and some more to come. | ||
### Starting a Lavalink Server. | ||
@@ -138,3 +144,3 @@ [View Lavalink README here](https://github.com/Frederikam/Lavalink/blob/master/README.md) | ||
// You need to build shoukaku on your client's ready event for her to work like how its done in this example. | ||
Carrier.build(MyLavalinkServer, { id: client.user.id }); | ||
Carrier.start(MyLavalinkServer, { id: client.user.id }); | ||
console.log('Bot Initialized'); | ||
@@ -141,0 +147,0 @@ }) |
@@ -89,2 +89,3 @@ const { ShoukakuStatus } = require('../constants/ShoukakuConstants.js'); | ||
this._callback = callback; | ||
if (this.state === ShoukakuStatus.CONNECTING) { | ||
@@ -123,6 +124,3 @@ this._callback(new ShoukakuError('Can\'t connect while a connection is connecting. Wait for it to resolve first')); | ||
_send(d) { | ||
this.node.shoukaku.send({ | ||
op:4, | ||
d | ||
}); | ||
this.node.shoukaku.send({ op: 4, d }); | ||
} | ||
@@ -137,18 +135,11 @@ | ||
_destroy() { | ||
this.node.send({ | ||
op: 'destroy', | ||
guildId: this.guildID | ||
}).catch(() => null); | ||
this.node.send({ op: 'destroy', guildId: this.guildID }) | ||
.catch(() => null); | ||
} | ||
_voiceUpdate(event) { | ||
this.node.send({ | ||
op: 'voiceUpdate', | ||
guildId: this.guildID, | ||
sessionId: this.sessionID, | ||
event | ||
}) | ||
this.node.send({ op: 'voiceUpdate', guildId: this.guildID, sessionId: this.sessionID, event }) | ||
.then(() => { | ||
if (this._timeout) clearTimeout(this._timeout); | ||
if (this.state !== ShoukakuStatus.CONNECTING) return; | ||
clearTimeout(this._timeout); | ||
this.state = ShoukakuStatus.CONNECTED; | ||
@@ -158,9 +149,9 @@ this._callback(null, this.player); | ||
.catch((error) => { | ||
if (this.state === ShoukakuStatus.CONNECTING) { | ||
clearTimeout(this._timeout); | ||
this.state = ShoukakuStatus.DISCONNECTED; | ||
this._callback(error); | ||
if (this._timeout) clearTimeout(this._timeout); | ||
if (this.state !== ShoukakuStatus.CONNECTING) { | ||
this.player._listen('error', error); | ||
return; | ||
} | ||
this.player._listen('error', error); | ||
this.state = ShoukakuStatus.DISCONNECTED; | ||
this._callback(error); | ||
}) | ||
@@ -167,0 +158,0 @@ .finally(() => { |
@@ -57,4 +57,8 @@ const { ShoukakuStatus, ShoukakuNodeStats, ShoukakuJoinOptions } = require('../constants/ShoukakuConstants.js'); | ||
this.name = node.name; | ||
/** | ||
* URL of the websocket used in this node. | ||
* @type {string} | ||
*/ | ||
this.url = `ws://${node.host}:${node.port}`; | ||
Object.defineProperty(this, 'url', { value: `ws://${node.host}:${node.port}` }); | ||
Object.defineProperty(this, 'auth', { value: node.auth }); | ||
@@ -61,0 +65,0 @@ Object.defineProperty(this, 'resumed', { value: false, writable: true }); |
@@ -24,2 +24,7 @@ const Fetch = require('node-fetch'); | ||
/** | ||
* URL of the host used by this resolver instance. | ||
* @type {string} | ||
*/ | ||
this.url = `http://${host}:${port}/`; | ||
/** | ||
* This Resolver Timeout before it decides to cancel the request. | ||
@@ -31,3 +36,2 @@ * @type {number} | ||
Object.defineProperty(this, 'auth', { value: auth }); | ||
Object.defineProperty(this, 'url', { value: `http://${host}:${port}/` }); | ||
} | ||
@@ -34,0 +38,0 @@ /** |
@@ -50,3 +50,6 @@ const { ShoukakuStatus } = require('../constants/ShoukakuConstants.js'); | ||
if (!player) return; | ||
if (json.op === 'playerUpdate') return player._listen('playerUpdate', json.state); | ||
if (json.op === 'playerUpdate') { | ||
player._listen('playerUpdate', json.state); | ||
return; | ||
} | ||
if (json.op === 'event') { | ||
@@ -53,0 +56,0 @@ switch (json.type) { |
@@ -60,3 +60,2 @@ const { RawRouter, ReconnectRouter } = require('./router/ShoukakuRouter.js'); | ||
Object.defineProperty(this, 'options', { value: this._mergeDefault(constants.ShoukakuOptions, options) }); | ||
Object.defineProperty(this, 'init', { value: true, writable: true }); | ||
Object.defineProperty(this, 'rawRouter', { value: RawRouter.bind(this) }); | ||
@@ -129,4 +128,5 @@ Object.defineProperty(this, 'reconnectRouter', { value: ReconnectRouter.bind(this) }); | ||
*/ | ||
build(nodes, options) { | ||
if (!this.init) throw new ShoukakuError('You cannot build Shoukaku twice'); | ||
start(nodes, options) { | ||
if (this.id) | ||
throw new ShoukakuError('You already started Shoukaku, you don\'t need to start her again.'); | ||
options = this._mergeDefault(constants.ShoukakuBuildOptions, options); | ||
@@ -141,3 +141,2 @@ this.id = options.id; | ||
this.client.on('shardReady', this.reconnectRouter); | ||
this.init = false; | ||
} | ||
@@ -150,2 +149,4 @@ /** | ||
addNode(nodeOptions) { | ||
if (!this.id) | ||
throw new ShoukakuError('You didn\'t start Shoukaku once. Please call .start() method once before using this.'); | ||
const node = new ShoukakuSocket(this, nodeOptions); | ||
@@ -168,2 +169,4 @@ node.connect(this.id, this.shardCount, false); | ||
removeNode(name, libraryInvoked = false) { | ||
if (!this.id) | ||
throw new ShoukakuError('You didn\'t start Shoukaku once. Please call .start() method once before using this.'); | ||
const node = this.nodes.get(name); | ||
@@ -192,2 +195,4 @@ if (!node) return false; | ||
getNode(name) { | ||
if (!this.id) | ||
throw new ShoukakuError('You didn\'t start Shoukaku once. Please call .start() method once before using this.'); | ||
if (!this.nodes.size) | ||
@@ -208,2 +213,4 @@ throw new ShoukakuError('No nodes available. What happened?'); | ||
getPlayer(guildID) { | ||
if (!this.id) | ||
throw new ShoukakuError('You didn\'t start Shoukaku once. Please call .start() method once before using this.'); | ||
if (!guildID) return null; | ||
@@ -210,0 +217,0 @@ if (!this.nodes.size) return null; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
61811
1426
1
190