Skip to content

Commit

Permalink
Chore: Improving useVoipClient logic
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandernsilva committed Aug 25, 2022
1 parent bbf2889 commit 971e332
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions apps/meteor/ee/client/hooks/useVoipClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ const isSignedResponse = (data: any): data is { result: string } => typeof data?
// Currently we only support the websocket connection and the SIP proxy connection being from the same host,
// we need to add a new setting for SIP proxy if we want to support different hosts for them.
export const useVoipClient = (): UseVoipClientResult => {
const settingVoipEnabled = useSetting('VoIP_Enabled');
const [voipEnabled, setVoipEnabled] = useSafely(useState(settingVoipEnabled));
const settingVoipEnabled = Boolean(useSetting('VoIP_Enabled'));

const [voipConnectorEnabled, setVoipConnectorEnabled] = useSafely(useState(true));

const voipRetryCount = useSetting('VoIP_Retry_Count');
const enableKeepAlive = useSetting('VoIP_Enable_Keep_Alive_For_Unstable_Networks');
const registrationInfo = useEndpoint('GET', '/v1/connector.extension.getRegistrationInfoByUserId');
Expand All @@ -34,17 +36,19 @@ export const useVoipClient = (): UseVoipClientResult => {
const [result, setResult] = useSafely(useState<UseVoipClientResult>({}));

const isEE = useHasLicenseModule('voip-enterprise');
const voipEnabled = settingVoipEnabled && voipConnectorEnabled;

useEffect(() => {
setVoipEnabled(settingVoipEnabled);
}, [settingVoipEnabled, setVoipEnabled]);

useEffect(() => {
const voipEnableEventHandler = (enabled: boolean): void => {
setVoipEnabled(enabled);
};
return subscribeToNotifyLoggedIn(`voip.statuschanged`, voipEnableEventHandler);
}, [setResult, setVoipEnabled, subscribeToNotifyLoggedIn]);
setVoipConnectorEnabled(settingVoipEnabled);
}, [settingVoipEnabled, setVoipConnectorEnabled]);

useEffect(
() =>
subscribeToNotifyLoggedIn(`voip.statuschanged`, (enabled: boolean): void => {
setVoipConnectorEnabled(enabled);
}),
[setResult, setVoipConnectorEnabled, subscribeToNotifyLoggedIn],
);

useEffect(() => {
const uid = user?._id;
Expand Down

0 comments on commit 971e332

Please sign in to comment.