Skip to content

Commit

Permalink
fix: avoid updateMainDevice if physical
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyco97 committed Dec 11, 2024
1 parent d06a0d0 commit c20ce0a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 21 deletions.
41 changes: 28 additions & 13 deletions components/layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,6 @@ export const Layout: FC<LayoutProps> = ({ children }) => {
) {
let deviceIdObject = webrtcData[0]
setMainDeviceId(deviceIdObject)
dispatch.user.updateDefaultDevice(deviceIdObject)
eventDispatch('phone-island-default-device-change', { deviceIdObject })
}
}
Expand All @@ -462,10 +461,18 @@ export const Layout: FC<LayoutProps> = ({ children }) => {
}

useEffect(() => {
if (isFirstRunRef?.current && userInformation?.default_device?.type === '' && isEmpty(operatorsStore?.extensions)) {
if (
isFirstRunRef?.current &&
userInformation?.default_device?.type === '' &&
isEmpty(operatorsStore?.extensions)
) {
isFirstRunRef.current = true
}
if (isFirstRunRef?.current && userInformation?.default_device?.type !== '' && !isEmpty(operatorsStore?.extensions)) {
if (
isFirstRunRef?.current &&
userInformation?.default_device?.type !== '' &&
!isEmpty(operatorsStore?.extensions)
) {
isFirstRunRef.current = false
handleWebRTCAsDefaultDevice()
handlePhysicalDeviceDetach()
Expand Down Expand Up @@ -779,10 +786,14 @@ export const Layout: FC<LayoutProps> = ({ children }) => {
) {
if (firstRenderDetach) {
let desktopPhoneObject = desktopPhoneDevice[0]
setMainDeviceId(desktopPhoneObject)
dispatch.user.updateDefaultDevice(desktopPhoneObject)
setFirstRenderDetach(false)
eventDispatch('phone-island-default-device-change', { desktopPhoneObject })
const isPhysicalDefault = userInformation.endpoints.extension.some(
(ext: any) => ext.type === 'physical' && ext.id === userInformation?.default_device?.id,
)
if (!isPhysicalDefault) {
setMainDeviceId(desktopPhoneObject)
setFirstRenderDetach(false)
eventDispatch('phone-island-default-device-change', { desktopPhoneObject })
}
}
} else if (
data[currentUsername]?.number === desktopPhoneDevice[0]?.id &&
Expand All @@ -791,12 +802,16 @@ export const Layout: FC<LayoutProps> = ({ children }) => {
) {
if (firstRenderAttach) {
let deviceIdInfo: any = {}
deviceIdInfo = webrtcData[0]
setMainDeviceId(deviceIdInfo)
dispatch.user.updateDefaultDevice(deviceIdInfo)
setFirstRenderAttach(false)
eventDispatch('phone-island-default-device-change', { deviceIdInfo })
eventDispatch('phone-island-attach', { deviceIdInfo })
const isPhysicalDefault = userInformation.endpoints.extension.some(
(ext: any) => ext.type === 'physical' && ext.id === userInformation?.default_device?.id,
)
if (!isPhysicalDefault) {
deviceIdInfo = webrtcData[0]
setMainDeviceId(deviceIdInfo)
setFirstRenderAttach(false)
eventDispatch('phone-island-default-device-change', { deviceIdInfo })
eventDispatch('phone-island-attach', { deviceIdInfo })
}
}
}
})
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@nethesis/nethesis-brands-svg-icons": "github:nethesis/Font-Awesome#ns-brands",
"@nethesis/nethesis-light-svg-icons": "github:nethesis/Font-Awesome#ns-light",
"@nethesis/nethesis-solid-svg-icons": "github:nethesis/Font-Awesome#ns-solid",
"@nethesis/phone-island": "^0.8.27",
"@nethesis/phone-island": "^0.8.28",
"@rematch/core": "^2.2.0",
"@rematch/immer": "^2.1.3",
"@types/crypto-js": "^4.1.1",
Expand Down

0 comments on commit c20ce0a

Please sign in to comment.