peer-term 1.2.9 → 1.2.10

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 +28 -13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "peer-term",
3
- "version": "1.2.9",
3
+ "version": "1.2.10",
4
4
  "license": "MIT",
5
5
  "description": "Share your terminal instantly using a 6-digit code. Encrypted. No config.",
6
6
  "keywords": [
package/src/index.js CHANGED
@@ -326,6 +326,7 @@ class Session {
326
326
  this.awaitingRejoin = false;
327
327
  this.destroyed = false;
328
328
  this.intentionalClose = false;
329
+ this.ptyOutputQueue = Promise.resolve();
329
330
  this.reconnectTimer = null;
330
331
  this.createdAt = Date.now();
331
332
  this.relayUrl = null; // Track which relay URL we connected to
@@ -708,25 +709,14 @@ class Session {
708
709
  env: process.env,
709
710
  });
710
711
 
711
- this.ptyProcess.onData(async (data) => {
712
+ this.ptyProcess.onData((data) => {
712
713
  // Mirror PTY output to local viewer terminal
713
714
  if (this.viewerSocket) {
714
715
  try { this.viewerSocket.write(data); } catch {}
715
716
  }
716
717
 
717
718
  if (!this.sharedKey) return;
718
- try {
719
- const payload = await encrypt(this.sharedKey, data);
720
- // Phase 4: Route through DataChannel if active, else relay
721
- if (this.useDataChannel && this.webrtc && this.webrtc.isActive()) {
722
- this.webrtc.send(payload);
723
- } else if (this.ws && this.ws.readyState === WebSocket.OPEN) {
724
- // Backpressure: drop chunk if relay can't keep up (1.25 MB buffer limit)
725
- if (this.ws.bufferedAmount < 1.25 * 1024 * 1024) {
726
- this.ws.send(JSON.stringify({ type: 'data', payload }));
727
- }
728
- }
729
- } catch {}
719
+ this._queuePtyOutput(data, this.sharedKey);
730
720
  });
731
721
 
732
722
  this.ptyProcess.onExit(({ exitCode }) => {
@@ -742,6 +732,31 @@ class Session {
742
732
  }
743
733
 
744
734
  // ─── Local TCP viewer for host terminal ─────────────────────────────
735
+ _queuePtyOutput(data, sharedKey) {
736
+ this.ptyOutputQueue = this.ptyOutputQueue
737
+ .then(() => this._sendPtyOutput(data, sharedKey))
738
+ .catch((err) => {
739
+ this.logDebug(`Failed to send PTY output: ${err.message}`);
740
+ });
741
+ }
742
+
743
+ async _sendPtyOutput(data, sharedKey) {
744
+ if (this.destroyed || !sharedKey || sharedKey !== this.sharedKey) return;
745
+
746
+ const payload = await encrypt(sharedKey, data);
747
+ if (this.destroyed || sharedKey !== this.sharedKey) return;
748
+
749
+ // Phase 4: Route through DataChannel if active, else relay
750
+ if (this.useDataChannel && this.webrtc && this.webrtc.isActive()) {
751
+ this.webrtc.send(payload);
752
+ } else if (this.ws && this.ws.readyState === WebSocket.OPEN) {
753
+ // Backpressure: drop chunk if relay can't keep up (1.25 MB buffer limit)
754
+ if (this.ws.bufferedAmount < 1.25 * 1024 * 1024) {
755
+ this.ws.send(JSON.stringify({ type: 'data', payload }));
756
+ }
757
+ }
758
+ }
759
+
745
760
  _startViewerServer() {
746
761
  this.viewerServer = net.createServer((socket) => {
747
762
  // Close any existing viewer connection before accepting a new one