sessioncast-cli 2.0.1 → 2.0.2
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.
|
@@ -39,8 +39,8 @@ const tmux = __importStar(require("./tmux"));
|
|
|
39
39
|
const fs = __importStar(require("fs"));
|
|
40
40
|
const path = __importStar(require("path"));
|
|
41
41
|
// Capture intervals
|
|
42
|
-
const CAPTURE_INTERVAL_ACTIVE_MS =
|
|
43
|
-
const CAPTURE_INTERVAL_IDLE_MS =
|
|
42
|
+
const CAPTURE_INTERVAL_ACTIVE_MS = 16;
|
|
43
|
+
const CAPTURE_INTERVAL_IDLE_MS = 100;
|
|
44
44
|
const ACTIVE_THRESHOLD_MS = 2000;
|
|
45
45
|
const FORCE_SEND_INTERVAL_MS = 10000;
|
|
46
46
|
const USE_COMPRESSION = true;
|
|
@@ -21,12 +21,15 @@ export declare class RelayWebSocketClient extends EventEmitter {
|
|
|
21
21
|
private circuitBreakerOpen;
|
|
22
22
|
private circuitBreakerResetTime;
|
|
23
23
|
private reconnectTimer;
|
|
24
|
+
private pingTimer;
|
|
24
25
|
private destroyed;
|
|
25
26
|
constructor(options: WebSocketClientOptions);
|
|
26
27
|
connect(): void;
|
|
27
28
|
private registerAsHost;
|
|
28
29
|
private handleMessage;
|
|
29
30
|
private handleError;
|
|
31
|
+
private startPing;
|
|
32
|
+
private stopPing;
|
|
30
33
|
private scheduleReconnect;
|
|
31
34
|
send(message: Message): boolean;
|
|
32
35
|
sendScreen(data: Buffer, paneMeta?: {
|
package/dist/agent/websocket.js
CHANGED
|
@@ -40,10 +40,11 @@ exports.RelayWebSocketClient = void 0;
|
|
|
40
40
|
const ws_1 = __importDefault(require("ws"));
|
|
41
41
|
const events_1 = require("events");
|
|
42
42
|
const zlib = __importStar(require("zlib"));
|
|
43
|
-
const MAX_RECONNECT_ATTEMPTS =
|
|
43
|
+
const MAX_RECONNECT_ATTEMPTS = 50;
|
|
44
44
|
const BASE_RECONNECT_DELAY_MS = 2000;
|
|
45
45
|
const MAX_RECONNECT_DELAY_MS = 60000;
|
|
46
46
|
const CIRCUIT_BREAKER_DURATION_MS = 120000;
|
|
47
|
+
const PING_INTERVAL_MS = 30000;
|
|
47
48
|
class RelayWebSocketClient extends events_1.EventEmitter {
|
|
48
49
|
constructor(options) {
|
|
49
50
|
super();
|
|
@@ -53,6 +54,7 @@ class RelayWebSocketClient extends events_1.EventEmitter {
|
|
|
53
54
|
this.circuitBreakerOpen = false;
|
|
54
55
|
this.circuitBreakerResetTime = 0;
|
|
55
56
|
this.reconnectTimer = null;
|
|
57
|
+
this.pingTimer = null;
|
|
56
58
|
this.destroyed = false;
|
|
57
59
|
this.url = options.url;
|
|
58
60
|
this.sessionId = options.sessionId;
|
|
@@ -71,6 +73,7 @@ class RelayWebSocketClient extends events_1.EventEmitter {
|
|
|
71
73
|
this.reconnectAttempts = 0;
|
|
72
74
|
this.circuitBreakerOpen = false;
|
|
73
75
|
this.registerAsHost();
|
|
76
|
+
this.startPing();
|
|
74
77
|
this.emit('connected');
|
|
75
78
|
});
|
|
76
79
|
this.ws.on('message', (data) => {
|
|
@@ -84,6 +87,7 @@ class RelayWebSocketClient extends events_1.EventEmitter {
|
|
|
84
87
|
});
|
|
85
88
|
this.ws.on('close', (code, reason) => {
|
|
86
89
|
this.isConnected = false;
|
|
90
|
+
this.stopPing();
|
|
87
91
|
this.emit('disconnected', { code, reason: reason.toString() });
|
|
88
92
|
if (this.autoReconnect && !this.destroyed) {
|
|
89
93
|
this.scheduleReconnect();
|
|
@@ -188,6 +192,20 @@ class RelayWebSocketClient extends events_1.EventEmitter {
|
|
|
188
192
|
console.error(`Error: code=${meta.code}, message=${meta.messageEn}`);
|
|
189
193
|
}
|
|
190
194
|
}
|
|
195
|
+
startPing() {
|
|
196
|
+
this.stopPing();
|
|
197
|
+
this.pingTimer = setInterval(() => {
|
|
198
|
+
if (this.ws && this.ws.readyState === ws_1.default.OPEN) {
|
|
199
|
+
this.ws.ping();
|
|
200
|
+
}
|
|
201
|
+
}, PING_INTERVAL_MS);
|
|
202
|
+
}
|
|
203
|
+
stopPing() {
|
|
204
|
+
if (this.pingTimer) {
|
|
205
|
+
clearInterval(this.pingTimer);
|
|
206
|
+
this.pingTimer = null;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
191
209
|
scheduleReconnect() {
|
|
192
210
|
if (this.destroyed)
|
|
193
211
|
return;
|
|
@@ -340,6 +358,7 @@ class RelayWebSocketClient extends events_1.EventEmitter {
|
|
|
340
358
|
destroy() {
|
|
341
359
|
this.destroyed = true;
|
|
342
360
|
this.autoReconnect = false;
|
|
361
|
+
this.stopPing();
|
|
343
362
|
if (this.reconnectTimer) {
|
|
344
363
|
clearTimeout(this.reconnectTimer);
|
|
345
364
|
this.reconnectTimer = null;
|