fix(voice): await remote-end upload before store removeCall to prevent sync cleanup race

This commit is contained in:
Tanmay Deep Sharma
2026-05-01 11:15:09 +07:00
parent 63c193358c
commit 069f25f88a
@@ -241,11 +241,16 @@ class ActionCableConnector extends BaseActionCableConnector {
};
// eslint-disable-next-line class-methods-use-this
onVoiceCallEnded = data => {
onVoiceCallEnded = async data => {
if (data?.provider !== 'whatsapp') return;
// Upload any in-memory recording chunks before tearing down the session,
// so contact-initiated hangups still produce an audio attachment.
handleWhatsappRemoteEnd(data.id).catch(() => {});
// Must await the upload-and-cleanup BEFORE removeCall, because the store's
// sync teardownByProvider -> cleanupWhatsappSession would otherwise wipe
// mediaRecorder + recorderChunks before any upload microtask gets to run.
try {
await handleWhatsappRemoteEnd(data.id);
} catch (_) {
/* noop — upload is best-effort */
}
useCallsStore().removeCall(data.call_id);
};
}