From 99f75f1cd18599e900ac73a2fc60f2f5d431ff6e Mon Sep 17 00:00:00 2001 From: Joren Date: Wed, 25 Sep 2024 15:47:39 +0200 Subject: [PATCH] Change the wss if https --- src/templates/progress | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/templates/progress b/src/templates/progress index 7b6162c..02934bd 100644 --- a/src/templates/progress +++ b/src/templates/progress @@ -218,13 +218,22 @@ } const consoleDiv = document.getElementById('console'); - const ws = new WebSocket(`ws://${window.location.host}/ws?filename=${filename}`); + const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'; + const ws = new WebSocket(`${protocol}//${window.location.host}/ws?filename=${filename}`); ws.onmessage = function(event) { consoleDiv.textContent += event.data; consoleDiv.scrollTop = consoleDiv.scrollHeight; }; + ws.onclose = function() { + console.log('WebSocket connection closed'); + }; + + ws.onerror = function(error) { + console.error('WebSocket error:', error); + }; + document.getElementById('toggle-console').onclick = function() { if (consoleDiv.style.display === "none") { consoleDiv.style.display = "block";