Refactor WebSocket connection to support HTTPS

This commit is contained in:
Yohann Streibel 2025-12-18 00:16:15 +01:00 committed by GitHub
parent eb75868adb
commit 16e47163ec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -469,7 +469,9 @@ async function initSockets() {
ui.waitMessage(document.getElementById('divContainer')).classList.add('socket-wait'); ui.waitMessage(document.getElementById('divContainer')).classList.add('socket-wait');
let host = window.location.protocol === 'file:' ? hst : window.location.hostname; let host = window.location.protocol === 'file:' ? hst : window.location.hostname;
try { try {
socket = new WebSocket(`ws://${host}:8080/`); const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
const port = window.location.protocol === 'https:' ? '' : ':8080';
socket = new WebSocket(`${protocol}//${host}${port}/`);
socket.onmessage = (evt) => { socket.onmessage = (evt) => {
if (evt.data.startsWith('42')) { if (evt.data.startsWith('42')) {
let ndx = evt.data.indexOf(','); let ndx = evt.data.indexOf(',');