@c7-digital/ledger 0.0.13 → 0.0.14

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/lib/src/ledger.js CHANGED
@@ -359,7 +359,8 @@ class LedgerStream {
359
359
  // Auto-reconnect on abnormal close (1006) if stream is still active and auto-reconnect is enabled
360
360
  if (code === 1006 && this.state_ === "live" && this.autoReconnect) {
361
361
  logger.log(`WebSocket closed abnormally (1006), reconnecting in 3 seconds...`);
362
- setTimeout(() => {
362
+ this.reconnectTimer = setTimeout(() => {
363
+ this.reconnectTimer = undefined;
363
364
  if (this.state_ === "live") {
364
365
  // Double-check we're still active
365
366
  logger.log(`Attempting to reconnect stream...`);
@@ -421,6 +422,10 @@ class LedgerStream {
421
422
  // Set state to stop to prevent transitions
422
423
  this.state_ = "stop";
423
424
  this.eventEmitter.emit("state", "stop");
425
+ if (this.reconnectTimer) {
426
+ clearTimeout(this.reconnectTimer);
427
+ this.reconnectTimer = undefined;
428
+ }
424
429
  if (this.stopClient) {
425
430
  this.stopClient();
426
431
  this.stopClient = undefined;
@@ -441,6 +446,11 @@ class LedgerStream {
441
446
  switch (this.state_) {
442
447
  case "live":
443
448
  logger.debug(`Restarting live stream with new token`);
449
+ // Cancel any pending reconnect timer to avoid duplicate connections
450
+ if (this.reconnectTimer) {
451
+ clearTimeout(this.reconnectTimer);
452
+ this.reconnectTimer = undefined;
453
+ }
444
454
  // Close current connection
445
455
  if (this.stopClient) {
446
456
  this.stopClient();