muthera 1.0.2 → 1.0.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "muthera",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "A simple Lavalink wrapper for Discord music bot. Forked from Niizuki.",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -66,10 +66,11 @@ class Node {
66
66
  }
67
67
 
68
68
  open() {
69
- if (this.reconnectTimeout) clearTimeout(this.reconnectTimeout);
69
+ if (this.reconnectAttempt) clearTimeout(this.reconnectAttempt);
70
70
 
71
71
  this.muthera.emit("nodeConnect", this);
72
72
  this.connected = true;
73
+ this.reconnectAttempted = 1; // Reset reconnection attempts on successful connection
73
74
  this.muthera.emit(
74
75
  "debug",
75
76
  this.name,
@@ -138,7 +139,7 @@ class Node {
138
139
 
139
140
  reconnect() {
140
141
  this.reconnectAttempt = setTimeout(() => {
141
- if (this.reconnectAttempted >= this.reconnectTries) {
142
+ if (this.reconnectAttempted > this.reconnectTries) {
142
143
  const error = new Error(
143
144
  `Unable to connect node: ${this.name} after ${this.reconnectTries} attempts.`
144
145
  );
@@ -147,9 +148,10 @@ class Node {
147
148
  return this.destroy();
148
149
  }
149
150
 
150
- this.ws.removeAllListeners();
151
+ this.ws?.removeAllListeners();
151
152
  this.ws = null;
152
153
  this.muthera.emit("nodeReconnect", this);
154
+ this.muthera.emit("debug", this.name, `Reconnection attempt ${this.reconnectAttempted}/${this.reconnectTries}`);
153
155
  this.connect();
154
156
  this.reconnectAttempted++;
155
157
  }, this.reconnectTimeout);