MCPcopy Create free account
hub / github.com/RioArisk/claudecode_api_RemoteControl / startForegroundProbe

Function startForegroundProbe

app/src/modules/websocket.js:91–129  ·  view source on GitHub ↗
(trigger)

Source from the content-addressed store, hash-verified

89}
90
91function startForegroundProbe(trigger) {
92 if (!S.ws || S.ws.readyState !== WebSocket.OPEN) return;
93 if (S.foregroundProbeId) return;
94
95 const probeId = `fg_${++S.foregroundProbeSeq}_${Date.now().toString(36)}`;
96 S.foregroundProbeId = probeId;
97 debugLog('foreground_probe_send', {
98 trigger,
99 probeId,
100 sessionId: S.sessionId || null,
101 lastSeq: S.lastSeq,
102 waiting: S.waiting,
103 wsState: wsReadyStateName(S.ws),
104 });
105
106 S.foregroundProbeTimer = setTimeout(() => {
107 if (S.foregroundProbeId !== probeId) return;
108 debugLog('foreground_probe_timeout', {
109 trigger,
110 probeId,
111 sessionId: S.sessionId || null,
112 lastSeq: S.lastSeq,
113 waiting: S.waiting,
114 wsState: wsReadyStateName(S.ws),
115 });
116 reconnectFromForeground('foreground_probe_timeout');
117 }, FOREGROUND_PROBE_TIMEOUT_MS);
118
119 try {
120 S.ws.send(JSON.stringify({
121 type: 'foreground_probe',
122 probeId,
123 sessionId: S.sessionId || null,
124 lastSeq: S.lastSeq,
125 }));
126 } catch {
127 reconnectFromForeground('foreground_probe_send_failed');
128 }
129}
130
131export function recoverConnectionOnForeground(trigger) {
132 if (typeof document !== 'undefined' && document.hidden) return;

Callers 1

Calls 3

debugLogFunction · 0.90
wsReadyStateNameFunction · 0.90
reconnectFromForegroundFunction · 0.70

Tested by

no test coverage detected