diff --git a/client/providers/CallProvider/hooks/useVoipClient.ts b/client/providers/CallProvider/hooks/useVoipClient.ts index 3dd5df962631..35bafdfa0072 100644 --- a/client/providers/CallProvider/hooks/useVoipClient.ts +++ b/client/providers/CallProvider/hooks/useVoipClient.ts @@ -51,13 +51,12 @@ export const useVoipClient = (): UseVoipClientResult => { callServerConfig: { websocketPath }, } = parsedData; - // let client: VoIPUser; (async (): Promise => { try { const subscription = await membership({ extension }); client = await SimpleVoipUser.create(extension, password, host, websocketPath, iceServers, 'video'); // Today we are hardcoding workflow mode. - // In futue, this should be read from configuration + // In future, this should be ready from configuration client.setWorkflowMode(WorkflowTypes.CONTACT_CENTER_USER); client.setMembershipSubscription(subscription); setResult({ voipClient: client, registrationInfo: parsedData }); @@ -71,8 +70,6 @@ export const useVoipClient = (): UseVoipClientResult => { }, ); return (): void => { - // client?.disconnect(); - // TODO how to close the client? before creating a new one? if (client) { client.clear(); } @@ -88,10 +85,12 @@ export const useVoipClient = (): UseVoipClientResult => { setExtension(user.extension); } else { setExtension(null); - if (!isUseVoipClientResultError(result) && !isUseVoipClientResultLoading(result)) { - const { voipClient } = result as UseVoipClientResultResolved; - voipClient.clear(); + + if (!result.voipClient) { + return; } + + result.voipClient.clear(); } }, [result, setExtension, setResult, user]); return result;