diff --git a/components/layout/Layout.tsx b/components/layout/Layout.tsx index b1fa0cec..a7fa16f1 100644 --- a/components/layout/Layout.tsx +++ b/components/layout/Layout.tsx @@ -446,7 +446,6 @@ export const Layout: FC = ({ children }) => { ) { let deviceIdObject = webrtcData[0] setMainDeviceId(deviceIdObject) - dispatch.user.updateDefaultDevice(deviceIdObject) eventDispatch('phone-island-default-device-change', { deviceIdObject }) } } @@ -462,10 +461,18 @@ export const Layout: FC = ({ 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() @@ -779,10 +786,14 @@ export const Layout: FC = ({ 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 && @@ -791,12 +802,16 @@ export const Layout: FC = ({ 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 }) + } } } }) diff --git a/package-lock.json b/package-lock.json index 4c76f63b..703452a5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,7 +19,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", @@ -4225,9 +4225,9 @@ } }, "node_modules/@nethesis/phone-island": { - "version": "0.8.27", - "resolved": "https://registry.npmjs.org/@nethesis/phone-island/-/phone-island-0.8.27.tgz", - "integrity": "sha512-Ui00Thsxus/oSa5SPNKh5uh/ATt06WOVq9t2ar47mt9QpeT1eDULzRWhk584swv8Nk1IK8eL5Ug8g2yaq3rBKg==", + "version": "0.8.28", + "resolved": "https://registry.npmjs.org/@nethesis/phone-island/-/phone-island-0.8.28.tgz", + "integrity": "sha512-4t9cf3AwvKa8G+AVgA+6y5JT0rZJ0q2qF7XNLl3Xrwgd4aICpVOVbd2D6lLJPlanG8dFFwENCwnej4Zq6KMIPA==", "dependencies": { "@fortawesome/free-solid-svg-icons": "^6.2.1", "@fortawesome/react-fontawesome": "^0.2.0", @@ -16055,9 +16055,9 @@ } }, "node_modules/nanoid": { - "version": "3.3.7", - "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.7.tgz", - "integrity": "sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g==", + "version": "3.3.8", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.8.tgz", + "integrity": "sha512-WNLf5Sd8oZxOm+TzppcYk8gVOgP+l58xNy58D0nbUnOxOWRWvlcCV4kUF7ltmI6PsrLl/BgKEyS4mqsGChFN0w==", "funding": [ { "type": "github", diff --git a/package.json b/package.json index f1d4614a..2d851949 100644 --- a/package.json +++ b/package.json @@ -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",