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:
@@ -71,6 +71,11 @@ export const useSipPhone = (config?: Partial<SIPConfig>) => {
|
||||
return;
|
||||
}
|
||||
|
||||
// Don't reconnect if already connected or connecting
|
||||
if (sipClientRef.current?.isConnected() || sipClientRef.current?.isRegistered()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (sipClientRef.current) {
|
||||
sipClientRef.current.disconnect();
|
||||
}
|
||||
@@ -127,11 +132,15 @@ export const useSipPhone = (config?: Partial<SIPConfig>) => {
|
||||
setIsOnHold(!isOnHold);
|
||||
}, [isOnHold]);
|
||||
|
||||
// Cleanup on unmount
|
||||
// Cleanup only on actual page unload, not StrictMode remount
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
const handleUnload = () => {
|
||||
sipClientRef.current?.disconnect();
|
||||
};
|
||||
window.addEventListener('beforeunload', handleUnload);
|
||||
return () => {
|
||||
window.removeEventListener('beforeunload', handleUnload);
|
||||
};
|
||||
}, []);
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user