mirror of
https://dev.azure.com/globalhealthx/EMR/_git/helix-engage
synced 2026-04-11 18:28:15 +00:00
fix: prevent SIP disconnect during active call
disconnectSip() now guards against disconnect when outboundPending or outboundActive is true. Accepts force=true for intentional disconnects (logout, page unload, component unmount). Prevents React re-render cycles from killing the SIP WebSocket mid-dial, which was causing the call to drop and disposition modal to not appear. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -125,14 +125,14 @@ export const SipProvider = ({ children }: PropsWithChildren) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleUnload = () => disconnectSip();
|
const handleUnload = () => disconnectSip(true);
|
||||||
|
|
||||||
window.addEventListener('beforeunload', handleBeforeUnload);
|
window.addEventListener('beforeunload', handleBeforeUnload);
|
||||||
window.addEventListener('unload', handleUnload);
|
window.addEventListener('unload', handleUnload);
|
||||||
return () => {
|
return () => {
|
||||||
window.removeEventListener('beforeunload', handleBeforeUnload);
|
window.removeEventListener('beforeunload', handleBeforeUnload);
|
||||||
window.removeEventListener('unload', handleUnload);
|
window.removeEventListener('unload', handleUnload);
|
||||||
disconnectSip();
|
disconnectSip(true); // force — component is unmounting
|
||||||
};
|
};
|
||||||
}, []); // empty deps — runs once on mount, cleanup only on unmount
|
}, []); // empty deps — runs once on mount, cleanup only on unmount
|
||||||
|
|
||||||
|
|||||||
@@ -81,8 +81,16 @@ export function connectSip(config: SIPConfig): void {
|
|||||||
sipClient.connect();
|
sipClient.connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function disconnectSip(): void {
|
export function disconnectSip(force = false): void {
|
||||||
console.log('[SIP-MGR] Disconnecting SIP');
|
// Guard: don't disconnect SIP during an active or pending call
|
||||||
|
// unless explicitly forced (e.g., logout, page unload).
|
||||||
|
// This prevents React re-render cycles from killing the
|
||||||
|
// SIP WebSocket mid-dial.
|
||||||
|
if (!force && (outboundPending || outboundActive)) {
|
||||||
|
console.log('[SIP-MGR] Disconnect blocked — call in progress');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log('[SIP-MGR] Disconnecting SIP' + (force ? ' (forced)' : ''));
|
||||||
sipClient?.disconnect();
|
sipClient?.disconnect();
|
||||||
sipClient = null;
|
sipClient = null;
|
||||||
connected = false;
|
connected = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user