Skip to content

Commit

Permalink
svelte: websocket protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
tbmc committed May 28, 2024
1 parent 9ba243c commit 52ea2cc
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion svelte/src/lib/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ export const connectWebsocket = (
}
};

const protocol = window.location.protocol;
const websocketProtocol = protocol.includes('https') ? 'wss' : 'ws';
const host = window.location.host;
socket = new WebSocket(`ws://${host}/`);
socket = new WebSocket(`${websocketProtocol}://${host}/`);
socket.addEventListener('open', onOpen);
socket.addEventListener('message', onMessage);

Expand Down

0 comments on commit 52ea2cc

Please sign in to comment.