fix(api): Fixed websocket routing

This commit is contained in:
2025-11-26 18:41:15 +01:00
parent 576e5af87e
commit 25c3c61c8c

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