mirror of
https://dev.azure.com/globalhealthx/EMR/_git/helix-engage
synced 2026-04-11 18:28:15 +00:00
fix: prevent StrictMode double-mount from killing SIP WebSocket connection
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { createContext, useContext, useEffect, type PropsWithChildren } from 'react';
|
||||
import { createContext, useContext, useEffect, useRef, type PropsWithChildren } from 'react';
|
||||
import { useSipPhone } from '@/hooks/use-sip-phone';
|
||||
|
||||
type SipContextType = ReturnType<typeof useSipPhone>;
|
||||
@@ -7,10 +7,15 @@ const SipContext = createContext<SipContextType | null>(null);
|
||||
|
||||
export const SipProvider = ({ children }: PropsWithChildren) => {
|
||||
const sipPhone = useSipPhone();
|
||||
const hasConnected = useRef(false);
|
||||
|
||||
// Auto-connect on mount
|
||||
// Auto-connect on mount — skip StrictMode double-fire
|
||||
useEffect(() => {
|
||||
sipPhone.connect();
|
||||
if (!hasConnected.current) {
|
||||
hasConnected.current = true;
|
||||
sipPhone.connect();
|
||||
}
|
||||
// Do NOT disconnect on cleanup — the SIP connection should persist
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user