diff --git a/ui/services/websocket-client.js b/ui/services/websocket-client.js index 93428b87..208e0780 100644 --- a/ui/services/websocket-client.js +++ b/ui/services/websocket-client.js @@ -1,9 +1,19 @@ // WebSocket Client for Three.js Visualization - WiFi DensePose -// Connects to ws://localhost:8000/ws/pose and manages real-time data flow +// Default endpoint is `/ws/sensing` on the same host the page was served from. +// Callers (e.g. viz.html) usually pass an explicit `url` derived from +// `buildSensingWsUrl()` so HTTP/WS port pairings are handled centrally. + +function _defaultWsUrl() { + if (typeof window === 'undefined' || !window.location) { + return 'ws://localhost:8765/ws/sensing'; + } + const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'; + return `${protocol}//${window.location.host}/ws/sensing`; +} export class WebSocketClient { constructor(options = {}) { - this.url = options.url || 'ws://localhost:8000/ws/pose'; + this.url = options.url || _defaultWsUrl(); this.ws = null; this.state = 'disconnected'; // disconnected, connecting, connected, error this.isRealData = false; diff --git a/ui/utils/toast.js b/ui/utils/toast.js index ec1a097e..219c713a 100644 --- a/ui/utils/toast.js +++ b/ui/utils/toast.js @@ -27,6 +27,8 @@ export class ToastManager { action = null } = options; + if (!this.container) this.init(); + const id = ++this.idCounter; const toast = document.createElement('div'); toast.className = `toast toast-${type}`; diff --git a/ui/viz.html b/ui/viz.html index 54fa0a5f..1029f985 100644 --- a/ui/viz.html +++ b/ui/viz.html @@ -84,9 +84,23 @@
- - - + + + @@ -100,6 +114,7 @@ import { DashboardHUD } from './components/dashboard-hud.js'; import { WebSocketClient } from './services/websocket-client.js'; import { DataProcessor } from './services/data-processor.js'; + import { buildSensingWsUrl } from './services/sensing.service.js'; // -- Application State -- const state = { @@ -175,9 +190,12 @@ state.stats = initStats(); setLoadingProgress(85, 'Connecting to server...'); - // 8. WebSocket client + // 8. WebSocket client — derive URL from window.location so the page + // works on both default (HTTP 8080 / WS 8765) and Docker (3000/3001) + // port pairings. `?ws=…` query overrides for advanced setups. + const wsOverride = new URLSearchParams(window.location.search).get('ws'); state.wsClient = new WebSocketClient({ - url: 'ws://localhost:8000/ws/pose', + url: wsOverride || buildSensingWsUrl(), onMessage: (msg) => handleWebSocketMessage(msg), onStateChange: (newState, oldState) => handleConnectionStateChange(newState, oldState), onError: (err) => console.error('[VIZ] WebSocket error:', err)