From 1c00f76dd5cdcd1660b5662a5e6499a42133d00f Mon Sep 17 00:00:00 2001 From: sdca Date: Thu, 27 Oct 2022 14:48:30 -0400 Subject: [PATCH] Dynamic switch for ws/wss Enables belaUI to be served over an HTTPS reverse proxy --- public/script.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/public/script.js b/public/script.js index d0ed3e0..d70c765 100644 --- a/public/script.js +++ b/public/script.js @@ -21,7 +21,11 @@ let config = {}; let ws = null; function tryConnect() { - let c = new WebSocket("ws://" + window.location.host); + let wsProtocol = 'ws://'; + if (window.location.protocol === 'https:') { + wsProtocol = 'wss://'; + } + let c = new WebSocket(wsProtocol + window.location.host); c.addEventListener('message', function (event) { handleMessage(JSON.parse(event.data)); });