From 25973506b1726376fbee9ec9929499e15888078e Mon Sep 17 00:00:00 2001 From: Carter Date: Thu, 19 Mar 2026 12:50:23 -0600 Subject: [PATCH] temporarily gettin rid of web sockets --- src/hooks/useDeviceStatusStreams.ts | 5 ++++- src/hooks/useWebSocket.ts | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/hooks/useDeviceStatusStreams.ts b/src/hooks/useDeviceStatusStreams.ts index 24ca8bb..5c38058 100644 --- a/src/hooks/useDeviceStatusStreams.ts +++ b/src/hooks/useDeviceStatusStreams.ts @@ -1,6 +1,9 @@ import { pond } from "protobuf-ts/pond"; import { useEffect, useRef, useCallback, useMemo } from "react"; +/** 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. @@ -98,7 +101,7 @@ export function useDeviceStatusStreams(options: UseDeviceStatusStreamsOptions) { ); useEffect(() => { - if (!enabled || !token || deviceIds.length === 0) { + if (!WEBSOCKETS_ENABLED || !enabled || !token || deviceIds.length === 0) { wsMapRef.current.forEach((ws) => ws.close(1000, "disabled")); wsMapRef.current.clear(); reconnectTimeoutsRef.current.forEach((t) => clearTimeout(t)); diff --git a/src/hooks/useWebSocket.ts b/src/hooks/useWebSocket.ts index 6a4029d..ff6092c 100644 --- a/src/hooks/useWebSocket.ts +++ b/src/hooks/useWebSocket.ts @@ -1,5 +1,8 @@ import { useEffect, useRef, useCallback } from "react"; +/** 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" @@ -100,7 +103,7 @@ export function useWebSocket(options: UseWebSocketOptions) { }, [path, token, rate]); useEffect(() => { - if (!enabled || !token) { + if (!WEBSOCKETS_ENABLED || !enabled || !token) { if (wsRef.current) { wsRef.current.close(1000, "disabled"); wsRef.current = null;