whatsapp calls fixes
This commit is contained in:
@@ -32,9 +32,10 @@ class WhatsappCallsAPI {
|
||||
return axios.post(`${this.baseUrl}/${callId}/terminate`);
|
||||
}
|
||||
|
||||
initiate(conversationId) {
|
||||
initiate(conversationId, sdpOffer) {
|
||||
return axios.post(`${this.baseUrl}/initiate`, {
|
||||
conversation_id: conversationId,
|
||||
sdp_offer: sdpOffer,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,19 +97,54 @@ const hasSlaPolicyId = computed(() => props.chat?.sla_policy_id);
|
||||
|
||||
const canInitiateWhatsappCall = computed(() => {
|
||||
if (!isAWhatsAppCloudChannel.value) return false;
|
||||
return !!inbox.value?.callingEnabled;
|
||||
return !!inbox.value?.calling_enabled;
|
||||
});
|
||||
|
||||
const initiateWhatsappCall = async () => {
|
||||
if (isInitiatingCall.value || !currentChat.value?.id) return;
|
||||
isInitiatingCall.value = true;
|
||||
let pc = null;
|
||||
let localStream = null;
|
||||
try {
|
||||
await WhatsappCallsAPI.initiate(currentChat.value.id);
|
||||
localStream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
||||
pc = new RTCPeerConnection({
|
||||
iceServers: [{ urls: 'stun:stun.l.google.com:19302' }],
|
||||
});
|
||||
localStream.getTracks().forEach(track => pc.addTrack(track, localStream));
|
||||
|
||||
const offer = await pc.createOffer();
|
||||
await pc.setLocalDescription(offer);
|
||||
|
||||
const response = await WhatsappCallsAPI.initiate(
|
||||
currentChat.value.id,
|
||||
offer.sdp
|
||||
);
|
||||
|
||||
const callStatus = response.data?.status;
|
||||
if (callStatus === 'permission_requested' || callStatus === 'permission_pending') {
|
||||
pc.close();
|
||||
localStream.getTracks().forEach(track => track.stop());
|
||||
const messageKey = callStatus === 'permission_requested'
|
||||
? 'WHATSAPP_CALL.PERMISSION_REQUESTED'
|
||||
: 'WHATSAPP_CALL.PERMISSION_PENDING';
|
||||
emitter.emit(BUS_EVENTS.SHOW_ALERT, {
|
||||
message: t(messageKey),
|
||||
type: 'info',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
emitter.emit(BUS_EVENTS.SHOW_ALERT, {
|
||||
message: t('WHATSAPP_CALL.CALLING'),
|
||||
type: 'success',
|
||||
});
|
||||
|
||||
window.__outboundCallPC = pc;
|
||||
window.__outboundCallStream = localStream;
|
||||
window.__outboundCallId = response.data?.call_id;
|
||||
} catch (err) {
|
||||
if (pc) pc.close();
|
||||
if (localStream) localStream.getTracks().forEach(track => track.stop());
|
||||
const errorMessage =
|
||||
err.response?.data?.error || t('WHATSAPP_CALL.CALL_FAILED');
|
||||
emitter.emit(BUS_EVENTS.SHOW_ALERT, {
|
||||
|
||||
@@ -38,6 +38,7 @@ class ActionCableConnector extends BaseActionCableConnector {
|
||||
'whatsapp_call.incoming': this.onWhatsappCallIncoming,
|
||||
'whatsapp_call.accepted': this.onWhatsappCallAccepted,
|
||||
'whatsapp_call.ended': this.onWhatsappCallEnded,
|
||||
'whatsapp_call.permission_granted': this.onWhatsappCallPermissionGranted,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -235,6 +236,14 @@ class ActionCableConnector extends BaseActionCableConnector {
|
||||
const whatsappCallsStore = useWhatsappCallsStore();
|
||||
whatsappCallsStore.handleCallEnded(data.call_id);
|
||||
};
|
||||
|
||||
// eslint-disable-next-line class-methods-use-this
|
||||
onWhatsappCallPermissionGranted = data => {
|
||||
emitter.emit(BUS_EVENTS.SHOW_ALERT, {
|
||||
message: `${data.contact_name} approved the call permission request. You can now call them.`,
|
||||
type: 'success',
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export default {
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
"INITIATE_CALL": "Call via WhatsApp",
|
||||
"CALLING": "Calling…",
|
||||
"CALL_FAILED": "Call failed. Please try again.",
|
||||
"PERMISSION_REQUESTED": "Call permission request sent to the contact. You can call once they approve.",
|
||||
"PERMISSION_PENDING": "Waiting for the contact to approve the call permission request. Please try again shortly.",
|
||||
"UNKNOWN_CALLER": "Unknown caller",
|
||||
"MIC_DENIED": "Microphone access denied. Please allow mic access and try again.",
|
||||
"CALL_TAKEN": "Call accepted by another agent"
|
||||
|
||||
Reference in New Issue
Block a user