mirror of
https://dev.azure.com/globalhealthx/EMR/_git/helix-engage
synced 2026-04-11 18:28:15 +00:00
- Replace mock DataProvider with real GraphQL queries through sidecar - Add queries.ts and transforms.ts for platform field name mapping - Migrate SIP state from React Context to Jotai atoms (React 19 compat) - Add singleton SIP manager to survive StrictMode remounts - Remove hardcoded Olivia/Sienna accounts from nav menu - Add password eye toggle, remember me checkbox, forgot password link - Fix worklist hook to transform platform field names - Add seed scripts for clinics, health packages, lab tests - Update test harness for new doctor→clinic relation Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
59 lines
1.5 KiB
TypeScript
59 lines
1.5 KiB
TypeScript
import { SIPClient } from '@/lib/sip-client';
|
|
import type { SIPConfig, ConnectionStatus, CallState } from '@/types/sip';
|
|
|
|
// Singleton SIP client — survives React StrictMode remounts
|
|
let sipClient: SIPClient | null = null;
|
|
let connected = false;
|
|
|
|
type StateUpdater = {
|
|
setConnectionStatus: (status: ConnectionStatus) => void;
|
|
setCallState: (state: CallState) => void;
|
|
setCallerNumber: (number: string | null) => void;
|
|
};
|
|
|
|
let stateUpdater: StateUpdater | null = null;
|
|
|
|
export function registerSipStateUpdater(updater: StateUpdater) {
|
|
stateUpdater = updater;
|
|
}
|
|
|
|
export function connectSip(config: SIPConfig): void {
|
|
if (connected || sipClient?.isRegistered() || sipClient?.isConnected()) {
|
|
return;
|
|
}
|
|
|
|
if (!config.wsServer || !config.uri) {
|
|
console.warn('SIP config incomplete — wsServer and uri required');
|
|
return;
|
|
}
|
|
|
|
if (sipClient) {
|
|
sipClient.disconnect();
|
|
}
|
|
|
|
connected = true;
|
|
stateUpdater?.setConnectionStatus('connecting');
|
|
|
|
sipClient = new SIPClient(
|
|
config,
|
|
(status) => stateUpdater?.setConnectionStatus(status),
|
|
(state, number) => {
|
|
stateUpdater?.setCallState(state);
|
|
if (number !== undefined) stateUpdater?.setCallerNumber(number ?? null);
|
|
},
|
|
);
|
|
|
|
sipClient.connect();
|
|
}
|
|
|
|
export function disconnectSip(): void {
|
|
sipClient?.disconnect();
|
|
sipClient = null;
|
|
connected = false;
|
|
stateUpdater?.setConnectionStatus('disconnected');
|
|
}
|
|
|
|
export function getSipClient(): SIPClient | null {
|
|
return sipClient;
|
|
}
|