Skip to content

Commit

Permalink
fix: wrong default_device update (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyco97 authored Jan 17, 2025
1 parent e89aee9 commit 15e2b07
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
19 changes: 19 additions & 0 deletions src/components/Socket.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,25 @@ export const Socket: FC<SocketProps> = ({
socket.current.on('updateDefaultDevice', (extension: string) => {
// Dispatch phone island physical call event with the link and the urlType
dispatchDefaultDeviceUpdate(extension)
// Update the internal store
const { extensions } = store.getState().users
const { endpoints } = store.getState().currentUser
if (!extensions || !endpoints) return

const extensionInformations: any = Object.values(extensions).filter(
(ext) => ext?.exten === extension,
)
if (extensionInformations.length === 0) return

let objectComplete = extensionInformations[0]
const endpointExtension = endpoints.extension.find(
(endpoint) => endpoint.id === objectComplete.exten,
)
if (endpointExtension) {
objectComplete = { ...objectComplete, type: endpointExtension.type }
}

store.dispatch.currentUser.updateCurrentDefaultDevice(objectComplete)
})
}

Expand Down
28 changes: 26 additions & 2 deletions src/components/WebRTC.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,33 @@ export const WebRTC: FC<WebRTCProps> = ({

case 'incomingcall':
const { default_device } = store.getState().currentUser
const { endpoints, username } = store.getState().currentUser
const { extensions } = store.getState().users

const hasOnlineNethlink = () => {
if (!extensions || !username) return false

// Get all extensions for current user
const userExtensions: any = Object.values(extensions).filter(
(ext) => ext?.username === username,
)

// Check if any extension is nethlink type and online
return userExtensions?.some((ext) => {
const endpointExtension = endpoints?.extension.find(
(endpoint) => endpoint.id === ext?.exten,
)
return (
endpointExtension?.type === 'nethlink' && ext?.status !== 'offline'
)
})
}

if (
(uaType === 'mobile' && default_device?.type === 'nethlink') ||
(uaType === 'desktop' && default_device?.type === 'webrtc')
(uaType === 'mobile' &&
(default_device?.type === 'nethlink' || hasOnlineNethlink())) ||
(uaType === 'desktop' &&
(default_device?.type === 'webrtc' || !hasOnlineNethlink()))
) {
// Update webrtc state
dispatch.webrtc.updateWebRTC({ jsepGlobal: jsep })
Expand Down

0 comments on commit 15e2b07

Please sign in to comment.