MCPcopy Create free account
hub / github.com/Snapchat/Valdi / connectToDaemon

Function connectToDaemon

npm_modules/cli/src/utils/daemonClient.ts:386–417  ·  view source on GitHub ↗
(port: number = DEFAULT_PORT)

Source from the content-addressed store, hash-verified

384}
385
386export async function connectToDaemon(port: number = DEFAULT_PORT): Promise<DaemonConnection> {
387 // Only set up adb forwarding for mobile ports — standalone macOS apps listen
388 // directly on localhost and adb forward would shadow them.
389 if (port !== STANDALONE_PORT) {
390 await tryAdbForward(port);
391 }
392 return new Promise((resolve, reject) => {
393 const socket = net.createConnection({ port, host: '127.0.0.1' });
394
395 const timer = setTimeout(() => {
396 socket.destroy();
397 reject(new Error(`Timeout connecting to Valdi daemon on port ${port}. Is the hot-reloader running?`));
398 }, 5_000);
399
400 socket.once('connect', () => {
401 clearTimeout(timer);
402 resolve(new DaemonConnection(socket));
403 });
404
405 socket.once('error', (err: NodeJS.ErrnoException) => {
406 clearTimeout(timer);
407 if (err.code === 'ECONNREFUSED') {
408 reject(new CliError(
409 `Valdi daemon not running on port ${port}.\n` +
410 `Start the hot-reloader (valdi hotreload) or pass --port to use a different port.`,
411 ));
412 } else {
413 reject(err);
414 }
415 });
416 });
417}
418
419// ─── Device / context selection helpers ──────────────────────────────────────
420

Callers 7

inspectStatusFunction · 0.90
inspectHeapFunction · 0.90
inspectSelectFunction · 0.90
inspectDevicesFunction · 0.90
inspectSnapshotFunction · 0.90
inspectTreeFunction · 0.90
inspectContextsFunction · 0.90

Calls 7

tryAdbForwardFunction · 0.85
rejectFunction · 0.85
destroyMethod · 0.65
onceMethod · 0.65
setTimeoutFunction · 0.50
clearTimeoutFunction · 0.50
resolveFunction · 0.50

Tested by

no test coverage detected