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

Function connect

app/src/modules/websocket.js:240–481  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

238}
239
240export function connect() {
241 let ws;
242 let connectErrorShown = false;
243 const isCurrentSocket = () => S.ws === ws;
244 const failConnect = (message) => {
245 if (connectErrorShown) return;
246 connectErrorShown = true;
247 hideHubConnectOverlay();
248 renderHubCards();
249 showToast(message);
250 };
251 try {
252 ws = new WebSocket(serverWsUrl);
253 } catch (e) {
254 failConnect('Invalid server address');
255 return;
256 }
257 S.ws = ws;
258 S.authenticated = false;
259 S.resumeRequestedFor = '';
260 S.replaying = true;
261 debugLog('ws_connect_start', {
262 serverWsUrl,
263 sessionId: S.sessionId || null,
264 hidden: typeof document !== 'undefined' ? !!document.hidden : null,
265 online: typeof navigator !== 'undefined' && 'onLine' in navigator ? !!navigator.onLine : null,
266 });
267
268 const connectTimeout = setTimeout(() => {
269 if (!isCurrentSocket()) return;
270 if (ws.readyState !== WebSocket.OPEN) {
271 ws.close();
272 failConnect('Connection timed out');
273 }
274 }, 8000);
275
276 ws.onopen = () => {
277 clearTimeout(connectTimeout);
278 if (!isCurrentSocket()) {
279 try { ws.close(); } catch {}
280 return;
281 }
282 clearForegroundProbe('ws_open');
283 S.lastMessageAt = Date.now();
284 S.intentionalDisconnect = false;
285 S.skipNextCloseHandling = false;
286 setStatus('starting');
287 ws.send(JSON.stringify({
288 type: 'hello',
289 clientInstanceId: CLIENT_INSTANCE_ID,
290 token: serverToken || '',
291 page: location.pathname || '/',
292 userAgent: navigator.userAgent || '',
293 }));
294 debugLog('ws_open', {
295 sessionId: S.sessionId || null,
296 waiting: S.waiting,
297 replaying: S.replaying,

Callers 4

connectToServerFunction · 0.90
reconnectFromForegroundFunction · 0.70
tryConnectFunction · 0.70

Calls 15

debugLogFunction · 0.90
wsReadyStateNameFunction · 0.90
flushPendingDebugLogsFunction · 0.90
processEventFunction · 0.90
handleUploadStatusFunction · 0.90
updateHeaderInfoFunction · 0.90
applyTurnStateFunction · 0.90
scheduleSessionCacheSaveFunction · 0.90
cacheTurnStateFunction · 0.90
setWaitingFunction · 0.90

Tested by

no test coverage detected