diff --git a/js/main.js b/js/main.js index e68b0aa..8db71c9 100644 --- a/js/main.js +++ b/js/main.js @@ -5,6 +5,7 @@ const username = root.dataset.username; const serverAddress = root.dataset.serverAddress; const apiBase = root.dataset.supportApiBase; + const supportWsBaseOverride = (root.dataset.supportWsBase || "").trim(); const RASTER_IMAGE_EXT = new Set(["jpg", "jpeg", "png", "gif", "webp", "bmp", "tif", "tiff", "heic", "heif"]); const RASTER_IMAGE_MIME = new Set([ @@ -149,10 +150,25 @@ } function wsUrlForTicket(ticketNumber) { + const tail = `/tickets/${encodeURIComponent(ticketNumber)}`; + if (supportWsBaseOverride) { + try { + const raw = supportWsBaseOverride.replace(/\/$/, ""); + const u = new URL(raw.includes("://") ? raw : `wss://${raw}`); + const wsProto = u.protocol === "https:" ? "wss:" : u.protocol === "http:" ? "ws:" : u.protocol; + let path = (u.pathname || "").replace(/\/$/, ""); + if (path === "" || path === "/") { + path = "/ws"; + } + return `${wsProto}//${u.host}${path}${tail}`; + } catch (_) { + return null; + } + } try { const u = new URL(apiBase); const wsProto = u.protocol === "https:" ? "wss:" : "ws:"; - return `${wsProto}//${u.host}/ws/tickets/${encodeURIComponent(ticketNumber)}`; + return `${wsProto}//${u.host}/ws${tail}`; } catch (_) { return null; } @@ -311,25 +327,26 @@