peer-term 1.1.0 → 1.1.1

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +16 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "peer-term",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Share your terminal instantly using a 6-digit code. Encrypted. No config.",
5
5
  "main": "src/index.js",
6
6
  "bin": {
package/src/index.js CHANGED
@@ -602,8 +602,15 @@ class Session {
602
602
 
603
603
  this.log(`⏳ Reconnect attempt ${attempts}/${maxAttempts}...`);
604
604
 
605
+ // Close any in-flight reconnect socket from the previous tick
606
+ if (this._pendingReconnectWs) {
607
+ try { this._pendingReconnectWs.removeAllListeners(); this._pendingReconnectWs.close(); } catch {}
608
+ this._pendingReconnectWs = null;
609
+ }
610
+
605
611
  try {
606
612
  const newWs = new WebSocket(this.relayUrl);
613
+ this._pendingReconnectWs = newWs;
607
614
 
608
615
  newWs.on('open', () => {
609
616
  newWs.send(JSON.stringify({ type: 'host-rejoin', code: this.code }));
@@ -619,6 +626,7 @@ class Session {
619
626
 
620
627
  if (msg.type === 'rejoined') {
621
628
  // Success — replace the old ws with this new one
629
+ this._pendingReconnectWs = null;
622
630
  this.ws = newWs;
623
631
  this._stopReconnecting();
624
632
  this.log(`✅ Reconnected. Session restored.`);
@@ -632,6 +640,7 @@ class Session {
632
640
  }
633
641
  } else if (msg.type === 'error') {
634
642
  this.log(`Rejoin failed: ${msg.msg}`);
643
+ this._pendingReconnectWs = null;
635
644
  this._stopReconnecting();
636
645
  this.destroy();
637
646
  try { newWs.close(); } catch {}
@@ -640,11 +649,13 @@ class Session {
640
649
 
641
650
  newWs.on('error', () => {
642
651
  // Connection failed, next retry in 5s
652
+ if (this._pendingReconnectWs === newWs) this._pendingReconnectWs = null;
643
653
  try { newWs.close(); } catch {}
644
654
  });
645
655
 
646
656
  newWs.on('close', () => {
647
- // If we haven't adopted this ws, nothing to do — retry will fire
657
+ // Clean up reference if this was the pending socket
658
+ if (this._pendingReconnectWs === newWs) this._pendingReconnectWs = null;
648
659
  });
649
660
  } catch (e) {
650
661
  // Connection failed, next retry in 5s
@@ -657,6 +668,10 @@ class Session {
657
668
  clearInterval(this.reconnectTimer);
658
669
  this.reconnectTimer = null;
659
670
  }
671
+ if (this._pendingReconnectWs) {
672
+ try { this._pendingReconnectWs.removeAllListeners(); this._pendingReconnectWs.close(); } catch {}
673
+ this._pendingReconnectWs = null;
674
+ }
660
675
  }
661
676
 
662
677
  /**