Files
kandev/apps/web/components/ws-connector.tsx
T
2026-01-11 16:28:25 +00:00

22 lines
669 B
TypeScript

'use client';
import { useMemo } from 'react';
import { useAppStoreApi } from '@/components/state-provider';
import { getBackendConfig } from '@/lib/config';
import { httpToWebSocketUrl, isValidBackendUrl } from '@/lib/ws/utils';
import { useWebSocket } from '@/lib/ws/use-websocket';
export function WebSocketConnector() {
const store = useAppStoreApi();
const backendUrl = useMemo(() => {
const configured = getBackendConfig().apiBaseUrl;
return isValidBackendUrl(configured) ? configured : 'http://localhost:8080';
}, []);
const wsUrl = useMemo(() => httpToWebSocketUrl(backendUrl), [backendUrl]);
useWebSocket(store, wsUrl);
return null;
}