diff options
Diffstat (limited to 'src/daemon')
| -rw-r--r-- | src/daemon/bridge.ts | 8 | ||||
| -rw-r--r-- | src/daemon/index.ts | 5 | ||||
| -rw-r--r-- | src/daemon/protocol.ts | 5 | ||||
| -rw-r--r-- | src/daemon/server.ts | 12 | ||||
| -rw-r--r-- | src/daemon/spawn.ts | 1 |
5 files changed, 3 insertions, 28 deletions
diff --git a/src/daemon/bridge.ts b/src/daemon/bridge.ts index bc162a7..95f6888 100644 --- a/src/daemon/bridge.ts +++ b/src/daemon/bridge.ts @@ -1,4 +1,3 @@ - import WebSocket from "ws"; import { discoverWsUrl } from "../cdp/discovery"; import { isCdpRawMessage } from "../cdp/types"; @@ -7,7 +6,6 @@ import type { WireRequest, WireResponse, WireEvent } from "./protocol"; import { CDP_CONNECT_TIMEOUT_MS, CDP_COMMAND_TIMEOUT_MS } from "./protocol"; import { asString, isRecord } from "../util/guards"; - export type SendToClient = (clientId: string, msg: WireResponse | WireEvent) => void; export type EventHandler = (event: WireEvent, targetClientIds: string[]) => void; @@ -27,7 +25,6 @@ export type CdpBridge = { onClose(handler: CloseHandler): void; }; - interface PendingEntry { clientId: string; localId: number; @@ -63,7 +60,6 @@ class IdMultiplexer { } } - class EventRouter { private owners = new Map<string, string>(); private clientSessions = new Map<string, Set<string>>(); @@ -108,7 +104,6 @@ class EventRouter { } } - export const createCdpBridge = (): CdpBridge => { let ws: WebSocket | null = null; let wsUrl: string | null = null; @@ -125,7 +120,6 @@ export const createCdpBridge = (): CdpBridge => { isAttach: boolean; }>(); - const onChromeMessage = (raw: string): void => { let parsed: unknown; try { parsed = JSON.parse(raw); } catch { return; } @@ -184,8 +178,6 @@ export const createCdpBridge = (): CdpBridge => { } }; - - let reconnectTimer: ReturnType<typeof setTimeout> | null = null; let reconnectAttempt = 0; let stopped = false; diff --git a/src/daemon/index.ts b/src/daemon/index.ts index 30a6b6e..226a895 100644 --- a/src/daemon/index.ts +++ b/src/daemon/index.ts @@ -1,4 +1,3 @@ - import { createIpcServer } from "./server"; import { createCdpBridge, type SendToClient } from "./bridge"; import { DAEMON_IDLE_TIMEOUT_MS } from "./protocol"; @@ -9,7 +8,6 @@ async function main() { const ipcServer = createIpcServer(); const cdpBridge = createCdpBridge(); - ipcServer.onMessage((msg, client) => { if (msg.type !== "request") return; @@ -39,7 +37,6 @@ async function main() { }); }); - let idleTimer: ReturnType<typeof setTimeout> | null = null; const resetIdleTimer = (): void => { @@ -60,7 +57,6 @@ async function main() { ipcServer.onConnect(() => { cancelIdleTimer(); }); ipcServer.onDisconnect(() => { resetIdleTimer(); }); - try { await ipcServer.start(); console.log("[pi-browser-daemon] IPC server listening"); @@ -73,7 +69,6 @@ async function main() { resetIdleTimer(); - const shutdown = async () => { console.log("[pi-browser-daemon] Shutting down..."); await cdpBridge.stop(); diff --git a/src/daemon/protocol.ts b/src/daemon/protocol.ts index d3d8297..43c89de 100644 --- a/src/daemon/protocol.ts +++ b/src/daemon/protocol.ts @@ -1,7 +1,5 @@ - import { isRecord } from "../util/guards"; - export type WireRequest = { readonly type: "request"; readonly id: number; @@ -37,7 +35,6 @@ export type WireControl = { export type WireMessage = WireRequest | WireResponse | WireEvent | WireControl; - export const isWireMessage = (v: unknown): v is WireMessage => { if (!isRecord(v)) return false; const t = v["type"]; @@ -85,7 +82,6 @@ export const isWireMessage = (v: unknown): v is WireMessage => { } }; - export const serialize = (msg: WireMessage): string => JSON.stringify(msg); export const deserialize = (line: string): WireMessage | null => { @@ -99,7 +95,6 @@ export const deserialize = (line: string): WireMessage | null => { return parsed; }; - // Windows requires a named pipe (`\\.\pipe\<name>`); a Unix path is not a valid `net` listen/connect target there. export const DAEMON_SOCKET_PATH = process.platform === "win32" diff --git a/src/daemon/server.ts b/src/daemon/server.ts index b694fc0..7c78372 100644 --- a/src/daemon/server.ts +++ b/src/daemon/server.ts @@ -1,4 +1,3 @@ - import { createServer, type Server, type Socket } from "node:net"; import { createInterface, type Interface } from "node:readline"; import { unlinkSync } from "node:fs"; @@ -11,7 +10,6 @@ import { DAEMON_STALE_SOCKET_CLEANUP, } from "./protocol"; - export type ClientSocket = { id: string; readonly socket: Socket; @@ -36,7 +34,6 @@ export type IpcServer = { clientCount(): number; }; - export const createIpcServer = (): IpcServer => { let server: Server | null = null; const sockets = new Map<string, ClientSocket>(); @@ -51,8 +48,7 @@ export const createIpcServer = (): IpcServer => { if (DAEMON_STALE_SOCKET_CLEANUP) { try { unlinkSync(DAEMON_SOCKET_PATH); - } catch { - } + } catch {} } server = createServer({ pauseOnConnect: false }, (socket: Socket) => { @@ -113,8 +109,7 @@ export const createIpcServer = (): IpcServer => { messageHandler?.(msg, currentClient); }); - socket.on("error", () => { - }); + socket.on("error", () => {}); socket.on("close", () => { const found = clients.get(currentClient.id) ?? sockets.get(tempId); @@ -176,8 +171,7 @@ export const createIpcServer = (): IpcServer => { if (!client) return; try { client.socket.write(JSON.stringify(msg) + "\n"); - } catch { - } + } catch {} }, broadcast(msg) { for (const [clientId] of clients) { diff --git a/src/daemon/spawn.ts b/src/daemon/spawn.ts index d14d234..a88855f 100644 --- a/src/daemon/spawn.ts +++ b/src/daemon/spawn.ts @@ -1,4 +1,3 @@ - import { spawn, type ChildProcess } from "node:child_process"; import { access, unlink } from "node:fs/promises"; import { existsSync } from "node:fs"; |
