Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] VoIP button gets disabled whenever user status changes #24789

Merged
merged 4 commits into from
Mar 17, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions client/providers/CallProvider/hooks/useVoipClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { IRegistrationInfo } from '../../../../definition/voip/IRegistrationInfo
import { WorkflowTypes } from '../../../../definition/voip/WorkflowTypes';
import { useEndpoint } from '../../../contexts/ServerContext';
import { useSetting } from '../../../contexts/SettingsContext';
import { useUser } from '../../../contexts/UserContext';
import { useUserId } from '../../../contexts/UserContext';
import { SimpleVoipUser } from '../../../lib/voip/SimpleVoipUser';
import { VoIPUser } from '../../../lib/voip/VoIPUser';
import { useWebRtcServers } from './useWebRtcServers';
Expand All @@ -32,18 +32,17 @@ export const useVoipClient = (): UseVoipClientResult => {
const voipEnabled = useSetting('VoIP_Enabled');
const registrationInfo = useEndpoint('GET', 'connector.extension.getRegistrationInfoByUserId');
const membership = useEndpoint('GET', 'voip/queues.getMembershipSubscription');
const user = useUser();
const userId = useUserId();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey 👀 not sure of a different approach here, but, I did use "user.extension" prop on other fix to prevent this call from happening if the user doesn't have an extension associated.

But, that breaks the fix 🤔 since I was using the "useUser" hook, unless we have a "useUserExtension" hook somewhere (or we create one)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, If you are using other data from the user object, we can return the code to the way it was before my review

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KevLehman Can you please point me to the task? There are few of such kind which are dependent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As @KevLehman pointed out, the fix was breaking #24752. Next commit fixes this.

const iceServers = useWebRtcServers();

const [result, setResult] = useSafely(useState<UseVoipClientResult>({}));

useEffect(() => {
if (!user || !user?._id || !voipEnabled) {
if (!userId || !voipEnabled) {
setResult({});
return;
}

registrationInfo({ id: user._id }).then(
registrationInfo({ id: userId }).then(
(data) => {
let parsedData: IRegistrationInfo;
if (isSignedResponse(data)) {
Expand Down Expand Up @@ -82,7 +81,6 @@ export const useVoipClient = (): UseVoipClientResult => {
// client?.disconnect();
// TODO how to close the client? before creating a new one?
};
}, [user, iceServers, registrationInfo, setResult, membership, voipEnabled]);

}, [userId, iceServers, registrationInfo, setResult, membership, voipEnabled]);
return result;
};