Merge branch 'websocket_context' into staging_environment

This commit is contained in:
Carter 2026-03-20 11:50:17 -06:00
commit 587fdd455e
2 changed files with 2 additions and 27 deletions

View file

@ -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[];

View file

@ -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<T> {
/** The API path including /v1, e.g. "/v1/live/devices/123/components" */
path: string;