Skip to content

Commit

Permalink
fix(client): add check for window object
Browse files Browse the repository at this point in the history
provides compatibility with nodejs
  • Loading branch information
TimoBechtel committed Nov 23, 2020
1 parent 268ba28 commit 5b0cbc5
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};

Expand Down

0 comments on commit 5b0cbc5

Please sign in to comment.