Skip to content

Commit 9fed279

Browse files
committed
v2.7.6 - more nodelink features
1 parent dc4e605 commit 9fed279

File tree

4 files changed

+69
-2
lines changed

4 files changed

+69
-2
lines changed

docs/src/content/docs/extra/version-log.mdx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ Logs about the changed features.
99

1010
---
1111

12+
## **Version 2.7.6**
13+
14+
More NodeLink Specific / additional features added, in case you are using NodeLink.
15+
- Added `node.fetchConnectionMetrics()`, which returns the connection metrics of the node.
16+
- Added `node.info.isNodelink` to check wether the node is using NodeLink or Lavalink.
17+
- Added `node.stats.detailedStats` to check wether the node is using NodeLink or Lavalink.
18+
1219
## **Version 2.7.5**
1320

1421
- Add some private getters to minify the code a little

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lavalink-client",
3-
"version": "2.7.5",
3+
"version": "2.7.6",
44
"description": "Easy, flexible and feature-rich lavalink@v4 Client. Both for Beginners and Proficients.",
55
"main": "./dist/index.js",
66
"module": "./dist/index.mjs",

src/structures/Node.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import type { LavalinkTrack, PluginInfo, Track } from "./Types/Track";
1919
import type { NodeManager } from "./NodeManager";
2020

2121
import type {
22-
BaseNodeStats, LavalinkInfo, LavalinkNodeOptions, LyricsResult, ModifyRequest, NodeStats, SponsorBlockSegment
22+
BaseNodeStats, LavalinkInfo, LavalinkNodeOptions, LyricsResult, ModifyRequest, NodeLinkConnectionMetrics, NodeStats, SponsorBlockSegment
2323
} from "./Types/Node";
2424
/**
2525
* Lavalink Node creator class
@@ -51,6 +51,17 @@ export class LavalinkNode {
5151
used: 0,
5252
},
5353
uptime: 0,
54+
/** something from nodeLink https://nodelink.js.org/docs/differences#detailed-statistics */
55+
detailedStats: {
56+
api: {
57+
requests: {},
58+
errors: {},
59+
},
60+
sources: {},
61+
playback: {
62+
events: {},
63+
},
64+
},
5465
frameStats: {
5566
deficit: 0,
5667
nulled: 0,
@@ -875,6 +886,20 @@ export class LavalinkNode {
875886
return await this.request(`/stats`) as BaseNodeStats;
876887
}
877888

889+
/**
890+
* Request NodeLink connection metrics. https://nodelink.js.org/docs/differences#connection-metrics
891+
* @returns the connection metrics of the node
892+
*
893+
* @example
894+
* ```ts
895+
* const connectionMetrics = await player.node.fetchConnectionMetrics();
896+
* ```
897+
*/
898+
public async fetchConnectionMetrics(): Promise<NodeLinkConnectionMetrics> {
899+
if (this.info && !this.info.isNodelink) throw new Error("There is no Information about wether you are using NodeLink instead of Lavalink, so this function won't work");
900+
return await this.request(`/connection`) as NodeLinkConnectionMetrics;
901+
}
902+
878903
/**
879904
* Request Lavalink version.
880905
* @returns the current used lavalink version
@@ -1180,9 +1205,13 @@ export class LavalinkNode {
11801205
throw new Error(errorString);
11811206
}
11821207

1208+
// if it's a lavalink server this property will be undefined
1209+
this.info.isNodelink = !!this.info.isNodelink
1210+
11831211
this.NodeManager.emit("connect", this);
11841212
}
11851213

1214+
11861215
/** @private util function for handling closing events from websocket */
11871216
private close(code: number, reason: string): void {
11881217
this.resetAckTimeouts(true, true);

src/structures/Types/Node.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,41 @@ export interface BaseNodeStats {
9898
frameStats: FrameStats;
9999
}
100100

101+
export interface NodeLinkConnectionMetrics {
102+
status: string;
103+
metrics: {
104+
speed: {
105+
bps: number;
106+
kbps: number;
107+
mbps: number;
108+
};
109+
downloadedBytes: number;
110+
durationSeconds: number;
111+
timestamp: number;
112+
};
113+
}
101114
/**
102115
* Interface for nodeStats from lavalink
103116
*/
104117
export interface NodeStats extends BaseNodeStats {
105118
/** The frame stats for the node. */
106119
frameStats: FrameStats;
120+
/** something from nodeLink https://nodelink.js.org/docs/differences#detailed-statistics */
121+
detailedStats?: {
122+
api: {
123+
/** e.g. { "/v4/loadtracks": 150, "/v4/info": 5 } */
124+
requests: Record<string, number>;
125+
errors: unknown;
126+
};
127+
/** e.g. { "youtube": 150, "soundcloud": 5 } */
128+
sources: Record<string, number>;
129+
playback: {
130+
/** e.g. { "TrackStartEvent": 150, "TrackEndEvent": 5 } */
131+
events: Record<string, number>;
132+
};
133+
/** and potential others */
134+
[key: string]: unknown;
135+
},
107136
}
108137

109138
/**
@@ -126,6 +155,8 @@ export interface LavalinkInfo {
126155
filters: string[];
127156
/** The enabled plugins for this server */
128157
plugins: PluginObject[];
158+
/** Something from NodeLink: https://nodelink.js.org/docs/differences#server-info */
159+
isNodelink?: boolean;
129160
}
130161

131162
/**

0 commit comments

Comments
 (0)