From 06bf888bd85432ffdf61fc5842cb41ced551484f Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Fri, 29 Sep 2023 19:31:43 +0200 Subject: [PATCH] Allow supply of WebSocket constructor --- packages/ws-relay/src/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/ws-relay/src/index.ts b/packages/ws-relay/src/index.ts index 53d02e2..1cc3915 100644 --- a/packages/ws-relay/src/index.ts +++ b/packages/ws-relay/src/index.ts @@ -33,7 +33,7 @@ type TransportState = { peer: Ref, }; -export function boot(ds: Ref, debug: boolean = false) { +export function boot(ds: Ref, debug: boolean = false, WebSocketConstructor?: typeof WebSocket) { spawn named 'transportConnector' { at ds { during Observe({ "pattern": :pattern G.TransportConnection({ @@ -107,7 +107,7 @@ export function boot(ds: Ref, debug: boolean = false) { setTimeout(() => facet.turn(() => { stop {} }), 10000); } try { - const ws = new WebSocket(addr.url); + const ws = new (WebSocketConstructor ?? WebSocket)(addr.url); ws.binaryType = 'arraybuffer'; ws.onopen = () => facet.turn(() => succeed(ws)); ws.onclose = () => facet.turn(() => fail(Symbol.for('closed')));