peer-term 1.1.2 → 1.1.4
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 +20 -4
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -205,6 +205,20 @@ class Session {
|
|
|
205
205
|
logger.debug(`${prefix} ${msg}`);
|
|
206
206
|
}
|
|
207
207
|
|
|
208
|
+
async _sendSessionConfig() {
|
|
209
|
+
if (!this.sharedKey || !this.ws || this.ws.readyState !== WebSocket.OPEN) return;
|
|
210
|
+
|
|
211
|
+
const config = JSON.stringify({
|
|
212
|
+
type: 'session-config',
|
|
213
|
+
readonly: this.readOnly,
|
|
214
|
+
version: '1.1.3',
|
|
215
|
+
shell: this.shell,
|
|
216
|
+
startPath: this.startPath,
|
|
217
|
+
});
|
|
218
|
+
const payload = await encrypt(this.sharedKey, config);
|
|
219
|
+
this.ws.send(JSON.stringify({ type: 'data', payload }));
|
|
220
|
+
}
|
|
221
|
+
|
|
208
222
|
// ─── Start the session ──────────────────────────────────────────────
|
|
209
223
|
async start() {
|
|
210
224
|
for (let i = 0; i < RELAY_URLS.length; i++) {
|
|
@@ -284,6 +298,7 @@ class Session {
|
|
|
284
298
|
const peerPublicKey = await importPublicKey(msg.publicKey);
|
|
285
299
|
this.sharedKey = await deriveSharedKey(this.keyPair.privateKey, peerPublicKey);
|
|
286
300
|
this.log('Encrypted tunnel active');
|
|
301
|
+
await this._sendSessionConfig();
|
|
287
302
|
|
|
288
303
|
this.startHeartbeat();
|
|
289
304
|
|
|
@@ -594,13 +609,13 @@ class Session {
|
|
|
594
609
|
this.reconnectTimer = setInterval(() => {
|
|
595
610
|
attempts++;
|
|
596
611
|
if (attempts > maxAttempts) {
|
|
597
|
-
this.log('
|
|
612
|
+
this.log('Could not reconnect. Session expired.');
|
|
598
613
|
this._stopReconnecting();
|
|
599
614
|
this.destroy();
|
|
600
615
|
return;
|
|
601
616
|
}
|
|
602
617
|
|
|
603
|
-
this.log(
|
|
618
|
+
this.log(`Reconnect attempt ${attempts}/${maxAttempts}...`);
|
|
604
619
|
|
|
605
620
|
// Close any in-flight reconnect socket from the previous tick
|
|
606
621
|
if (this._pendingReconnectWs) {
|
|
@@ -629,7 +644,7 @@ class Session {
|
|
|
629
644
|
this._pendingReconnectWs = null;
|
|
630
645
|
this.ws = newWs;
|
|
631
646
|
this._stopReconnecting();
|
|
632
|
-
this.log(
|
|
647
|
+
this.log(`Reconnected. Session restored.`);
|
|
633
648
|
|
|
634
649
|
// Re-attach the full message handler by wiring up events
|
|
635
650
|
this._attachWsHandlers(newWs);
|
|
@@ -712,6 +727,7 @@ class Session {
|
|
|
712
727
|
const peerPublicKey = await importPublicKey(msg.publicKey);
|
|
713
728
|
this.sharedKey = await deriveSharedKey(this.keyPair.privateKey, peerPublicKey);
|
|
714
729
|
this.log('Encrypted tunnel active');
|
|
730
|
+
await this._sendSessionConfig();
|
|
715
731
|
|
|
716
732
|
this.startHeartbeat();
|
|
717
733
|
|
|
@@ -782,7 +798,7 @@ class Session {
|
|
|
782
798
|
}
|
|
783
799
|
|
|
784
800
|
case 'rejoined': {
|
|
785
|
-
this.log(
|
|
801
|
+
this.log(`Reconnected. Session restored. (code: ${msg.code})`);
|
|
786
802
|
if (this.isClientConnected) {
|
|
787
803
|
this.startHeartbeat();
|
|
788
804
|
}
|