Skip to content

Commit

Permalink
fix: added call endend event on hangup (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyco97 authored Dec 17, 2024
1 parent 056e4b6 commit e5b1b47
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"You must accept audio and video permissions.": "You must accept audio/video permissions",
"Unknown audio or camera permissions.": "Unknown audio/camera permissions",
"Web Phone connection is down.": "Web Phone connection is down",
"NethLink connection is down.": "NethLink connection is down",
"Server connection is down.": "Server connection is down",
"Camera is already used.": "Camera is already used",
"Call transferred successfully.": "Call transferred successfully"
Expand Down
1 change: 1 addition & 0 deletions public/locales/it/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"Accept audio and video permissions.": "Accetta le autorizzazioni audio/video",
"Unknown audio or camera permissions.": "Autorizzazioni audio/camera sconosciute",
"Web Phone connection is down.": "Connessione Web Phone non disponibile",
"NethLink connection is down.": "Connessione NethLink non disponibile",
"Server connection is down.": "Connessione al server non disponibile",
"Camera is already used.": "Camera già in uso",
"Call transferred successfully.": "Chiamata trasferita con successo"
Expand Down
20 changes: 20 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useEventListener, eventDispatch, setJSONItem, getJSONItem } from './uti
import { detach } from './lib/webrtc/messages'
import { checkDarkTheme, setTheme } from './lib/darkTheme'
import { changeOperatorStatus } from './services/user'
import { isEmpty } from './utils/genericFunctions/isEmpty'

interface PhoneIslandProps {
dataConfig: string
Expand Down Expand Up @@ -168,6 +169,25 @@ export const PhoneIsland: FC<PhoneIslandProps> = ({
store.dispatch.alerts.setAlert(alertType.toString())
})

useEventListener('phone-island-main-presence', (data: any) => {
const currentUsernameInformation: any = store.getState().currentUser?.username
const currentUserObject: any = store.getState().currentUser
let mainPresenceValueBeforeUpdate = currentUserObject?.mainPresence
if (
currentUsernameInformation !== undefined &&
currentUsernameInformation !== '' &&
!isEmpty(data[currentUsernameInformation]) &&
data[currentUsernameInformation]?.mainPresence !== undefined
) {
let newMainPresenceValue = data[currentUsernameInformation]?.mainPresence
store.dispatch.currentUser.updateMainPresence(data[currentUsernameInformation]?.mainPresence)
let mainPresenceValueAfterUpdate = newMainPresenceValue
if (mainPresenceValueAfterUpdate === 'online' && mainPresenceValueBeforeUpdate !== 'online') {
eventDispatch('phone-island-call-ended', {})
}
}
})

return (
<>
<Provider store={store}>
Expand Down
10 changes: 9 additions & 1 deletion src/components/AlertView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import { faTimes, faCircleXmark, faCircleCheck } from '@fortawesome/free-solid-s
import { Button } from '../Button'
import { t } from 'i18next'
import { eventDispatch } from '../../utils'
import { store } from '../../store'

/**
* Shows user alerts
*/
const AlertView: FC = () => {
const { data } = useSelector((state: RootState) => state.alerts)
const { default_device } = useSelector((state: RootState) => state.currentUser)
const dispatch = useDispatch<Dispatch>()

// Extract active alerts
Expand Down Expand Up @@ -53,7 +55,13 @@ const AlertView: FC = () => {

<div className='ml-3'>
<h3 className='pi-text-lg pi-font-medium pi-text-gray-900 dark:pi-text-gray-50 pi-dark:text-rose-100 margin-block-property'>
{t(`Errors.${latestAlert?.type}`)}
{t(
`Errors.${
default_device?.type === 'nethlink' && latestAlert?.type === 'webrtc_down'
? latestAlert?.nethlink_message
: latestAlert?.type
}`,
)}
</h3>
<div className='pi-text-sm pi-font-normal pi-text-gray-700 dark:pi-text-gray-200 pi-dark:text-rose-200 pi-leading-5'>
{t(`Errors.${latestAlert?.message}`)}
Expand Down
2 changes: 2 additions & 0 deletions src/models/alerts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const defaultState: AlertsTypes = {
active: false,
break: true,
message: 'Web Phone connection is down.',
nethlink_message: 'NethLink connection is down.',
type: 'webrtc_down',
},
socket_down: {
Expand Down Expand Up @@ -143,4 +144,5 @@ export interface AlertTypes {
break?: boolean // This means that it brokes WebRTC audio calls or Socket connection
success?: boolean
type: string
nethlink_message?: string
}
3 changes: 3 additions & 0 deletions src/models/currentUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export const currentUser = createModel<RootModel>()({
...payload,
}
},
updateMainPresence: (state, payload) => {
state.mainPresence = payload
},
updateCurrentDefaultDevice: (state, payload) => {
state.default_device = payload
},
Expand Down

0 comments on commit e5b1b47

Please sign in to comment.