magmastream 2.10.4 → 2.10.5

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.
@@ -438,7 +438,9 @@ class Manager extends events_1.EventEmitter {
438
438
  const player = this.getPlayer(update.guild_id);
439
439
  if (!player)
440
440
  return;
441
- this.emit(Enums_1.ManagerEventTypes.Debug, `[MANAGER] Updating voice state: ${Utils_1.JSONUtils.safe(update, 2)}`);
441
+ if (this.listenerCount(Enums_1.ManagerEventTypes.Debug)) {
442
+ this.emit(Enums_1.ManagerEventTypes.Debug, `[MANAGER] Updating voice state: ${Utils_1.JSONUtils.safe(update, 2)}`);
443
+ }
442
444
  if ("token" in update) {
443
445
  return await this.handleVoiceServerUpdate(player, update);
444
446
  }
@@ -23,7 +23,6 @@ export declare class Node {
23
23
  private reconnectTimeout?;
24
24
  private reconnectAttempts;
25
25
  private redisPrefix?;
26
- /** Session ID sent in the reconnect header for resumption — cleared once the ready op is received. */
27
26
  private pendingResumeSessionId;
28
27
  /**
29
28
  * Creates an instance of Node.
@@ -31,7 +31,6 @@ class Node {
31
31
  reconnectTimeout;
32
32
  reconnectAttempts = 0;
33
33
  redisPrefix;
34
- /** Session ID sent in the reconnect header for resumption — cleared once the ready op is received. */
35
34
  pendingResumeSessionId = null;
36
35
  /**
37
36
  * Creates an instance of Node.
@@ -256,12 +255,7 @@ class Node {
256
255
  "User-Id": this.manager.options.clientId,
257
256
  "Client-Name": this.manager.options.clientName,
258
257
  };
259
- // Capture resume session ID for the WS header, then clear this.sessionId.
260
- // REST calls guard on this.sessionId being non-null — keeping the stale value
261
- // would let updatePlayer/destroyPlayer fire with an invalid session during the
262
- // reconnect window (between connect() and the 'ready' op).
263
- // pendingResumeSessionId is kept so the 'ready' handler can still compute
264
- // hadPreviousSession correctly. this.sessionId is re-set by 'ready'.
258
+ // Keep the resume header while blocking REST calls until the next ready event.
265
259
  this.pendingResumeSessionId = this.sessionId;
266
260
  this.sessionId = null;
267
261
  if (typeof this.pendingResumeSessionId === "string" && this.pendingResumeSessionId.length > 0) {
@@ -310,11 +304,9 @@ class Node {
310
304
  if (players.size) {
311
305
  await Promise.all(Array.from(players.values(), (player) => player.autoMoveNode()));
312
306
  }
313
- // Always clear reconnect state regardless of connection status
314
307
  clearTimeout(this.reconnectTimeout);
315
308
  this.reconnectTimeout = undefined;
316
309
  this.reconnectAttempts = 0;
317
- // Only close the socket if it is actually open
318
310
  if (this.connected) {
319
311
  this.socket.close(1000, "destroy");
320
312
  this.socket.removeAllListeners();
@@ -419,9 +411,7 @@ class Node {
419
411
  };
420
412
  this.manager.emit(Enums_1.ManagerEventTypes.NodeDisconnect, this, { code, reason });
421
413
  this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[NODE] Disconnected node: ${Utils_1.JSONUtils.safe(debugInfo, 2)}`);
422
- // Null the session ID immediately so REST calls during the reconnect delay
423
- // window don't fire with a stale session. connect() reloads it from storage
424
- // into pendingResumeSessionId for the WS Session-Id header.
414
+ // Prevent REST calls from using a stale session during reconnect.
425
415
  this.sessionId = null;
426
416
  if (this.manager.useableNode) {
427
417
  const players = this.manager.players.filter((player) => player.node.options.identifier == this.options.identifier);
@@ -500,9 +490,6 @@ class Node {
500
490
  case "ready":
501
491
  this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[NODE] Node message: ${Utils_1.JSONUtils.safe(payload, 2)}`);
502
492
  this.rest.setSessionId(payload.sessionId);
503
- // pendingResumeSessionId holds what we sent in Session-Id header (if anything).
504
- // Use it — not this.sessionId which was nulled in connect() — to detect whether
505
- // we attempted resumption with a different session than what Lavalink gave back.
506
493
  const hadPreviousSession = this.pendingResumeSessionId && this.pendingResumeSessionId !== payload.sessionId;
507
494
  this.pendingResumeSessionId = null;
508
495
  this.sessionId = payload.sessionId;
@@ -544,7 +531,6 @@ class Node {
544
531
  if (!player || player.node.options.identifier !== this.options.identifier)
545
532
  return;
546
533
  player.position = payload.state.position ?? 0;
547
- // Transport status can lag lifecycle events; expose it without overwriting player.state.
548
534
  this.manager.emit(Enums_1.ManagerEventTypes.PlayerUpdate, player, payload);
549
535
  }
550
536
  /**
@@ -1239,7 +1225,7 @@ class Node {
1239
1225
  * @param {WebSocketClosedEvent} payload - The event payload containing additional data about the WebSocket close event.
1240
1226
  */
1241
1227
  socketClosed(player, payload) {
1242
- player.state = Enums_1.StateTypes.Disconnected;
1228
+ // A move can close the old socket after the new connection is ready.
1243
1229
  this.manager.emit(Enums_1.ManagerEventTypes.SocketClosed, player, payload);
1244
1230
  this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[NODE] Websocket closed for player: ${player.guildId} with payload: ${Utils_1.JSONUtils.safe(payload, 2)}`);
1245
1231
  }
@@ -1136,9 +1136,6 @@ class Player {
1136
1136
  context: { guildId: this.guildId },
1137
1137
  });
1138
1138
  }
1139
- // Only destroy the player on the old node if it is still reachable.
1140
- // If the server is down the REST call would fail anyway; skipping it
1141
- // also prevents a spurious error when switching nodes during an outage.
1142
1139
  if (this.node.connected) {
1143
1140
  await this.node.rest.destroyPlayer(this.guildId).catch(() => { });
1144
1141
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "magmastream",
3
- "version": "2.10.4",
3
+ "version": "2.10.5",
4
4
  "description": "A user-friendly Lavalink client designed for NodeJS.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",