diff --git a/app/javascript/dashboard/components-next/message/bubbles/VoiceCall.vue b/app/javascript/dashboard/components-next/message/bubbles/VoiceCall.vue index a2b0c3792..48b1fd469 100644 --- a/app/javascript/dashboard/components-next/message/bubbles/VoiceCall.vue +++ b/app/javascript/dashboard/components-next/message/bubbles/VoiceCall.vue @@ -38,9 +38,10 @@ const { t } = useI18n(); const store = useStore(); const { call, conversationId, currentUserId, inboxId, sender } = useMessageContext(); -const { activeCall, isJoining, joinCall } = useCallSession({ - manageSessionState: false, -}); +const { activeCall, hasActiveCall, isJoining, joinCall, endCall } = + useCallSession({ + manageSessionState: false, + }); const status = computed(() => call.value?.status); const isOutbound = computed(() => call.value?.direction === 'outgoing'); @@ -153,8 +154,23 @@ const joinLabel = computed(() => : t('CONVERSATION.VOICE_CALL.JOIN_CALL') ); +const activeConversation = computed(() => { + const id = activeCall.value?.conversationId; + return id ? store.getters.getConversationById?.(id) : null; +}); + const handleJoinClick = async () => { if (!canJoin.value || isJoining.value) return; + if (hasActiveCall.value && activeCall.value?.callSid !== callSid.value) { + const activeInboxId = activeConversation.value?.inbox_id; + if (activeCall.value?.conversationId && activeInboxId) { + await endCall({ + conversationId: activeCall.value.conversationId, + inboxId: activeInboxId, + callSid: activeCall.value.callSid, + }); + } + } await joinCall({ conversationId: conversationId.value, inboxId: resolvedInboxId.value, @@ -165,7 +181,18 @@ const handleJoinClick = async () => {