From 5b0cbc54d883bbc7dfa8d366bacec73b67df7464 Mon Sep 17 00:00:00 2001 From: Timo Bechtel Date: Mon, 23 Nov 2020 23:25:06 +0100 Subject: [PATCH] fix(client): add check for window object provides compatibility with nodejs --- src/client.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/client.ts b/src/client.ts index dca3448..cb0d2e2 100644 --- a/src/client.ts +++ b/src/client.ts @@ -19,10 +19,16 @@ type UpdateListener = { }; export function SocketDBClient({ - url = `ws://${window.location.hostname}:${window.location.port}`, + url, store = createStore(), socketClient = createWebsocketClient({ url }), }: { url?: string; store?: Store; socketClient?: SocketClient } = {}) { + if (!url) + url = + typeof window !== 'undefined' + ? `ws://${window.location.hostname}:${window.location.port}` + : 'ws://localhost:8080'; + const subscribedPaths: string[] = []; const updateListener: UpdateListener = {};