temporarily gettin rid of web sockets

This commit is contained in:
Carter 2026-03-19 12:50:23 -06:00
parent 4326ecbd0f
commit 25973506b1
2 changed files with 8 additions and 2 deletions

View file

@ -1,6 +1,9 @@
import { pond } from "protobuf-ts/pond"; import { pond } from "protobuf-ts/pond";
import { useEffect, useRef, useCallback, useMemo } from "react"; 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. * Derives the WebSocket base URL from VITE_APP_API_URL.
* Matches the logic in useWebSocket.ts. * Matches the logic in useWebSocket.ts.
@ -98,7 +101,7 @@ export function useDeviceStatusStreams(options: UseDeviceStatusStreamsOptions) {
); );
useEffect(() => { 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.forEach((ws) => ws.close(1000, "disabled"));
wsMapRef.current.clear(); wsMapRef.current.clear();
reconnectTimeoutsRef.current.forEach((t) => clearTimeout(t)); reconnectTimeoutsRef.current.forEach((t) => clearTimeout(t));

View file

@ -1,5 +1,8 @@
import { useEffect, useRef, useCallback } from "react"; 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. * Derives the WebSocket base URL from VITE_APP_API_URL.
* e.g. "https://api.brandxtech.ca" -> "wss://api.brandxtech.ca" * e.g. "https://api.brandxtech.ca" -> "wss://api.brandxtech.ca"
@ -100,7 +103,7 @@ export function useWebSocket<T>(options: UseWebSocketOptions<T>) {
}, [path, token, rate]); }, [path, token, rate]);
useEffect(() => { useEffect(() => {
if (!enabled || !token) { if (!WEBSOCKETS_ENABLED || !enabled || !token) {
if (wsRef.current) { if (wsRef.current) {
wsRef.current.close(1000, "disabled"); wsRef.current.close(1000, "disabled");
wsRef.current = null; wsRef.current = null;