orchestrating 0.1.18 → 0.1.19

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/bin/orch +25 -0
  2. package/package.json +1 -1
package/bin/orch CHANGED
@@ -273,9 +273,13 @@ if (!authToken && !serverUrl.includes("localhost") && !serverUrl.includes("127.0
273
273
 
274
274
  // --- WebSocket connection with reconnect ---
275
275
  const BUFFER_MAX = 50 * 1024; // 50KB reconnect buffer
276
+ const PING_INTERVAL_MS = 30_000; // 30s keepalive ping
277
+ const PONG_TIMEOUT_MS = 10_000; // 10s to receive pong before assuming dead
276
278
  let ws = null;
277
279
  let wsReady = false;
278
280
  let reconnectTimer = null;
281
+ let pingTimer = null;
282
+ let pongTimer = null;
279
283
  let authFailed = false;
280
284
  const sendBuffer = [];
281
285
  let bufferSize = 0;
@@ -920,6 +924,23 @@ async function connectWs() {
920
924
  if (adapter) {
921
925
  broadcastPermissions();
922
926
  }
927
+
928
+ // Keepalive: send WebSocket ping frames every 30s to prevent idle disconnects
929
+ if (pingTimer) clearInterval(pingTimer);
930
+ if (pongTimer) clearTimeout(pongTimer);
931
+ pingTimer = setInterval(() => {
932
+ if (ws && ws.readyState === WebSocket.OPEN) {
933
+ ws.ping();
934
+ pongTimer = setTimeout(() => {
935
+ // No pong received — connection is dead, force reconnect
936
+ if (ws) ws.terminate();
937
+ }, PONG_TIMEOUT_MS);
938
+ }
939
+ }, PING_INTERVAL_MS);
940
+ });
941
+
942
+ ws.on("pong", () => {
943
+ if (pongTimer) { clearTimeout(pongTimer); pongTimer = null; }
923
944
  });
924
945
 
925
946
  ws.on("message", (raw) => {
@@ -950,6 +971,8 @@ async function connectWs() {
950
971
  ws.on("close", () => {
951
972
  wsReady = false;
952
973
  ws = null;
974
+ if (pingTimer) { clearInterval(pingTimer); pingTimer = null; }
975
+ if (pongTimer) { clearTimeout(pongTimer); pongTimer = null; }
953
976
  if (!authFailed) {
954
977
  reconnectTimer = setTimeout(connectWs, 2000);
955
978
  }
@@ -986,6 +1009,8 @@ function revokeSessionPermissions() {
986
1009
 
987
1010
  function cleanup() {
988
1011
  revokeSessionPermissions();
1012
+ if (pingTimer) clearInterval(pingTimer);
1013
+ if (pongTimer) clearTimeout(pongTimer);
989
1014
  if (reconnectTimer) clearTimeout(reconnectTimer);
990
1015
  if (ws) ws.close();
991
1016
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orchestrating",
3
- "version": "0.1.18",
3
+ "version": "0.1.19",
4
4
  "description": "Stream terminal sessions to the orchestrat.ing dashboard",
5
5
  "type": "module",
6
6
  "bin": {