Skip to content

Commit

Permalink
events. added phone-island-default-device-change (#49)
Browse files Browse the repository at this point in the history
Co-authored-by: Edoardo Spadoni <[email protected]>
  • Loading branch information
tonyco97 and edospadoni authored May 3, 2024
1 parent 984c67c commit 1720650
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 22 deletions.
26 changes: 25 additions & 1 deletion docs/EVENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,24 @@ eventDispatch(`<event-name>`, `<data-object>`)
}
```

- `phone-island-default-device-change` The event to change phone-island default device

```json
{
"id": "<number>",
"type": "webrtc | nethlink | physical",
"secret": "<secret>",
"username": "<number>",
"description": "",
"actions": {
"answer": true,
"dtmf": true,
"hold": true
},
"proxy_port": null
}
```

## Dispatch Phone-Island Events - phone-island-*

- `phone-island-expanded` The dispatch of phone-island expand
Expand Down Expand Up @@ -147,7 +165,13 @@ eventDispatch(`<event-name>`, `<data-object>`)
```json
{}
```
- `phone-island-theme-changed-` The dispatch of change phone-island theme
- `phone-island-theme-changed` The dispatch of change phone-island theme

```json
{}
```

- `phone-island-default-device-changed` The dispatch of change phone-island default device

```json
{}
Expand Down
6 changes: 6 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ export const PhoneIsland: FC<PhoneIslandProps> = ({
setTheme(theme?.selectedTheme)
})

useEventListener('phone-island-default-device-change', (data) => {
store.dispatch.currentUser.updateCurrentDefaultDevice(data?.deviceInformationObject)
eventDispatch('phone-island-default-device-changed', {})
})

return (
<>
<Provider store={store}>
Expand All @@ -162,6 +167,7 @@ export const PhoneIsland: FC<PhoneIslandProps> = ({
sipPort={SIP_PORT}
reload={reload}
reloadedCallback={() => setReloadedWebRTC(true)}
uaType={uaType}
>
<RestAPI hostName={HOST_NAME} username={USERNAME} authToken={AUTH_TOKEN}>
<Socket
Expand Down
49 changes: 29 additions & 20 deletions src/components/WebRTC.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ interface WebRTCProps {
sipHost: string
sipPort: string
reload: boolean
uaType: string
reloadedCallback?: () => void
}

Expand All @@ -34,6 +35,7 @@ export const WebRTC: FC<WebRTCProps> = ({
sipHost,
sipPort,
reload,
uaType,
reloadedCallback,
}) => {
// Initialize store dispatch
Expand Down Expand Up @@ -244,29 +246,36 @@ export const WebRTC: FC<WebRTCProps> = ({
break

case 'incomingcall':
// Update webrtc state
dispatch.webrtc.updateWebRTC({ jsepGlobal: jsep })
// Check if is recording an audio through call
// ...recording an audio is a request made by the user
// ...it must be managed differently than an incoming call
if (recording) {
// Update the recorder state
dispatch.recorder.setIncoming(true)
} else {
// Manage the incoming message as a webrtc call
// Update incoming webrtc state, number and display name
// ...are updated inside socket
dispatch.currentCall.checkIncomingUpdatePlay({
incomingWebRTC: true,
})

if (janus.current.log) {
janus.current.log('Incoming call from ' + result['username'] + '!')
const { default_device } = store.getState().currentUser
if (
(uaType === 'mobile' && default_device?.type === 'nethlink') ||
(uaType === 'desktop' && default_device?.type === 'webrtc')
) {
// Update webrtc state
dispatch.webrtc.updateWebRTC({ jsepGlobal: jsep })
// Check if is recording an audio through call
// ...recording an audio is a request made by the user
// ...it must be managed differently than an incoming call
if (recording) {
// Update the recorder state
dispatch.recorder.setIncoming(true)
} else {
// Manage the incoming message as a webrtc call
// Update incoming webrtc state, number and display name
// ...are updated inside socket
dispatch.currentCall.checkIncomingUpdatePlay({
incomingWebRTC: true,
})

if (janus.current.log) {
janus.current.log('Incoming call from ' + result['username'] + '!')
}
}

// Update the webrtc last activity time
dispatch.webrtc.updateLastActivity(new Date().getTime())
}

// Update the webrtc last activity time
dispatch.webrtc.updateLastActivity(new Date().getTime())
break

case 'accepted':
Expand Down
2 changes: 1 addition & 1 deletion src/stories/Call.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ const CallTemplate: Story<any> = (args) => {
/>
<button onClick={() => launchEvent()}>Launch {getEventName}</button>

<PhoneIsland dataConfig={config} showAlways={false} {...args} uaType={'mobile'} />
<PhoneIsland dataConfig={config} showAlways={false} {...args} uaType={'desktop'} />
</div>
)
}
Expand Down

0 comments on commit 1720650

Please sign in to comment.