From 52ea2cc3e6c9779c59b88bc1bfc0c7e6d99e0042 Mon Sep 17 00:00:00 2001 From: Thibault Date: Wed, 29 May 2024 01:13:30 +0200 Subject: [PATCH] svelte: websocket protocol --- svelte/src/lib/websocket.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/svelte/src/lib/websocket.ts b/svelte/src/lib/websocket.ts index f8a196b..9e9a83e 100644 --- a/svelte/src/lib/websocket.ts +++ b/svelte/src/lib/websocket.ts @@ -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);