lavalink-client 2.4.2 → 2.4.3
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/README.md +8 -0
- package/dist/cjs/structures/LavalinkManager.js +24 -10
- package/dist/cjs/structures/Types/Manager.d.ts +2 -0
- package/dist/esm/structures/LavalinkManager.js +24 -10
- package/dist/esm/structures/Types/Manager.d.ts +2 -0
- package/dist/types/structures/Types/Manager.d.ts +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -789,3 +789,11 @@ if(previousTrack) {
|
|
|
789
789
|
*Allows you to inmplement a custom playerVoiceEmpty handler*
|
|
790
790
|
|
|
791
791
|
- Added the new events and configuration to the docs
|
|
792
|
+
|
|
793
|
+
## **Version 2.4.3**
|
|
794
|
+
- `managerOptions#playerOptions.onDisconnect.autoReconnect`:
|
|
795
|
+
- Added the option `managerOptions#playerOptions.onDisconnect.autoReconnectOnlyWithTracks` to control wether to try reconnecting only when there are tracks in the queue / current track or not
|
|
796
|
+
- Added a new debug log for that
|
|
797
|
+
- Added the try to play the next track if there is no current track
|
|
798
|
+
- *There was a problem trying to auto-reconnect on "empty-queue" events, which caused the player to get destroyed by that and log the error in console "`There is no Track in the Queue, nor provided in the PlayOptions`"*
|
|
799
|
+
- *Now you have to handle that case manually if you want to or set autoReconnectOnlyWithTracks to false (default)*
|
|
@@ -83,7 +83,8 @@ class LavalinkManager extends events_1.EventEmitter {
|
|
|
83
83
|
defaultSearchPlatform: options?.playerOptions?.defaultSearchPlatform ?? "ytsearch",
|
|
84
84
|
onDisconnect: {
|
|
85
85
|
destroyPlayer: options?.playerOptions?.onDisconnect?.destroyPlayer ?? true,
|
|
86
|
-
autoReconnect: options?.playerOptions?.onDisconnect?.autoReconnect ?? false
|
|
86
|
+
autoReconnect: options?.playerOptions?.onDisconnect?.autoReconnect ?? false,
|
|
87
|
+
autoReconnectOnlyWithTracks: options?.playerOptions?.onDisconnect?.autoReconnectOnlyWithTracks ?? false,
|
|
87
88
|
},
|
|
88
89
|
onEmptyQueue: {
|
|
89
90
|
autoPlayFunction: options?.playerOptions?.onEmptyQueue?.autoPlayFunction ?? null,
|
|
@@ -569,13 +570,14 @@ class LavalinkManager extends events_1.EventEmitter {
|
|
|
569
570
|
this.emit("playerSuppressChange", player, player.voiceState.suppress);
|
|
570
571
|
}
|
|
571
572
|
else {
|
|
572
|
-
|
|
573
|
+
const { autoReconnectOnlyWithTracks, destroyPlayer, autoReconnect } = this.options?.playerOptions?.onDisconnect ?? {};
|
|
574
|
+
if (destroyPlayer === true) {
|
|
573
575
|
return void await player.destroy(Constants_1.DestroyReasons.Disconnected);
|
|
574
576
|
}
|
|
575
|
-
|
|
576
|
-
if (this.options?.playerOptions?.onDisconnect?.autoReconnect === true) {
|
|
577
|
+
if (autoReconnect === true) {
|
|
577
578
|
try {
|
|
578
|
-
const
|
|
579
|
+
const previousPosition = player.position;
|
|
580
|
+
const previousPaused = player.paused;
|
|
579
581
|
if (this.options?.advancedOptions?.enableDebugEvents) {
|
|
580
582
|
this.emit("debug", Constants_1.DebugEvents.PlayerAutoReconnect, {
|
|
581
583
|
state: "log",
|
|
@@ -583,12 +585,23 @@ class LavalinkManager extends events_1.EventEmitter {
|
|
|
583
585
|
functionLayer: "LavalinkManager > sendRawData()",
|
|
584
586
|
});
|
|
585
587
|
}
|
|
586
|
-
|
|
588
|
+
// connect if there are tracks & autoReconnectOnlyWithTracks = true or autoReconnectOnlyWithTracks is false
|
|
589
|
+
if (!autoReconnectOnlyWithTracks || (autoReconnectOnlyWithTracks && (player.queue.current || player.queue.tracks.length))) {
|
|
590
|
+
await player.connect();
|
|
591
|
+
}
|
|
587
592
|
// replay the current playing stream
|
|
588
|
-
|
|
589
|
-
position:
|
|
590
|
-
|
|
591
|
-
|
|
593
|
+
if (player.queue.current) {
|
|
594
|
+
return void await player.play({ position: previousPosition, paused: previousPaused, clientTrack: player.queue.current, });
|
|
595
|
+
}
|
|
596
|
+
// try to play the next track
|
|
597
|
+
if (player.queue.tracks.length) {
|
|
598
|
+
return void await player.play({ paused: previousPaused });
|
|
599
|
+
}
|
|
600
|
+
// debug log if nothing was possible
|
|
601
|
+
this.emit("debug", Constants_1.DebugEvents.PlayerAutoReconnect, {
|
|
602
|
+
state: "log",
|
|
603
|
+
message: `Auto reconnected, but nothing to play`,
|
|
604
|
+
functionLayer: "LavalinkManager > sendRawData()",
|
|
592
605
|
});
|
|
593
606
|
}
|
|
594
607
|
catch (e) {
|
|
@@ -596,6 +609,7 @@ class LavalinkManager extends events_1.EventEmitter {
|
|
|
596
609
|
return void await player.destroy(Constants_1.DestroyReasons.PlayerReconnectFail);
|
|
597
610
|
}
|
|
598
611
|
}
|
|
612
|
+
this.emit("playerDisconnect", player, player.voiceChannelId);
|
|
599
613
|
player.voiceChannelId = null;
|
|
600
614
|
player.voice = Object.assign({});
|
|
601
615
|
return;
|
|
@@ -200,6 +200,8 @@ export interface ManagerPlayerOptions {
|
|
|
200
200
|
onDisconnect?: {
|
|
201
201
|
/** Try to reconnect? -> If fails -> Destroy */
|
|
202
202
|
autoReconnect?: boolean;
|
|
203
|
+
/** Only try to reconnect if there are tracks in the queue */
|
|
204
|
+
autoReconnectOnlyWithTracks?: boolean;
|
|
203
205
|
/** Instantly destroy player (overrides autoReconnect) | Don't provide == disable feature*/
|
|
204
206
|
destroyPlayer?: boolean;
|
|
205
207
|
};
|
|
@@ -80,7 +80,8 @@ export class LavalinkManager extends EventEmitter {
|
|
|
80
80
|
defaultSearchPlatform: options?.playerOptions?.defaultSearchPlatform ?? "ytsearch",
|
|
81
81
|
onDisconnect: {
|
|
82
82
|
destroyPlayer: options?.playerOptions?.onDisconnect?.destroyPlayer ?? true,
|
|
83
|
-
autoReconnect: options?.playerOptions?.onDisconnect?.autoReconnect ?? false
|
|
83
|
+
autoReconnect: options?.playerOptions?.onDisconnect?.autoReconnect ?? false,
|
|
84
|
+
autoReconnectOnlyWithTracks: options?.playerOptions?.onDisconnect?.autoReconnectOnlyWithTracks ?? false,
|
|
84
85
|
},
|
|
85
86
|
onEmptyQueue: {
|
|
86
87
|
autoPlayFunction: options?.playerOptions?.onEmptyQueue?.autoPlayFunction ?? null,
|
|
@@ -566,13 +567,14 @@ export class LavalinkManager extends EventEmitter {
|
|
|
566
567
|
this.emit("playerSuppressChange", player, player.voiceState.suppress);
|
|
567
568
|
}
|
|
568
569
|
else {
|
|
569
|
-
|
|
570
|
+
const { autoReconnectOnlyWithTracks, destroyPlayer, autoReconnect } = this.options?.playerOptions?.onDisconnect ?? {};
|
|
571
|
+
if (destroyPlayer === true) {
|
|
570
572
|
return void await player.destroy(DestroyReasons.Disconnected);
|
|
571
573
|
}
|
|
572
|
-
|
|
573
|
-
if (this.options?.playerOptions?.onDisconnect?.autoReconnect === true) {
|
|
574
|
+
if (autoReconnect === true) {
|
|
574
575
|
try {
|
|
575
|
-
const
|
|
576
|
+
const previousPosition = player.position;
|
|
577
|
+
const previousPaused = player.paused;
|
|
576
578
|
if (this.options?.advancedOptions?.enableDebugEvents) {
|
|
577
579
|
this.emit("debug", DebugEvents.PlayerAutoReconnect, {
|
|
578
580
|
state: "log",
|
|
@@ -580,12 +582,23 @@ export class LavalinkManager extends EventEmitter {
|
|
|
580
582
|
functionLayer: "LavalinkManager > sendRawData()",
|
|
581
583
|
});
|
|
582
584
|
}
|
|
583
|
-
|
|
585
|
+
// connect if there are tracks & autoReconnectOnlyWithTracks = true or autoReconnectOnlyWithTracks is false
|
|
586
|
+
if (!autoReconnectOnlyWithTracks || (autoReconnectOnlyWithTracks && (player.queue.current || player.queue.tracks.length))) {
|
|
587
|
+
await player.connect();
|
|
588
|
+
}
|
|
584
589
|
// replay the current playing stream
|
|
585
|
-
|
|
586
|
-
position:
|
|
587
|
-
|
|
588
|
-
|
|
590
|
+
if (player.queue.current) {
|
|
591
|
+
return void await player.play({ position: previousPosition, paused: previousPaused, clientTrack: player.queue.current, });
|
|
592
|
+
}
|
|
593
|
+
// try to play the next track
|
|
594
|
+
if (player.queue.tracks.length) {
|
|
595
|
+
return void await player.play({ paused: previousPaused });
|
|
596
|
+
}
|
|
597
|
+
// debug log if nothing was possible
|
|
598
|
+
this.emit("debug", DebugEvents.PlayerAutoReconnect, {
|
|
599
|
+
state: "log",
|
|
600
|
+
message: `Auto reconnected, but nothing to play`,
|
|
601
|
+
functionLayer: "LavalinkManager > sendRawData()",
|
|
589
602
|
});
|
|
590
603
|
}
|
|
591
604
|
catch (e) {
|
|
@@ -593,6 +606,7 @@ export class LavalinkManager extends EventEmitter {
|
|
|
593
606
|
return void await player.destroy(DestroyReasons.PlayerReconnectFail);
|
|
594
607
|
}
|
|
595
608
|
}
|
|
609
|
+
this.emit("playerDisconnect", player, player.voiceChannelId);
|
|
596
610
|
player.voiceChannelId = null;
|
|
597
611
|
player.voice = Object.assign({});
|
|
598
612
|
return;
|
|
@@ -200,6 +200,8 @@ export interface ManagerPlayerOptions {
|
|
|
200
200
|
onDisconnect?: {
|
|
201
201
|
/** Try to reconnect? -> If fails -> Destroy */
|
|
202
202
|
autoReconnect?: boolean;
|
|
203
|
+
/** Only try to reconnect if there are tracks in the queue */
|
|
204
|
+
autoReconnectOnlyWithTracks?: boolean;
|
|
203
205
|
/** Instantly destroy player (overrides autoReconnect) | Don't provide == disable feature*/
|
|
204
206
|
destroyPlayer?: boolean;
|
|
205
207
|
};
|
|
@@ -200,6 +200,8 @@ export interface ManagerPlayerOptions {
|
|
|
200
200
|
onDisconnect?: {
|
|
201
201
|
/** Try to reconnect? -> If fails -> Destroy */
|
|
202
202
|
autoReconnect?: boolean;
|
|
203
|
+
/** Only try to reconnect if there are tracks in the queue */
|
|
204
|
+
autoReconnectOnlyWithTracks?: boolean;
|
|
203
205
|
/** Instantly destroy player (overrides autoReconnect) | Don't provide == disable feature*/
|
|
204
206
|
destroyPlayer?: boolean;
|
|
205
207
|
};
|
package/package.json
CHANGED