MCPcopy Create free account
hub / github.com/modem-dev/hunk / openRegisteredSocket

Function openRegisteredSocket

scripts/daemon-memory-check.ts:342–381  ·  view source on GitHub ↗
(
  port: number,
  sessionId: string,
  cycle: number,
  sessionIndex: number,
  options: CliOptions,
)

Source from the content-addressed store, hash-verified

340}
341
342async function openRegisteredSocket(
343 port: number,
344 sessionId: string,
345 cycle: number,
346 sessionIndex: number,
347 options: CliOptions,
348) {
349 const socket = new WebSocket(`ws://127.0.0.1:${port}/session`);
350 await new Promise<void>((resolve, reject) => {
351 const timeout = setTimeout(
352 () => reject(new Error(`Timed out opening websocket for ${sessionId}.`)),
353 2_000,
354 );
355 socket.addEventListener(
356 "open",
357 () => {
358 clearTimeout(timeout);
359 resolve();
360 },
361 { once: true },
362 );
363 socket.addEventListener(
364 "error",
365 () => {
366 clearTimeout(timeout);
367 reject(new Error(`Websocket failed for ${sessionId}.`));
368 },
369 { once: true },
370 );
371 });
372
373 socket.send(
374 JSON.stringify({
375 type: "register",
376 registration: makeRegistration(sessionId, cycle, sessionIndex, options),
377 snapshot: makeSnapshot(sessionId, 0, options),
378 }),
379 );
380 return socket;
381}
382
383async function sendSnapshotUpdates(
384 sockets: WebSocket[],

Callers 1

mainFunction · 0.85

Calls 3

makeRegistrationFunction · 0.85
makeSnapshotFunction · 0.85
sendMethod · 0.65

Tested by

no test coverage detected