fix: inbound and outbound email
This commit is contained in:
@@ -6,11 +6,15 @@ export const useWhatsappCallsStore = defineStore('whatsappCalls', {
|
||||
incomingCalls: [],
|
||||
// The single active call (accepted + audio connected)
|
||||
activeCall: null,
|
||||
// Cleanup callback registered by the composable — called when a call ends externally
|
||||
_cleanupCallback: null,
|
||||
}),
|
||||
|
||||
getters: {
|
||||
hasIncomingCall: state => state.incomingCalls.length > 0,
|
||||
hasActiveCall: state => state.activeCall !== null,
|
||||
hasWhatsappCall: state =>
|
||||
state.incomingCalls.length > 0 || state.activeCall !== null,
|
||||
firstIncomingCall: state => state.incomingCalls[0] || null,
|
||||
},
|
||||
|
||||
@@ -33,8 +37,11 @@ export const useWhatsappCallsStore = defineStore('whatsappCalls', {
|
||||
this.activeCall = null;
|
||||
},
|
||||
|
||||
registerCleanupCallback(callback) {
|
||||
this._cleanupCallback = callback;
|
||||
},
|
||||
|
||||
handleCallAcceptedByOther(callId) {
|
||||
// Another agent accepted — remove from incoming list for this agent
|
||||
this.removeIncomingCall(callId);
|
||||
},
|
||||
|
||||
@@ -42,6 +49,24 @@ export const useWhatsappCallsStore = defineStore('whatsappCalls', {
|
||||
this.removeIncomingCall(callId);
|
||||
if (this.activeCall?.callId === callId) {
|
||||
this.activeCall = null;
|
||||
// Trigger WebRTC cleanup via the registered callback
|
||||
if (this._cleanupCallback) {
|
||||
this._cleanupCallback();
|
||||
}
|
||||
}
|
||||
// Also clean up outbound call globals if they match
|
||||
if (window.__outboundCallId === callId) {
|
||||
if (window.__outboundCallPC) window.__outboundCallPC.close();
|
||||
if (window.__outboundCallStream)
|
||||
window.__outboundCallStream.getTracks().forEach(t => t.stop());
|
||||
if (window.__outboundCallAudio) {
|
||||
window.__outboundCallAudio.srcObject = null;
|
||||
window.__outboundCallAudio.remove();
|
||||
}
|
||||
window.__outboundCallPC = null;
|
||||
window.__outboundCallStream = null;
|
||||
window.__outboundCallAudio = null;
|
||||
window.__outboundCallId = null;
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user