peer-term 1.2.10 → 1.2.11
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 +1 -1
- package/src/index.js +38 -14
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -648,13 +648,10 @@ class Session {
|
|
|
648
648
|
try {
|
|
649
649
|
const resizeJson = JSON.stringify({ type: 'resize', cols, rows });
|
|
650
650
|
const payload = await encrypt(this.sharedKey, resizeJson);
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
} else if (this.ws && this.ws.readyState === WebSocket.OPEN) {
|
|
656
|
-
this.ws.send(JSON.stringify({ type: 'data', payload, meta: 'resize' }));
|
|
657
|
-
}
|
|
651
|
+
this._sendEncryptedToClient(payload, {
|
|
652
|
+
directPayload: JSON.stringify({ _meta: 'resize', payload }),
|
|
653
|
+
meta: 'resize',
|
|
654
|
+
});
|
|
658
655
|
} catch {}
|
|
659
656
|
}
|
|
660
657
|
|
|
@@ -746,14 +743,41 @@ class Session {
|
|
|
746
743
|
const payload = await encrypt(sharedKey, data);
|
|
747
744
|
if (this.destroyed || sharedKey !== this.sharedKey) return;
|
|
748
745
|
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
746
|
+
this._sendEncryptedToClient(payload, { enforceBackpressure: true });
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
_sendEncryptedToClient(payload, options = {}) {
|
|
750
|
+
const directPayload = options.directPayload || payload;
|
|
751
|
+
|
|
752
|
+
if (this.useDataChannel) {
|
|
753
|
+
if (this.webrtc && this.webrtc.isActive()) {
|
|
754
|
+
let sentDirect = false;
|
|
755
|
+
try {
|
|
756
|
+
sentDirect = this.webrtc.send(directPayload);
|
|
757
|
+
} catch {}
|
|
758
|
+
|
|
759
|
+
if (sentDirect) return true;
|
|
756
760
|
}
|
|
761
|
+
|
|
762
|
+
this.useDataChannel = false;
|
|
763
|
+
this.log('DataChannel send failed — falling back to relay');
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
return this._sendViaRelay(payload, options);
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
_sendViaRelay(payload, { meta, enforceBackpressure = false } = {}) {
|
|
770
|
+
if (!this.ws || this.ws.readyState !== WebSocket.OPEN) return false;
|
|
771
|
+
if (enforceBackpressure && this.ws.bufferedAmount >= 1.25 * 1024 * 1024) return false;
|
|
772
|
+
|
|
773
|
+
const msg = { type: 'data', payload };
|
|
774
|
+
if (meta) msg.meta = meta;
|
|
775
|
+
|
|
776
|
+
try {
|
|
777
|
+
this.ws.send(JSON.stringify(msg));
|
|
778
|
+
return true;
|
|
779
|
+
} catch {
|
|
780
|
+
return false;
|
|
757
781
|
}
|
|
758
782
|
}
|
|
759
783
|
|