From d8e75e5b49fd2b8fc2cefd9f5d8a969ce703096d Mon Sep 17 00:00:00 2001
From: Per Qvarforth <per@qvarforth.se>
Date: Sun, 27 Feb 2022 17:13:07 +0000
Subject: [PATCH] Added websocket url to config file

---
 config/trackdirect.ini  | 4 ++++
 htdocs/public/index.php | 6 +++---
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/config/trackdirect.ini b/config/trackdirect.ini
index af33eed..fa4ee97 100644
--- a/config/trackdirect.ini
+++ b/config/trackdirect.ini
@@ -23,6 +23,10 @@ leaflet_raster_tile_satellite=""            ;; Examples: "HERE.satelliteDay"
 coverage_only_moving_senders="0"
 coverage_percentile="95"
 
+;; Url to the websocket server, if you use https you need to set this
+;; If nothing is set we will try the url: ws://current-url:9000/ws
+;websocket_url="wss://ws.my-domain.com"
+
 
 [database]
 
diff --git a/htdocs/public/index.php b/htdocs/public/index.php
index c26188b..9cefff1 100755
--- a/htdocs/public/index.php
+++ b/htdocs/public/index.php
@@ -146,9 +146,9 @@ $REQUEST_PROTOCOL = $isSecure ? 'https' : 'http';
                     options['host'] = "<?php echo $_SERVER['HTTP_HOST']; ?>";
 
                     var supportsWebSockets = 'WebSocket' in window || 'MozWebSocket' in window;
-                    if (supportsWebSockets) {
-                        <?php if ($REQUEST_PROTOCOL == 'https') : ?>
-                            var wsServerUrl = 'wss://<?php echo $_SERVER['HTTP_HOST']; ?>:9000/ws';
+		    if (supportsWebSockets) {
+                       <?php if (getWebsiteConfig('websocket_url') != null) : ?>
+                           var wsServerUrl = "<?php echo getWebsiteConfig('websocket_url'); ?>";
                         <?php else : ?>
                             var wsServerUrl = 'ws://<?php echo $_SERVER['HTTP_HOST']; ?>:9000/ws';
                         <?php endif; ?>
-- 
GitLab