Skip to content

Commit

Permalink
defaultDeviceType. Check default device type and launch webrtc event (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyco97 authored Apr 22, 2024
1 parent 1ba0b96 commit faaaa04
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/components/Socket.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export const Socket: FC<SocketProps> = ({
startTime: `${getTimestampInSeconds()}`,
})

if (userInformation?.default_device?.type !== 'webrtc') {
if (userInformation?.default_device?.type === 'physical') {
checkDefaultDeviceConversationActive(conv)
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/components/WebRTC.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,15 @@ export const WebRTC: FC<WebRTCProps> = ({
janus.current.log(
'Successfully un-registered as ' + result['username'] + '!',
)
eventDispatch('phone-island-webrtc-unregistered', {})
break

case 'registered':
if (janus.current.log)
janus.current.log(
'Successfully registered as ' + result['username'] + '!',
)
eventDispatch('phone-island-webrtc-registered', {})
if (!store.getState().webrtc.registered) {
store.dispatch.webrtc.updateWebRTC({
registered: true,
Expand Down
11 changes: 9 additions & 2 deletions src/events/SocketEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,16 @@ export function dispatchMainPresence(event: MainPresenceTypes) {
* @param event The extenUpdate event from socket
*/
export function dispatchConversations(event: ExtensionTypes) {
const data: ConversationsEventType = {
const data: any = {
[event.username]: {
conversations: event.conversations,
conversations: event?.conversations,
status: event?.status,
sipuseragent: event?.sipuseragent,
username: event?.username,
port: event?.port,
dnd: event?.dnd,
number: event?.exten,
ip: event?.ip,
},
}
// Dispatch the event on window for external handlers
Expand Down
2 changes: 1 addition & 1 deletion src/lib/user/default_device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { store } from '../../store'
*/
export function isWebRTC() {
const { default_device } = store.getState().currentUser
if (default_device?.type === 'webrtc') {
if (default_device?.type === 'webrtc' || default_device?.type === 'nethlink') {
return true
}
return false
Expand Down
2 changes: 1 addition & 1 deletion src/lib/user/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function getWebrtcExtensions(): UserExtensionTypes | UserExtensionTypes[]
// Get endpoints currentUser store
const { endpoints } = store.getState().currentUser
if (endpoints?.extension && endpoints.extension.length > 0) {
const webrtcExtensions = endpoints?.extension.filter((extension) => extension.type === 'webrtc')
const webrtcExtensions = endpoints?.extension.filter((extension) => extension?.type === 'webrtc' || extension?.type === 'nethlink')
return webrtcExtensions.length === 1
? webrtcExtensions[0]
: webrtcExtensions.length > 1
Expand Down
9 changes: 6 additions & 3 deletions src/models/currentCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ export const currentCall = createModel<RootModel>()({
// Check call type and incoming confirmation source
if (
(rootState.currentUser.default_device?.type === 'webrtc' && payload.incomingWebRTC) ||
(rootState.currentUser.default_device?.type === 'physical' && payload.incomingSocket)
(rootState.currentUser.default_device?.type === 'physical' && payload.incomingSocket) ||
(rootState?.currentUser?.default_device?.type === 'nethlink' && payload?.incomingWebRTC)
) {
payload.incoming = true

Expand All @@ -102,7 +103,8 @@ export const currentCall = createModel<RootModel>()({
// Check call type and outgoing confirmation source
if (
(rootState.currentUser.default_device?.type === 'webrtc' && payload.outgoingWebRTC) ||
(rootState.currentUser.default_device?.type === 'physical' && payload.outgoingSocket)
(rootState.currentUser.default_device?.type === 'physical' && payload.outgoingSocket) ||
(rootState.currentUser.default_device?.type === 'nethlink' && payload.outgoingWebRTC)
) {
payload.outgoing = true
// Dispatch an event for outgoing call
Expand All @@ -117,7 +119,8 @@ export const currentCall = createModel<RootModel>()({
// Check call type and accepted confirmation source
if (
(rootState.currentUser.default_device?.type === 'webrtc' && payload.acceptedWebRTC) ||
(rootState.currentUser.default_device?.type === 'physical' && payload.acceptedSocket)
(rootState.currentUser.default_device?.type === 'physical' && payload.acceptedSocket) ||
(rootState.currentUser.default_device?.type === 'nethlink' && payload.acceptedWebRTC)
) {
payload.accepted = true
eventDispatch('phone-island-call-answered', {})
Expand Down
2 changes: 1 addition & 1 deletion src/types/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface UserCachesTypes {
operatorsAvatars: AvatarsTypes
}

export type ExtensionTypeTypes = 'webrtc' | 'physical'
export type ExtensionTypeTypes = 'webrtc' | 'physical' | 'nethlink'

export interface UserExtensionTypes {
id: string
Expand Down

0 comments on commit faaaa04

Please sign in to comment.