Skip to content

Commit 18b29a3

Browse files
authored
feat: trigger audio init on first start (#77)
1 parent 243a9fa commit 18b29a3

File tree

8 files changed

+173
-49
lines changed

8 files changed

+173
-49
lines changed

package-lock.json

Lines changed: 109 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"@nethesis/nethesis-brands-svg-icons": "github:nethesis/Font-Awesome#ns-brands",
5050
"@nethesis/nethesis-light-svg-icons": "github:nethesis/Font-Awesome#ns-light",
5151
"@nethesis/nethesis-solid-svg-icons": "github:nethesis/Font-Awesome#ns-solid",
52-
"@nethesis/phone-island": "^0.17.7",
52+
"@nethesis/phone-island": "^0.17.8",
5353
"@tailwindcss/forms": "^0.5.7",
5454
"@types/lodash": "^4.14.202",
5555
"@types/node": "^18.19.9",

src/main/classes/controllers/AccountController.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,19 @@ export class AccountController {
4040
}
4141

4242
async logout() {
43+
// Call API logout before clearing local data
44+
const account = store.store.account
45+
if (account) {
46+
try {
47+
const { NethVoiceAPI } = useNethVoiceAPI(account)
48+
await NethVoiceAPI.Authentication.phoneIslandTokenLogout()
49+
await NethVoiceAPI.Authentication.logout()
50+
Log.info('AccountController.logout() - logout API call completed successfully')
51+
} catch (e) {
52+
Log.warning('Error calling logout API:', e)
53+
}
54+
}
55+
4356
store.updateStore({
4457
auth: {
4558
...store.store.auth!,

src/main/main.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -355,14 +355,19 @@ function attachOnReadyProcess() {
355355
}
356356

357357
const account: Account = store.get('account') as Account
358-
const ext = account.data?.endpoints.extension.find((e) => e.type === "webrtc")
359358

360-
if (ext && account?.data?.default_device?.type !== 'physical') {
361-
const { NethVoiceAPI } = useNethVoiceAPI(account)
362-
const res = await NethVoiceAPI.User.default_device(ext)
363-
Log.info('Reset device', res, ext.type, ext.id)
359+
if (account?.data) {
360+
const ext = account.data.endpoints.extension.find((e) => e.type === "webrtc")
361+
362+
if (ext && account.data.default_device?.type !== 'physical') {
363+
const { NethVoiceAPI } = useNethVoiceAPI(account)
364+
const res = await NethVoiceAPI.User.default_device(ext)
365+
Log.info('Reset device', res, ext.type, ext.id)
366+
} else {
367+
Log.info('No device to reset')
368+
}
364369
} else {
365-
Log.info('No device to reset')
370+
Log.info('No account logged in, skipping device reset')
366371
}
367372

368373
// read shortcut from config and unregister

src/renderer/src/components/Modules/NethVoice/LastCalls/LastCallsBox.tsx

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,22 @@ import { useEffect, useState } from 'react'
1111
import { Scrollable } from '@renderer/components/Scrollable'
1212
import { ModuleTitle } from '@renderer/components/ModuleTitle'
1313
import { EmptyList } from '@renderer/components/EmptyList'
14+
import { useLoggedNethVoiceAPI } from '@renderer/hooks/useLoggedNethVoiceAPI'
1415

1516
export function LastCallsBox({ showContactForm }): JSX.Element {
1617

18+
const { NethVoiceAPI } = useLoggedNethVoiceAPI()
1719
const [lastCalls] = useNethlinkData('lastCalls')
1820
const [operators] = useNethlinkData('operators')
1921
const [missedCalls, setMissedCalls] = useNethlinkData('missedCalls')
2022
const [preparedCalls, setPreparedCalls] = useState<LastCallData[]>([])
23+
const [audioTestCode, setAudioTestCode] = useState<string>('*41')
2124

2225
const getFilteredCallsCount = (): number => {
2326
if (!lastCalls) return 0
2427
return lastCalls.filter((call) => {
2528
const numberToCheck = call.direction === 'in' ? call.src : call.dst
26-
return !numberToCheck?.includes('*43')
29+
return !numberToCheck?.includes(audioTestCode)
2730
}).length
2831
}
2932

@@ -32,7 +35,21 @@ export function LastCallsBox({ showContactForm }): JSX.Element {
3235

3336
useEffect(() => {
3437
prepareCalls()
35-
}, [lastCalls, missedCalls])
38+
}, [lastCalls, missedCalls, audioTestCode])
39+
40+
useEffect(() => {
41+
const loadFeatureCodes = async () => {
42+
try {
43+
const codes = await NethVoiceAPI.AstProxy.featureCodes()
44+
if (codes?.audio_test) {
45+
setAudioTestCode(codes.audio_test)
46+
}
47+
} catch (error) {
48+
console.error('Failed to load feature codes:', error)
49+
}
50+
}
51+
loadFeatureCodes()
52+
}, [])
3653

3754
const viewAllMissedCalls = () => {
3855
window.api.openHostPage('/history')
@@ -49,7 +66,7 @@ export function LastCallsBox({ showContactForm }): JSX.Element {
4966
return elem
5067
}).filter((call) => {
5168
const numberToCheck = call.direction === 'in' ? call.src : call.dst
52-
return !numberToCheck?.includes('*43')
69+
return !numberToCheck?.includes(audioTestCode)
5370
})
5471
setPreparedCalls((p) => preparedCalls)
5572
}

src/renderer/src/pages/PhoneIslandPage.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ export function PhoneIslandPage() {
8383
if (!hasRunWarmup.current) {
8484
hasRunWarmup.current = true
8585
Log.info('Requesting audio warm-up from main process...')
86-
//eventDispatch(PHONE_ISLAND_EVENTS['phone-island-init-audio'])
86+
setTimeout(() => {
87+
eventDispatch(PHONE_ISLAND_EVENTS['phone-island-init-audio'])
88+
}, 1000)
8789

8890
// Dispatch device changes after warm-up completes (after ~5 seconds)
8991
setTimeout(() => {

src/shared/types.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,15 @@ export type AuthAppData = {
425425
[accountUID: string]: Account
426426
}
427427
}
428+
export type FeatureCodes = {
429+
pickup?: string,
430+
dnd_toggle?: string,
431+
audio_test?: string,
432+
confbridge_conf?: string,
433+
incall_audio?: string,
434+
que_toggle?: string
435+
}
436+
428437
export type NethLinkPageData = {
429438
selectedSidebarMenu: MENU_ELEMENT,
430439
operators?: OperatorData,

src/shared/useNethVoiceAPI.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export const useNethVoiceAPI = (loggedAccount: Account | undefined = undefined)
4343
if (endpoint === '/login') {
4444
return `${FALLBACK_API_BASE_PATH}/authentication/login`
4545
}
46-
if (endpoint === '/authentication/logout') {
46+
if (endpoint === '/logout') {
4747
return `${FALLBACK_API_BASE_PATH}/authentication/logout`
4848
}
4949
if (endpoint === '/authentication/phone_island_token_login') {
@@ -210,7 +210,8 @@ export const useNethVoiceAPI = (loggedAccount: Account | undefined = undefined)
210210
extensions: async (): Promise<ExtensionsType> => await _GET(buildApiPath('/astproxy/extensions')),
211211
getQueues: async () => await _GET(buildApiPath('/astproxy/queues')),
212212
getParkings: async () => await _GET(buildApiPath('/astproxy/parkings')),
213-
pickupParking: async (parkInformation: any) => await _POST(buildApiPath('/astproxy/pickup_parking'), parkInformation)
213+
pickupParking: async (parkInformation: any) => await _POST(buildApiPath('/astproxy/pickup_parking'), parkInformation),
214+
featureCodes: async () => await _GET(buildApiPath('/astproxy/feature_codes'))
214215
}
215216

216217

@@ -378,7 +379,7 @@ export const useNethVoiceAPI = (loggedAccount: Account | undefined = undefined)
378379
isFirstHeartbeat = false
379380
return new Promise<void>(async (resolve) => {
380381
try {
381-
await _POST(buildApiPath('/authentication/logout'), {})
382+
await _POST(buildApiPath('/logout'))
382383
} catch (e) {
383384
Log.warning("error during logout:", e)
384385
} finally {
@@ -394,6 +395,9 @@ export const useNethVoiceAPI = (loggedAccount: Account | undefined = undefined)
394395

395396
phoneIslandTokenLogin: async (): Promise<{ username: string, token: string }> =>
396397
await _POST(buildApiPath('/authentication/phone_island_token_login'), { subtype: 'nethlink' }),
398+
399+
phoneIslandTokenLogout: async (): Promise<{ username: string, token: string }> =>
400+
await _POST(buildApiPath('/authentication/persistent_token_remove'), { type: 'phone-island', subtype: 'nethlink' }),
397401
}
398402

399403
const CustCard = {}

0 commit comments

Comments
 (0)