UNPKG

browser-debugger-cli

Version:

DevTools telemetry in your terminal. For humans and agents. Direct WebSocket to Chrome's debugging port.

49 lines 1.4 kB
/** * Socket Connection Manager * * Manages Unix domain socket connections with proper cleanup. */ import { connect } from 'net'; import { createLogger } from '../../ui/logging/index.js'; const log = createLogger('client'); /** * Create and configure a socket connection with event handlers. */ export function createSocket(config, handlers) { const socket = connect(config.socketPath); let timeoutHandle = null; socket.setEncoding('utf8'); socket.setNoDelay(true); if (handlers.onTimeout) { timeoutHandle = setTimeout(() => { handlers.onTimeout?.(); }, config.timeoutMs); } if (handlers.onConnect) { socket.once('connect', () => { log.debug(`Connected to daemon for ${config.requestName} request`); handlers.onConnect?.(socket); }); } if (handlers.onData) { socket.on('data', handlers.onData); } if (handlers.onError) { socket.once('error', handlers.onError); } if (handlers.onClose) { socket.once('close', handlers.onClose); } if (handlers.onEnd) { socket.once('end', handlers.onEnd); } const cleanup = () => { if (timeoutHandle) { clearTimeout(timeoutHandle); timeoutHandle = null; } socket.destroy(); }; return { socket, cleanup }; } //# sourceMappingURL=socket.js.map