Skip to content

Commit

Permalink
feat(events): Created new event for socket update default_device (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyco97 authored Dec 16, 2024
1 parent 66b6044 commit 88c3bf2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
12 changes: 10 additions & 2 deletions docs/EVENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -866,14 +866,22 @@ eventDispatch(`<event-name>`, `<data-object>`)
{}
```

- `phone-island-socket-disconnected-popup-open` Indicates that webscket connection missing popup appear
- `phone-island-socket-disconnected-popup-open` Indicates that websocket connection missing popup appear

```json
{}
```

- `phone-island-socket-disconnected-popup-close` Indicates that webscket connection missing popup disappear
- `phone-island-socket-disconnected-popup-close` Indicates that websocket connection missing popup disappear

```json
{}
```

- `phone-island-default-device-updated` Indicates that user has updated the default device

```json
{
"id": "91204"
}
```
7 changes: 7 additions & 0 deletions src/components/Socket.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
dispatchParkingUpdate,
dispatchExtensions,
dispatchUrlCall,
dispatchDefaultDeviceUpdate,
} from '../events'
import { store } from '../store'
import { eventDispatch, withTimeout } from '../utils'
Expand Down Expand Up @@ -424,6 +425,12 @@ export const Socket: FC<SocketProps> = ({
// Dispatch phone island physical call event with the link and the urlType
dispatchUrlCall(link, urlType)
})

// `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)
})
}

initSocketConnection()
Expand Down
10 changes: 10 additions & 0 deletions src/events/SocketEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,13 @@ export function dispatchUrlCall(url: string, urlType: string) {
}
eventDispatch('phone-island-action-physical', { urlCallObject })
}

/**
* The dispatch function to update the default device
*
* @param extension The default_device_update event from socket
*/
export function dispatchDefaultDeviceUpdate(extension: string) {
// Dispatch the event on window for external handlers
eventDispatch('phone-island-default-device-updated', { id: extension })
}

0 comments on commit 88c3bf2

Please sign in to comment.