magmastream 2.2.3 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -338,6 +338,16 @@ interface Track {
338
338
  readonly requester: unknown | null;
339
339
  /** Displays the track thumbnail with optional size or null if it's a unsupported source. */
340
340
  displayThumbnail(size?: Sizes): string;
341
+ /** Additional track info provided by plugins. */
342
+ pluginInfo: TrackPluginInfo;
343
+ }
344
+ interface TrackPluginInfo {
345
+ albumName?: string;
346
+ albumUrl?: string;
347
+ artistArtworkUrl?: string;
348
+ artistUrl?: string;
349
+ isPreview?: string;
350
+ previewUrl?: string;
341
351
  }
342
352
  /** Unresolved tracks can't be played normally, they will resolve before playing into a Track. */
343
353
  interface UnresolvedTrack extends Partial<Track> {
@@ -433,8 +443,6 @@ declare class Node {
433
443
  options: NodeOptions;
434
444
  /** The socket for the node. */
435
445
  socket: WebSocket | null;
436
- /** The amount of rest calls the node has made. */
437
- calls: number;
438
446
  /** The stats for the node. */
439
447
  stats: NodeStats;
440
448
  manager: Manager;
@@ -609,8 +617,8 @@ interface TrackData {
609
617
  encoded: string;
610
618
  /** The detailed information of the track. */
611
619
  info: TrackDataInfo;
612
- /** Addition track info provided by plugins. */
613
- pluginInfo: object;
620
+ /** Additional track info provided by plugins. */
621
+ pluginInfo: Record<string, string>;
614
622
  }
615
623
  interface TrackDataInfo {
616
624
  identifier: string;
@@ -812,10 +820,8 @@ declare class Manager extends EventEmitter {
812
820
  /** The options that were set. */
813
821
  readonly options: ManagerOptions;
814
822
  private initiated;
815
- /** Returns the least used Nodes. */
816
- get leastUsedNodes(): Collection<string, Node>;
817
- /** Returns the least system load Nodes. */
818
- get leastLoadNodes(): Collection<string, Node>;
823
+ /** Returns the nodes that has the least amount of players. */
824
+ get leastPlayersNodes(): Collection<string, Node>;
819
825
  /**
820
826
  * Initiates the Manager class.
821
827
  * @param options
@@ -946,4 +952,4 @@ interface PlaylistData {
946
952
  tracks: Track[];
947
953
  }
948
954
 
949
- export { CPUStats, EqualizerBand, Exception, Extendable, FrameStats, LavalinkResponse, LoadType, Manager, ManagerOptions, MemoryStats, Node, NodeMessage, NodeOptions, NodeStats, NowPlayingMessage, Payload, PlayOptions, Player, PlayerEvent, PlayerEventType, PlayerEvents, PlayerOptions, PlayerUpdate, PlaylistData, PlaylistRawData, Plugin, Queue, SearchPlatform, SearchQuery, SearchResult, Severity, Sizes, State, Structure, Track, TrackData, TrackDataInfo, TrackEndEvent, TrackEndReason, TrackExceptionEvent, TrackStartEvent, TrackStuckEvent, TrackUtils, UnresolvedQuery, UnresolvedTrack, VoicePacket, VoiceServer, VoiceState, WebSocketClosedEvent };
955
+ export { type CPUStats, type EqualizerBand, type Exception, type Extendable, type FrameStats, type LavalinkResponse, type LoadType, Manager, type ManagerOptions, type MemoryStats, Node, type NodeMessage, type NodeOptions, type NodeStats, type NowPlayingMessage, type Payload, type PlayOptions, Player, type PlayerEvent, type PlayerEventType, type PlayerEvents, type PlayerOptions, type PlayerUpdate, type PlaylistData, type PlaylistRawData, Plugin, Queue, type SearchPlatform, type SearchQuery, type SearchResult, type Severity, type Sizes, type State, Structure, type Track, type TrackData, type TrackDataInfo, type TrackEndEvent, type TrackEndReason, type TrackExceptionEvent, type TrackPluginInfo, type TrackStartEvent, type TrackStuckEvent, TrackUtils, type UnresolvedQuery, type UnresolvedTrack, type VoicePacket, type VoiceServer, type VoiceState, type WebSocketClosedEvent };
@@ -25,25 +25,11 @@ class Manager extends events_1.EventEmitter {
25
25
  /** The options that were set. */
26
26
  options;
27
27
  initiated = false;
28
- /** Returns the least used Nodes. */
29
- get leastUsedNodes() {
28
+ /** Returns the nodes that has the least amount of players. */
29
+ get leastPlayersNodes() {
30
30
  return this.nodes
31
31
  .filter((node) => node.connected)
32
- .sort((a, b) => b.calls - a.calls);
33
- }
34
- /** Returns the least system load Nodes. */
35
- get leastLoadNodes() {
36
- return this.nodes
37
- .filter((node) => node.connected)
38
- .sort((a, b) => {
39
- const aload = a.stats.cpu
40
- ? (a.stats.cpu.systemLoad / a.stats.cpu.cores) * 100
41
- : 0;
42
- const bload = b.stats.cpu
43
- ? (b.stats.cpu.systemLoad / b.stats.cpu.cores) * 100
44
- : 0;
45
- return aload - bload;
46
- });
32
+ .sort((a, b) => a.stats.players - b.stats.players);
47
33
  }
48
34
  /**
49
35
  * Initiates the Manager class.
@@ -118,7 +104,7 @@ class Manager extends events_1.EventEmitter {
118
104
  * @returns The search result.
119
105
  */
120
106
  async search(query, requester) {
121
- const node = this.leastUsedNodes.first();
107
+ const node = this.leastPlayersNodes.first();
122
108
  if (!node) {
123
109
  throw new Error("No available nodes.");
124
110
  }
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Node = void 0;
4
4
  const tslib_1 = require("tslib");
5
- /* eslint-disable no-case-declarations */
6
5
  const Utils_1 = require("./Utils");
7
6
  const Rest_1 = require("./Rest");
8
7
  const nodeCheck_1 = tslib_1.__importDefault(require("../utils/nodeCheck"));
@@ -11,8 +10,6 @@ class Node {
11
10
  options;
12
11
  /** The socket for the node. */
13
12
  socket = null;
14
- /** The amount of rest calls the node has made. */
15
- calls = 0;
16
13
  /** The stats for the node. */
17
14
  stats;
18
15
  manager;
@@ -90,7 +90,7 @@ class Player {
90
90
  if (options.textChannel)
91
91
  this.textChannel = options.textChannel;
92
92
  const node = this.manager.nodes.get(options.node);
93
- this.node = node || this.manager.leastLoadNodes.first();
93
+ this.node = node || this.manager.leastPlayersNodes.first();
94
94
  if (!this.node)
95
95
  throw new RangeError("No available nodes.");
96
96
  this.manager.players.set(options.guild, this);
@@ -96,6 +96,14 @@ class TrackUtils {
96
96
  : null;
97
97
  },
98
98
  requester,
99
+ pluginInfo: {
100
+ albumName: data.pluginInfo?.albumName,
101
+ albumUrl: data.pluginInfo?.albumUrl,
102
+ artistArtworkUrl: data.pluginInfo?.artistArtworkUrl,
103
+ artistUrl: data.pluginInfo?.artistUrl,
104
+ isPreview: data.pluginInfo?.isPreview,
105
+ previewUrl: data.pluginInfo?.previewUrl,
106
+ },
99
107
  };
100
108
  track.displayThumbnail = track.displayThumbnail.bind(track);
101
109
  if (this.trackPartial) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "magmastream",
3
- "version": "2.2.3",
3
+ "version": "2.3.0",
4
4
  "description": "A user-friendly Lavalink client designed for NodeJS.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -14,25 +14,25 @@
14
14
  "ci": "run-s lint build types"
15
15
  },
16
16
  "devDependencies": {
17
- "@favware/rollup-type-bundler": "^2.0.0",
18
- "@types/lodash": "^4.14.197",
19
- "@types/node": "^20.5.7",
20
- "@types/ws": "^8.5.3",
21
- "@typescript-eslint/eslint-plugin": "^6.5.0",
22
- "@typescript-eslint/parser": "^6.5.0",
23
- "eslint": "^8.48.0",
24
- "npm-run-all": "^1.7.0",
25
- "typedoc": "^0.24.8",
17
+ "@favware/rollup-type-bundler": "^3.2.1",
18
+ "@types/lodash": "^4.14.202",
19
+ "@types/node": "^20.11.0",
20
+ "@types/ws": "^8.5.10",
21
+ "@typescript-eslint/eslint-plugin": "^6.18.1",
22
+ "@typescript-eslint/parser": "^6.18.1",
23
+ "eslint": "^8.56.0",
24
+ "npm-run-all": "^1.8.0",
25
+ "typedoc": "^0.25.7",
26
26
  "typedoc-plugin-no-inherit": "^1.4.0",
27
- "typescript": "^5.1.6"
27
+ "typescript": "^5.3.3"
28
28
  },
29
29
  "dependencies": {
30
- "@discordjs/collection": "^1.5.3",
31
- "axios": "^1.4.0",
30
+ "@discordjs/collection": "^2.0.0",
31
+ "axios": "^1.6.5",
32
32
  "events": "^3.3.0",
33
33
  "lodash": "^4.17.21",
34
- "tslib": "^2.6.1",
35
- "ws": "^8.8.1"
34
+ "tslib": "^2.6.2",
35
+ "ws": "^8.16.0"
36
36
  },
37
37
  "engines": {
38
38
  "node": ">=16.0.0"