Skip to content

Commit

Permalink
fix: wrong hangup event on physical call view (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyco97 authored Jan 13, 2025
1 parent 0a7c679 commit 12891d1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 26 deletions.
8 changes: 5 additions & 3 deletions src/components/Socket.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import type {
import { getTimestampInSeconds } from '../utils/genericFunctions/timestamp'
import { userTotallyFree } from '../lib/user/extensions'
import { isEmpty } from '../utils/genericFunctions/isEmpty'
import { isPhysical } from '../lib/user/default_device'

interface SocketProps {
children: ReactNode
Expand Down Expand Up @@ -67,6 +68,7 @@ export const Socket: FC<SocketProps> = ({

// Stop the local audio element ringing
store.dispatch.player.stopAudioPlayer()
store.dispatch.player.setAudioPlayerLoop(false)
}

const checkDefaultDeviceConversationClosed = (conv: any) => {
Expand Down Expand Up @@ -140,7 +142,7 @@ export const Socket: FC<SocketProps> = ({
startTime: `${getTimestampInSeconds()}`,
})

if (userInformation?.default_device?.type === 'physical') {
if (isPhysical()) {
checkDefaultDeviceConversationActive(conv)
}
if (view === 'call' && transferring) {
Expand Down Expand Up @@ -426,8 +428,8 @@ export const Socket: FC<SocketProps> = ({
dispatchUrlCall(link, urlType)
})

// `updateDefaultDevice` is the socket event when user change the default device
socket.current.on('updateDefaultDevice', (extension:string) => {
// `updateDefaultDevice` is the socket event when user change the default device
socket.current.on('updateDefaultDevice', (extension: string) => {
// Dispatch phone island physical call event with the link and the urlType
dispatchDefaultDeviceUpdate(extension)
})
Expand Down
52 changes: 29 additions & 23 deletions src/components/WebRTC.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { attendedTransfer, hangupCurrentCall } from '../lib/phone/call'
import { webrtcCheck } from '../lib/webrtc/connection'
import outgoingRingtone from '../static/outgoing_ringtone'
import { eventDispatch, useEventListener } from '../utils'
import { isPhysical } from '../lib/user/default_device'

interface WebRTCProps {
children: ReactNode
Expand Down Expand Up @@ -311,33 +312,38 @@ export const WebRTC: FC<WebRTCProps> = ({
if (recording) {
dispatch.recorder.setRecording(false)
}

hangupCurrentCall()
sipcall.hangup()
if (!isPhysical() && uaType !== 'mobile') {
hangupCurrentCall()
sipcall.hangup()

// Stop the local audio element ringing
store.dispatch.player.stopAudioPlayer()

// Check the janus doc before enable the following
// if (
// result['code'] === 486 &&
// result['event'] === 'hangup' &&
// result['reason'] === 'Busy Here'
// ) {
// dispatch.player.updateAudioSource({
// src: busyRingtone,
// })
// dispatch.player.playAudio()
// }
// Reset current call info
store.dispatch.currentCall.reset()
if (janus.current.log)
janus.current.log(
'Call hung up (' + result['code'] + ' ' + result['reason'] + ')!',
)
// Update webrtc lastActivity time
dispatch.webrtc.updateLastActivity(new Date().getTime())
// stopScreenSharingI()
}

// Stop the local audio element ringing
store.dispatch.player.stopAudioPlayer()

// Check the janus doc before enable the following
// if (
// result['code'] === 486 &&
// result['event'] === 'hangup' &&
// result['reason'] === 'Busy Here'
// ) {
// dispatch.player.updateAudioSource({
// src: busyRingtone,
// })
// dispatch.player.playAudio()
// }
// Reset current call info
store.dispatch.currentCall.reset()
if (janus.current.log)
janus.current.log(
'Call hung up (' + result['code'] + ' ' + result['reason'] + ')!',
)
// Update webrtc lastActivity time
dispatch.webrtc.updateLastActivity(new Date().getTime())
// stopScreenSharingI()
break

case 'gateway_down':
Expand Down

0 comments on commit 12891d1

Please sign in to comment.