From 6324979913ae32e9572a90fd3ba4d9c3815fb8fa Mon Sep 17 00:00:00 2001 From: Donkie Date: Wed, 18 Oct 2023 19:24:27 +0200 Subject: [PATCH] Fixed client websocket URL converter TLS --- client/src/components/liveProvider.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/client/src/components/liveProvider.ts b/client/src/components/liveProvider.ts index 6815cea..b4d16b0 100644 --- a/client/src/components/liveProvider.ts +++ b/client/src/components/liveProvider.ts @@ -15,7 +15,7 @@ interface Event { /** * Converts an API URL to a WebSocket URL. - * E.g. "https://example.com/api/v1/..." -> "ws://example.com/api/v1/..." + * E.g. "https://example.com/api/v1/..." -> "wss://example.com/api/v1/..." * or "/api/v1/..." -> "ws://example.com/api/v1/..." * @param apiUrl The API URL to convert * @returns The WebSocket URL @@ -29,10 +29,14 @@ function toWebsocketURL(apiUrl: string) { // Split the URL to separate the protocol, host, and path const urlParts = currentURL.split("/"); + const protocol = urlParts[0]; const host = urlParts[2]; - // Create the WebSocket URL by adding "ws://" as the protocol and the relative URL as the path - return `ws://${host}${apiUrl}`; + if (protocol === "https:") { + return `wss://${host}${apiUrl}`; + } else { + return `ws://${host}${apiUrl}`; + } } else { // Absolute URL, e.g. "https://example.com/api/v1/..."