fix: prevent StrictMode double-mount from killing SIP WebSocket connection

This commit is contained in:
2026-03-17 20:08:22 +05:30
parent b2cc3d7012
commit d54d54f5f3
3 changed files with 30 additions and 5 deletions

View File

@@ -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 {