From ef97d81a7fafa56e50744c5fc286155571c412d1 Mon Sep 17 00:00:00 2001 From: Per Qvarforth Date: Sun, 12 Jan 2025 23:18:52 +0100 Subject: [PATCH] Websocket url fix --- htdocs/public/index.php | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/htdocs/public/index.php b/htdocs/public/index.php index b913dc9..2f741f3 100755 --- a/htdocs/public/index.php +++ b/htdocs/public/index.php @@ -139,13 +139,21 @@ // host is used to create url to /heatmaps and /images (leave empty to use same host as website) options['host'] = ""; - var supportsWebSockets = 'WebSocket' in window || 'MozWebSocket' in window; - if (supportsWebSockets) { - - var wsServerUrl = ""; + if (supportsWebSockets) { + + var wsServerUrl = ""; - var wsServerUrl = 'ws://:/ws'; + var wsServerUrl = ''; + if (window.location.protocol == 'https:') { + wsServerUrl += 'wss://' + window.location.host; + } else { + wsServerUrl += 'ws://' + window.location.host; + } + if (window.location.port != '' && window.location.port != 0) { + wsServerUrl += ':' + window.location.port; + } + wsServerUrl += '/ws'; var mapElementId = 'map-container'; @@ -251,7 +259,7 @@ -