fix(api): Fixed websocket routing (#88)

Reviewed-on: #88
Co-authored-by: Janis <janis.e.20@gmx.de>
Co-committed-by: Janis <janis.e.20@gmx.de>
This commit is contained in:
2025-11-27 07:51:02 +01:00
committed by Janis
parent 14b4473f72
commit 46c96d4ceb

View File

@@ -91,7 +91,12 @@ function setupSocketHandlers(socket) {
}
// connect/disconnect helpers
function connectWebSocket(url = "ws://localhost:9000/websocket") {
function connectWebSocket(url = null) {
if (!url) {
const loc = window.location;
const protocol = loc.protocol === "https:" ? "wss:" : "ws:";
url = protocol + "//" + loc.host + "/websocket";
}
if (ws && ws.readyState === WebSocket.OPEN) return Promise.resolve();
if (ws && ws.readyState === WebSocket.CONNECTING) {
// already connecting - return a promise that resolves on open