Change the wss if https

This commit is contained in:
Joren 2024-09-25 15:47:39 +02:00
parent c7712982f3
commit 99f75f1cd1
Signed by: Joren
GPG Key ID: 280E33DFBC0F1B55

View File

@ -218,13 +218,22 @@
} }
const consoleDiv = document.getElementById('console'); 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) { ws.onmessage = function(event) {
consoleDiv.textContent += event.data; consoleDiv.textContent += event.data;
consoleDiv.scrollTop = consoleDiv.scrollHeight; 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() { document.getElementById('toggle-console').onclick = function() {
if (consoleDiv.style.display === "none") { if (consoleDiv.style.display === "none") {
consoleDiv.style.display = "block"; consoleDiv.style.display = "block";