From 7767110982da5402b84be27025829d1d1fc58946 Mon Sep 17 00:00:00 2001 From: Carter Date: Fri, 20 Mar 2026 11:50:07 -0600 Subject: [PATCH] fixed duplicate v1 in url --- src/hooks/useDeviceStatusStreams.ts | 14 +------------- src/hooks/useWebSocket.ts | 15 +-------------- 2 files changed, 2 insertions(+), 27 deletions(-) diff --git a/src/hooks/useDeviceStatusStreams.ts b/src/hooks/useDeviceStatusStreams.ts index e235ebc..d04d663 100644 --- a/src/hooks/useDeviceStatusStreams.ts +++ b/src/hooks/useDeviceStatusStreams.ts @@ -1,22 +1,10 @@ import { pond } from "protobuf-ts/pond"; import { useEffect, useRef, useCallback, useMemo } from "react"; +import { getWsBaseUrl } from "utils/getWsBaseUrl"; /** Off by default to reduce server load; set VITE_ENABLE_WEBSOCKETS=true to enable live streams. */ const WEBSOCKETS_ENABLED = import.meta.env.VITE_ENABLE_WEBSOCKETS === "true"; -/** - * Derives the WebSocket base URL from VITE_APP_API_URL. - * Matches the logic in useWebSocket.ts. - */ -function getWsBaseUrl(): string { - const apiUrl = import.meta.env.VITE_APP_API_URL; - if (apiUrl) { - return apiUrl.replace(/^http/, "ws"); - } - const protocol = window.location.protocol === "https:" ? "wss:" : "ws:"; - return `${protocol}//${window.location.host}`; -} - export interface UseDeviceStatusStreamsOptions { /** Device IDs to stream status for (e.g. from the visible devices list) */ deviceIds: string[]; diff --git a/src/hooks/useWebSocket.ts b/src/hooks/useWebSocket.ts index 93d3aa2..9945f2d 100644 --- a/src/hooks/useWebSocket.ts +++ b/src/hooks/useWebSocket.ts @@ -1,22 +1,9 @@ import { useEffect, useRef, useCallback } from "react"; +import { getWsBaseUrl } from "utils/getWsBaseUrl"; /** Off by default to reduce server load; set VITE_ENABLE_WEBSOCKETS=true to enable live streams. */ const WEBSOCKETS_ENABLED = import.meta.env.VITE_ENABLE_WEBSOCKETS === "true"; -/** - * Derives the WebSocket base URL from VITE_APP_API_URL. - * e.g. "https://api.brandxtech.ca" -> "wss://api.brandxtech.ca" - * Falls back to current page host for local dev. - */ -function getWsBaseUrl(): string { - const apiUrl = import.meta.env.VITE_APP_API_URL; - if (apiUrl) { - return apiUrl.replace(/^http/, "ws"); - } - const protocol = window.location.protocol === "https:" ? "wss:" : "ws:"; - return `${protocol}//${window.location.host}`; -} - interface UseWebSocketOptions { /** The API path including /v1, e.g. "/v1/live/devices/123/components" */ path: string;