Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Deivu/Shoukaku
Browse files Browse the repository at this point in the history
  • Loading branch information
Deivu committed Nov 7, 2023
2 parents e5ed32f + 89f335b commit cd1821d
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 19 deletions.
27 changes: 14 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,19 +208,20 @@ const ShoukakuOptions = {
```
### Shoukaku's options
| Option | Type | Description |
|------------------------|------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------|
| resume | boolean | Whether to resume a connection on disconnect to Lavalink (Server Side) (Note: DOES NOT RESUME WHEN THE LAVALINK SERVER DIES) |
| resumeTimeout | number | Timeout before resuming a connection **in seconds** |
| resumeByLibrary | boolean | Whether to resume the players by doing it in the library side (Client Side) (Note: TRIES TO RESUME REGARDLESS OF WHAT HAPPENED ON A LAVALINK SERVER) |
| reconnectTries | number | Number of times to try and reconnect to Lavalink before giving up |
| reconnectInterval | number | Timeout before trying to reconnect **in seconds** |
| restTimeout | number | Time to wait for a response from the Lavalink REST API before giving up **in seconds** |
| moveOnDisconnect | boolean | Whether to move players to a different Lavalink node when a node disconnects |
| userAgent | string | User Agent to use when making requests to Lavalink |
| structures | Object{rest?, player?} | Custom structures for shoukaku to use |
| voiceConnectionTimeout | number | Timeout before abort connection **in seconds** |\
| nodeResolver | function(nodes, con) | Custom node resolver if you want to have your own method of getting the ideal node
| Option | Type | Default | Description |
|------------------------|------------------------|----------|------------------------------------------------------------------------------------------------------------------------------------------------------|
| resume | boolean | false | Whether to resume a connection on disconnect to Lavalink (Server Side) (Note: DOES NOT RESUME WHEN THE LAVALINK SERVER DIES) |
| resumeTimeout | number | 30 | Timeout before resuming a connection **in seconds** |
| resumeByLibrary | boolean | false | Whether to resume the players by doing it in the library side (Client Side) (Note: TRIES TO RESUME REGARDLESS OF WHAT HAPPENED ON A LAVALINK SERVER) |
| reconnectTries | number | 3 | Number of times to try and reconnect to Lavalink before giving up |
| reconnectInterval | number | 5 | Timeout before trying to reconnect **in seconds** |
| restTimeout | number | 60 | Time to wait for a response from the Lavalink REST API before giving up **in seconds** |
| moveOnDisconnect | boolean | false | Whether to move players to a different Lavalink node when a node disconnects |
| userAgent | string | (auto) | User Agent to use when making requests to Lavalink |
| structures | Object{rest?, player?} | {} | Custom structures for shoukaku to use |
| voiceConnectionTimeout | number | 15 | Timeout before abort connection **in seconds** |
| nodeResolver | function | function | Custom node resolver if you want to have your own method of getting the ideal node |
### Plugins list
> Open a pr to add your plugin here
Expand Down
19 changes: 15 additions & 4 deletions src/guild/Connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class Connection extends EventEmitter {
*/
public setDeaf(deaf = false): void {
this.deafened = deaf;
this.send({ guild_id: this.guildId, channel_id: this.channelId, self_deaf: this.deafened, self_mute: this.muted });
this.sendVoiceUpdate();
}

/**
Expand All @@ -118,7 +118,7 @@ export class Connection extends EventEmitter {
*/
public setMute(mute = false): void {
this.muted = mute;
this.send({ guild_id: this.guildId, channel_id: this.channelId, self_deaf: this.deafened, self_mute: this.muted });
this.sendVoiceUpdate();
}

/**
Expand All @@ -127,7 +127,10 @@ export class Connection extends EventEmitter {
*/
public disconnect(): void {
if (this.state === State.DISCONNECTED) return;
this.send({ guild_id: this.guildId, channel_id: null, self_mute: false, self_deaf: false });
this.channelId = null;
this.deafened = false;
this.muted = false;
this.sendVoiceUpdate();
this.state = State.DISCONNECTED;
this.debug(`[Voice] -> [Node] & [Discord] : Connection Destroyed | Guild: ${this.guildId}`);
}
Expand All @@ -140,7 +143,7 @@ export class Connection extends EventEmitter {
if (this.state === State.CONNECTING || this.state === State.CONNECTED) return;

this.state = State.CONNECTING;
this.send({ guild_id: this.guildId, channel_id: this.channelId, self_deaf: this.deafened, self_mute: this.muted });
this.sendVoiceUpdate();
this.debug(`[Voice] -> [Discord] : Requesting Connection | Guild: ${this.guildId}`);

const controller = new AbortController();
Expand Down Expand Up @@ -219,6 +222,14 @@ export class Connection extends EventEmitter {
this.debug(`[Voice] <- [Discord] : Server Update Received | Server: ${this.region} Guild: ${this.guildId}`);
}

/**
* Send voice data to discord
* @internal
*/
private sendVoiceUpdate() {
this.send({ guild_id: this.guildId, channel_id: this.channelId, self_deaf: this.deafened, self_mute: this.muted });
}

/**
* Send data to Discord
* @param data The data to send
Expand Down
36 changes: 36 additions & 0 deletions src/node/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,37 @@ export interface NodeStats {
uptime: number;
}

type NodeInfoVersion = {
semver: string;
major: number;
minor: number;
patch: number;
preRelease?: string;
build?: string;
};

type NodeInfoGit = {
branch: string;
commit: string;
commitTime: number;
};

type NodeInfoPlugin = {
name: string;
version: string;
};

export type NodeInfo = {
version: NodeInfoVersion;
buildTime: number;
git: NodeInfoGit;
jvm: string;
lavaplayer: string;
sourceManagers: string[];
filters: string[];
plugins: NodeInfoPlugin[];
};

export interface ResumableHeaders {
[key: string]: string;
'Client-Name': string;
Expand Down Expand Up @@ -84,6 +115,10 @@ export class Node extends EventEmitter {
* Statistics from Lavalink
*/
public stats: NodeStats|null;
/**
* Information about lavalink node
*/
public info: NodeInfo|null;
/**
* Websocket instance
*/
Expand Down Expand Up @@ -121,6 +156,7 @@ export class Node extends EventEmitter {
this.reconnects = 0;
this.state = State.DISCONNECTED;
this.stats = null;
this.info = null;
this.ws = null;
this.sessionId = null;
this.initialized = false;
Expand Down
17 changes: 15 additions & 2 deletions src/node/Rest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Node, NodeStats } from './Node';
import { Node, NodeInfo, NodeStats } from './Node';
import { NodeOption } from '../Shoukaku';
import { Versions } from '../Constants';
import { FilterOptions } from '../guild/Player';
Expand Down Expand Up @@ -122,7 +122,7 @@ export interface UpdatePlayerOptions {
endTime?: number;
volume?: number;
paused?: boolean;
filters?: FilterOptions;
filters?: FilterOptions;
voice?: LavalinkPlayerVoiceOptions;
}

Expand Down Expand Up @@ -333,6 +333,19 @@ export class Rest {
await this.fetch(options);
}

/**
* Get Lavalink info
*/
public getLavalinkInfo(): Promise<NodeInfo|undefined> {
const options = {
endpoint: '/info',
options: {
headers: { 'Content-Type': 'application/json' }
}
};
return this.fetch(options);
}

/**
* Make a request to Lavalink
* @param fetchOptions.endpoint Lavalink endpoint
Expand Down

0 comments on commit cd1821d

Please sign in to comment.