diff --git a/packages/plugin/src/node-websocket.ts b/packages/plugin/src/node-websocket.ts new file mode 100644 index 0000000..5d9a426 --- /dev/null +++ b/packages/plugin/src/node-websocket.ts @@ -0,0 +1,18 @@ +import WebSocket from 'ws' + +/** + * Host control / Relay data sockets for the Plugin Host process (#353). + * + * Scope: `HostServerConnection` only. `dsh web` replaces the process-global + * `WebSocket` with an implementation that attaches `Origin` from the Harness + * page. Self-hosted Servers compare that header to `DSH_SERVER_PUBLIC_URL` and + * reject mismatches (`origin_mismatch` → Host stays offline). + * + * The bundled `ws` client omits `Origin` unless `origin` is set. Browser Remote + * clients and AdaptiveTransport / RelayTransport keep the global `WebSocket` + * (browsers must send Origin). Plugin Client mode in `dsh web` is out of scope + * for this fix and needs its own justification and coverage if required later. + */ +export function createNodeWebSocket(url: string): WebSocket { + return new WebSocket(url, { perMessageDeflate: false }) +}