lavalink-client 2.4.0 → 2.4.2

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.
@@ -150,7 +150,7 @@ class FilterManager {
150
150
  sendData.equalizer = [...this.equalizerBands];
151
151
  if (sendData.equalizer.length === 0)
152
152
  delete sendData.equalizer;
153
- for (const key of [...Object.keys(sendData)]) {
153
+ for (const key of Object.keys(sendData)) {
154
154
  // delete disabled filters
155
155
  if (key === "pluginFilters") {
156
156
  // for(const key of [...Object.keys(sendData.pluginFilters)]) {
@@ -181,7 +181,7 @@ class FilterManager {
181
181
  this.filters.rotation = this.data.rotation.rotationHz !== 0;
182
182
  this.filters.vibrato = this.data.vibrato.frequency !== 0 || this.data.vibrato.depth !== 0;
183
183
  this.filters.tremolo = this.data.tremolo.frequency !== 0 || this.data.tremolo.depth !== 0;
184
- const lavalinkFilterData = (this.data.pluginFilters?.["lavalink-filter-plugin"] || { echo: { decay: this.data.pluginFilters?.echo?.decay && !this.data.pluginFilters?.echo?.echoLength ? this.data.pluginFilters.echo.decay : 0, delay: this.data.pluginFilters?.echo?.delay || 0 }, reverb: { gains: [], delays: [], ...((this.data.pluginFilters.reverb) || {}) } });
184
+ const lavalinkFilterData = (this.data.pluginFilters?.["lavalink-filter-plugin"] || { echo: { decay: this.data.pluginFilters?.echo?.decay && !this.data.pluginFilters?.echo?.echoLength ? this.data.pluginFilters.echo.decay : 0, delay: this.data.pluginFilters?.echo?.delay || 0 }, reverb: { gains: [], delays: [], ...(this.data.pluginFilters.reverb) } });
185
185
  this.filters.lavalinkFilterPlugin.echo = lavalinkFilterData.echo.decay !== 0 || lavalinkFilterData.echo.delay !== 0;
186
186
  this.filters.lavalinkFilterPlugin.reverb = lavalinkFilterData.reverb?.delays?.length !== 0 || lavalinkFilterData.reverb?.gains?.length !== 0;
187
187
  this.filters.lavalinkLavaDspxPlugin.highPass = Object.values(this.data.pluginFilters["high-pass"] || {}).length > 0;
@@ -486,25 +486,37 @@ class LavalinkManager extends events_1.EventEmitter {
486
486
  if ("token" in update) {
487
487
  if (!player.node?.sessionId)
488
488
  throw new Error("Lavalink Node is either not ready or not up to date");
489
- await player.node.updatePlayer({
490
- guildId: player.guildId,
491
- playerOptions: {
492
- voice: {
493
- token: update.token,
494
- endpoint: update.endpoint,
495
- sessionId: player.voice?.sessionId,
496
- }
497
- }
498
- });
499
- if (this.options?.advancedOptions?.enableDebugEvents) {
489
+ const sessionId2Use = player.voice?.sessionId || ("sessionId" in update ? update.sessionId : undefined);
490
+ if (!sessionId2Use) {
500
491
  this.emit("debug", Constants_1.DebugEvents.NoAudioDebug, {
501
- state: "log",
502
- message: `Sent updatePlayer for voice token session :: ${JSON.stringify({ voice: { token: update.token, endpoint: update.endpoint, sessionId: player.voice?.sessionId, }, update }, null, 2)}`,
492
+ state: "error",
493
+ message: `Can't send updatePlayer for voice token session - Missing sessionId :: ${JSON.stringify({ voice: { token: update.token, endpoint: update.endpoint, sessionId: sessionId2Use, }, update, playerVoice: player.voice }, null, 2)}`,
503
494
  functionLayer: "LavalinkManager > sendRawData()",
504
495
  });
496
+ if (this.options?.advancedOptions?.debugOptions?.noAudio === true)
497
+ console.debug("Lavalink-Client-Debug | NO-AUDIO [::] sendRawData function, Sent updatePlayer for voice token session", { voice: { token: update.token, endpoint: update.endpoint, sessionId: sessionId2Use, }, playerVoice: player.voice, update });
498
+ }
499
+ else {
500
+ await player.node.updatePlayer({
501
+ guildId: player.guildId,
502
+ playerOptions: {
503
+ voice: {
504
+ token: update.token,
505
+ endpoint: update.endpoint,
506
+ sessionId: sessionId2Use,
507
+ }
508
+ }
509
+ });
510
+ if (this.options?.advancedOptions?.enableDebugEvents) {
511
+ this.emit("debug", Constants_1.DebugEvents.NoAudioDebug, {
512
+ state: "log",
513
+ message: `Sent updatePlayer for voice token session :: ${JSON.stringify({ voice: { token: update.token, endpoint: update.endpoint, sessionId: sessionId2Use, }, update, playerVoice: player.voice }, null, 2)}`,
514
+ functionLayer: "LavalinkManager > sendRawData()",
515
+ });
516
+ }
517
+ if (this.options?.advancedOptions?.debugOptions?.noAudio === true)
518
+ console.debug("Lavalink-Client-Debug | NO-AUDIO [::] sendRawData function, Can't send updatePlayer for voice token session - Missing sessionId", { voice: { token: update.token, endpoint: update.endpoint, sessionId: sessionId2Use, } });
505
519
  }
506
- if (this.options?.advancedOptions?.debugOptions?.noAudio === true)
507
- console.debug("Lavalink-Client-Debug | NO-AUDIO [::] sendRawData function, Sent updatePlayer for voice token session", { voice: { token: update.token, endpoint: update.endpoint, sessionId: player.voice?.sessionId, } });
508
520
  return;
509
521
  }
510
522
  /* voice state update */
@@ -526,7 +538,18 @@ class LavalinkManager extends events_1.EventEmitter {
526
538
  if (update.channel_id) {
527
539
  if (player.voiceChannelId !== update.channel_id)
528
540
  this.emit("playerMove", player, player.voiceChannelId, update.channel_id);
529
- player.voice.sessionId = update.session_id;
541
+ player.voice.sessionId = update.session_id || player.voice.sessionId;
542
+ if (!player.voice.sessionId) {
543
+ if (this.options?.advancedOptions?.enableDebugEvents) {
544
+ this.emit("debug", Constants_1.DebugEvents.NoAudioDebug, {
545
+ state: "warn",
546
+ message: `Function to assing sessionId provided, but no found in Payload: ${JSON.stringify({ update, playerVoice: player.voice }, null, 2)}`,
547
+ functionLayer: "LavalinkManager > sendRawData()",
548
+ });
549
+ }
550
+ if (this.options?.advancedOptions?.debugOptions?.noAudio === true)
551
+ console.debug(`Lavalink-Client-Debug | NO-AUDIO [::] sendRawData function, Function to assing sessionId provided, but no found in Payload: ${JSON.stringify(update, null, 2)}`);
552
+ }
530
553
  player.voiceChannelId = update.channel_id;
531
554
  const selfMuteChanged = typeof update.self_mute === "boolean" && player.voiceState.selfMute !== update.self_mute;
532
555
  const serverMuteChanged = typeof update.mute === "boolean" && player.voiceState.serverMute !== update.mute;
@@ -811,7 +811,7 @@ class LavalinkNode {
811
811
  * @returns boolean
812
812
  */
813
813
  syncPlayerData(data, res) {
814
- if (typeof data === "object" && typeof data?.guildId === "string" && typeof data.playerOptions === "object" && Object.keys(data.playerOptions).length > 1) {
814
+ if (typeof data === "object" && typeof data?.guildId === "string" && typeof data.playerOptions === "object" && Object.keys(data.playerOptions).length > 0) {
815
815
  const player = this.NodeManager.LavalinkManager.getPlayer(data.guildId);
816
816
  if (!player)
817
817
  return;
@@ -837,7 +837,7 @@ class LavalinkNode {
837
837
  }
838
838
  }
839
839
  if (typeof data.playerOptions.filters !== "undefined") {
840
- const oldFilterTimescale = { ...(player.filterManager.data.timescale || {}) };
840
+ const oldFilterTimescale = { ...player.filterManager.data.timescale };
841
841
  Object.freeze(oldFilterTimescale);
842
842
  if (data.playerOptions.filters.timescale)
843
843
  player.filterManager.data.timescale = data.playerOptions.filters.timescale;
@@ -230,7 +230,7 @@ export interface NodeManagerEvents {
230
230
  * Aka for that you need to be able to save player data like vc channel + text channel in a db and then sync it again
231
231
  * @event Manager.nodeManager#nodeResumed
232
232
  */
233
- "resumed": (node: LavalinkNode, paylaod: {
233
+ "resumed": (node: LavalinkNode, payload: {
234
234
  resumed: true;
235
235
  sessionId: string;
236
236
  op: "ready";
@@ -37,7 +37,7 @@ class ManagerUtils {
37
37
  buildPluginInfo(data, clientData = {}) {
38
38
  return {
39
39
  clientData: clientData,
40
- ...(data.pluginInfo || data.plugin || {})
40
+ ...(data.pluginInfo || data.plugin),
41
41
  };
42
42
  }
43
43
  buildTrack(data, requester) {
@@ -67,7 +67,7 @@ class ManagerUtils {
67
67
  isrc: data.info.isrc,
68
68
  },
69
69
  userData: {
70
- ...(data.userData || {}),
70
+ ...data.userData,
71
71
  requester: transformedRequester
72
72
  },
73
73
  pluginInfo: this.buildPluginInfo(data, "clientData" in data ? data.clientData : {}),
@@ -147,7 +147,7 @@ export class FilterManager {
147
147
  sendData.equalizer = [...this.equalizerBands];
148
148
  if (sendData.equalizer.length === 0)
149
149
  delete sendData.equalizer;
150
- for (const key of [...Object.keys(sendData)]) {
150
+ for (const key of Object.keys(sendData)) {
151
151
  // delete disabled filters
152
152
  if (key === "pluginFilters") {
153
153
  // for(const key of [...Object.keys(sendData.pluginFilters)]) {
@@ -178,7 +178,7 @@ export class FilterManager {
178
178
  this.filters.rotation = this.data.rotation.rotationHz !== 0;
179
179
  this.filters.vibrato = this.data.vibrato.frequency !== 0 || this.data.vibrato.depth !== 0;
180
180
  this.filters.tremolo = this.data.tremolo.frequency !== 0 || this.data.tremolo.depth !== 0;
181
- const lavalinkFilterData = (this.data.pluginFilters?.["lavalink-filter-plugin"] || { echo: { decay: this.data.pluginFilters?.echo?.decay && !this.data.pluginFilters?.echo?.echoLength ? this.data.pluginFilters.echo.decay : 0, delay: this.data.pluginFilters?.echo?.delay || 0 }, reverb: { gains: [], delays: [], ...((this.data.pluginFilters.reverb) || {}) } });
181
+ const lavalinkFilterData = (this.data.pluginFilters?.["lavalink-filter-plugin"] || { echo: { decay: this.data.pluginFilters?.echo?.decay && !this.data.pluginFilters?.echo?.echoLength ? this.data.pluginFilters.echo.decay : 0, delay: this.data.pluginFilters?.echo?.delay || 0 }, reverb: { gains: [], delays: [], ...(this.data.pluginFilters.reverb) } });
182
182
  this.filters.lavalinkFilterPlugin.echo = lavalinkFilterData.echo.decay !== 0 || lavalinkFilterData.echo.delay !== 0;
183
183
  this.filters.lavalinkFilterPlugin.reverb = lavalinkFilterData.reverb?.delays?.length !== 0 || lavalinkFilterData.reverb?.gains?.length !== 0;
184
184
  this.filters.lavalinkLavaDspxPlugin.highPass = Object.values(this.data.pluginFilters["high-pass"] || {}).length > 0;
@@ -483,25 +483,37 @@ export class LavalinkManager extends EventEmitter {
483
483
  if ("token" in update) {
484
484
  if (!player.node?.sessionId)
485
485
  throw new Error("Lavalink Node is either not ready or not up to date");
486
- await player.node.updatePlayer({
487
- guildId: player.guildId,
488
- playerOptions: {
489
- voice: {
490
- token: update.token,
491
- endpoint: update.endpoint,
492
- sessionId: player.voice?.sessionId,
493
- }
494
- }
495
- });
496
- if (this.options?.advancedOptions?.enableDebugEvents) {
486
+ const sessionId2Use = player.voice?.sessionId || ("sessionId" in update ? update.sessionId : undefined);
487
+ if (!sessionId2Use) {
497
488
  this.emit("debug", DebugEvents.NoAudioDebug, {
498
- state: "log",
499
- message: `Sent updatePlayer for voice token session :: ${JSON.stringify({ voice: { token: update.token, endpoint: update.endpoint, sessionId: player.voice?.sessionId, }, update }, null, 2)}`,
489
+ state: "error",
490
+ message: `Can't send updatePlayer for voice token session - Missing sessionId :: ${JSON.stringify({ voice: { token: update.token, endpoint: update.endpoint, sessionId: sessionId2Use, }, update, playerVoice: player.voice }, null, 2)}`,
500
491
  functionLayer: "LavalinkManager > sendRawData()",
501
492
  });
493
+ if (this.options?.advancedOptions?.debugOptions?.noAudio === true)
494
+ console.debug("Lavalink-Client-Debug | NO-AUDIO [::] sendRawData function, Sent updatePlayer for voice token session", { voice: { token: update.token, endpoint: update.endpoint, sessionId: sessionId2Use, }, playerVoice: player.voice, update });
495
+ }
496
+ else {
497
+ await player.node.updatePlayer({
498
+ guildId: player.guildId,
499
+ playerOptions: {
500
+ voice: {
501
+ token: update.token,
502
+ endpoint: update.endpoint,
503
+ sessionId: sessionId2Use,
504
+ }
505
+ }
506
+ });
507
+ if (this.options?.advancedOptions?.enableDebugEvents) {
508
+ this.emit("debug", DebugEvents.NoAudioDebug, {
509
+ state: "log",
510
+ message: `Sent updatePlayer for voice token session :: ${JSON.stringify({ voice: { token: update.token, endpoint: update.endpoint, sessionId: sessionId2Use, }, update, playerVoice: player.voice }, null, 2)}`,
511
+ functionLayer: "LavalinkManager > sendRawData()",
512
+ });
513
+ }
514
+ if (this.options?.advancedOptions?.debugOptions?.noAudio === true)
515
+ console.debug("Lavalink-Client-Debug | NO-AUDIO [::] sendRawData function, Can't send updatePlayer for voice token session - Missing sessionId", { voice: { token: update.token, endpoint: update.endpoint, sessionId: sessionId2Use, } });
502
516
  }
503
- if (this.options?.advancedOptions?.debugOptions?.noAudio === true)
504
- console.debug("Lavalink-Client-Debug | NO-AUDIO [::] sendRawData function, Sent updatePlayer for voice token session", { voice: { token: update.token, endpoint: update.endpoint, sessionId: player.voice?.sessionId, } });
505
517
  return;
506
518
  }
507
519
  /* voice state update */
@@ -523,7 +535,18 @@ export class LavalinkManager extends EventEmitter {
523
535
  if (update.channel_id) {
524
536
  if (player.voiceChannelId !== update.channel_id)
525
537
  this.emit("playerMove", player, player.voiceChannelId, update.channel_id);
526
- player.voice.sessionId = update.session_id;
538
+ player.voice.sessionId = update.session_id || player.voice.sessionId;
539
+ if (!player.voice.sessionId) {
540
+ if (this.options?.advancedOptions?.enableDebugEvents) {
541
+ this.emit("debug", DebugEvents.NoAudioDebug, {
542
+ state: "warn",
543
+ message: `Function to assing sessionId provided, but no found in Payload: ${JSON.stringify({ update, playerVoice: player.voice }, null, 2)}`,
544
+ functionLayer: "LavalinkManager > sendRawData()",
545
+ });
546
+ }
547
+ if (this.options?.advancedOptions?.debugOptions?.noAudio === true)
548
+ console.debug(`Lavalink-Client-Debug | NO-AUDIO [::] sendRawData function, Function to assing sessionId provided, but no found in Payload: ${JSON.stringify(update, null, 2)}`);
549
+ }
527
550
  player.voiceChannelId = update.channel_id;
528
551
  const selfMuteChanged = typeof update.self_mute === "boolean" && player.voiceState.selfMute !== update.self_mute;
529
552
  const serverMuteChanged = typeof update.mute === "boolean" && player.voiceState.serverMute !== update.mute;
@@ -807,7 +807,7 @@ export class LavalinkNode {
807
807
  * @returns boolean
808
808
  */
809
809
  syncPlayerData(data, res) {
810
- if (typeof data === "object" && typeof data?.guildId === "string" && typeof data.playerOptions === "object" && Object.keys(data.playerOptions).length > 1) {
810
+ if (typeof data === "object" && typeof data?.guildId === "string" && typeof data.playerOptions === "object" && Object.keys(data.playerOptions).length > 0) {
811
811
  const player = this.NodeManager.LavalinkManager.getPlayer(data.guildId);
812
812
  if (!player)
813
813
  return;
@@ -833,7 +833,7 @@ export class LavalinkNode {
833
833
  }
834
834
  }
835
835
  if (typeof data.playerOptions.filters !== "undefined") {
836
- const oldFilterTimescale = { ...(player.filterManager.data.timescale || {}) };
836
+ const oldFilterTimescale = { ...player.filterManager.data.timescale };
837
837
  Object.freeze(oldFilterTimescale);
838
838
  if (data.playerOptions.filters.timescale)
839
839
  player.filterManager.data.timescale = data.playerOptions.filters.timescale;
@@ -230,7 +230,7 @@ export interface NodeManagerEvents {
230
230
  * Aka for that you need to be able to save player data like vc channel + text channel in a db and then sync it again
231
231
  * @event Manager.nodeManager#nodeResumed
232
232
  */
233
- "resumed": (node: LavalinkNode, paylaod: {
233
+ "resumed": (node: LavalinkNode, payload: {
234
234
  resumed: true;
235
235
  sessionId: string;
236
236
  op: "ready";
@@ -32,7 +32,7 @@ export class ManagerUtils {
32
32
  buildPluginInfo(data, clientData = {}) {
33
33
  return {
34
34
  clientData: clientData,
35
- ...(data.pluginInfo || data.plugin || {})
35
+ ...(data.pluginInfo || data.plugin),
36
36
  };
37
37
  }
38
38
  buildTrack(data, requester) {
@@ -62,7 +62,7 @@ export class ManagerUtils {
62
62
  isrc: data.info.isrc,
63
63
  },
64
64
  userData: {
65
- ...(data.userData || {}),
65
+ ...data.userData,
66
66
  requester: transformedRequester
67
67
  },
68
68
  pluginInfo: this.buildPluginInfo(data, "clientData" in data ? data.clientData : {}),
@@ -230,7 +230,7 @@ export interface NodeManagerEvents {
230
230
  * Aka for that you need to be able to save player data like vc channel + text channel in a db and then sync it again
231
231
  * @event Manager.nodeManager#nodeResumed
232
232
  */
233
- "resumed": (node: LavalinkNode, paylaod: {
233
+ "resumed": (node: LavalinkNode, payload: {
234
234
  resumed: true;
235
235
  sessionId: string;
236
236
  op: "ready";
package/package.json CHANGED
@@ -1,29 +1,23 @@
1
1
  {
2
2
  "name": "lavalink-client",
3
- "version": "2.4.0",
3
+ "version": "2.4.2",
4
4
  "description": "Easy, flexible and feature-rich lavalink@v4 Client. Both for Beginners and Proficients.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
7
7
  "types": "dist/types/index.d.js",
8
8
  "scripts": {
9
9
  "build": "npm run tool:clean && npm run build:all && npm run tool:fixbuild",
10
-
11
10
  "build:bun": "bun run tool:clean && bun run build:all:bun && bun run tool:fixbuild",
12
11
  "build:all:bun": "bun run build:cjs && bun run build:esm && bun run build:types",
13
-
14
12
  "build:all": "npm run build:cjs && npm run build:esm && npm run build:types",
15
13
  "build:cjs": "tsc -p tools/config/tsconfig.cjs.json && tsc-alias -p tools/config/tsconfig.cjs.json",
16
14
  "build:esm": "tsc -p tools/config/tsconfig.esm.json && tsc-alias -p tools/config/tsconfig.esm.json",
17
15
  "build:types": "tsc -p tools/config/tsconfig.types.json && tsc-alias -p tools/config/tsconfig.types.json",
18
-
19
16
  "tool:clean": "node tools/cleanup.js",
20
17
  "tool:fixbuild": "node tools/fixup.js",
21
-
22
18
  "lint": "eslint .",
23
19
  "lint:fix": "npm run lint -- --fix",
24
-
25
20
  "test": "node -v",
26
-
27
21
  "prepublishOnly": "npm run build",
28
22
  "prepare": "npm run build"
29
23
  },