Skip to content

Commit 48b5688

Browse files
committed
v2.7.2 - better reconnection handlings
1 parent 6902184 commit 48b5688

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Key Changes:
2626
- there is now a new getter: `node.reconnectionAttemptCount` (which allows you to get the count of the current reconnection attempts, considering the new option `node.options.retryTimespan`)
2727
- Before the `node.reconnectAttempts` was a number-counter. Now it's just an array of Date-Times, to be able to allow Retrys per a timespan (e.g. you can have 20 retries every hour.) - setup able through `node.options.retryTimespan`, on default it's -1. so it behaves as before.
2828
- FIX: Now instead of counting from "1 retry up" it counts from 0 up, means if you set `node.retryAmount` to "1" it actually tries 1 time to retry, and not 0. (issue before)
29-
29+
- New node-event "reconnectinprogress" which is triggered before "reconnecting" is triggered, but "reconnecting" might not be triggered, when the max retryAmount is reached, therefore "reconnectinprogress" exists.
3030

3131
## **Version 2.7.1**
3232

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.1",
3+
"version": "2.7.2",
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: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ export class LavalinkNode {
431431

432432
this.resetAckTimeouts(false, true);
433433

434+
if(this.pingTimeout) clearTimeout(this.pingTimeout);
434435
this.pingTimeout = setTimeout(() => {
435436
this.pingTimeout = null;
436437
if (!this.socket) {
@@ -1029,7 +1030,7 @@ export class LavalinkNode {
10291030
*
10301031
* @example
10311032
* ```ts
1032-
* await player.node.reconnect();
1033+
* await player.node.reconnect(true); //true forcefully trys the reconnect
10331034
* ```
10341035
*/
10351036
private reconnect(force = false): void {
@@ -1046,6 +1047,8 @@ export class LavalinkNode {
10461047
this.executeReconnect();
10471048
return;
10481049
}
1050+
1051+
if(this.reconnectTimeout) clearTimeout(this.reconnectTimeout);
10491052
this.reconnectTimeout = setTimeout(() => {
10501053
this.reconnectTimeout = null;
10511054
this.executeReconnect();
@@ -1180,10 +1183,7 @@ export class LavalinkNode {
11801183

11811184
if (code !== 1000 || reason !== "Node-Destroy") {
11821185
if (this.NodeManager.nodes.has(this.id)) { // try to reconnect only when the node is still in the nodeManager.nodes list
1183-
// Only reconnect if not already in progress
1184-
if (this.reconnectionState === ReconnectionState.IDLE) {
1185-
this.reconnect();
1186-
}
1186+
this.reconnect();
11871187
}
11881188
}
11891189

@@ -1688,11 +1688,7 @@ export class LavalinkNode {
16881688

16891689
this.NodeManager.LavalinkManager.emit("playerQueueEmptyStart", player, this.NodeManager.LavalinkManager.options.playerOptions.onEmptyQueue?.destroyAfterMs);
16901690

1691-
if (player.get("internal_queueempty")) {
1692-
clearTimeout(player.get("internal_queueempty"));
1693-
player.set("internal_queueempty", undefined);
1694-
}
1695-
1691+
if (player.get("internal_queueempty")) clearTimeout(player.get("internal_queueempty"));
16961692
player.set("internal_queueempty", setTimeout(() => {
16971693
player.set("internal_queueempty", undefined);
16981694
if (player.queue.current) {

0 commit comments

Comments
 (0)