fix(voice): keep voice activity hooks pure by skipping state update when applicable

This commit is contained in:
João Victor 2024-08-15 09:13:12 -03:00
parent c6e8464693
commit b2adf9ad15
2 changed files with 10 additions and 0 deletions

View File

@ -1,4 +1,5 @@
import { useEffect } from 'react';
import { isEqual } from 'radash';
import { makeVar, useReactiveVar } from '@apollo/client';
import { VoiceActivityResponse } from '/imports/ui/core/graphql/queries/whoIsTalking';
@ -34,6 +35,10 @@ const createUseWhoIsTalking = () => {
newTalkingUsers[userId] = talking;
});
if (isEqual(getWhoIsTalking(), newTalkingUsers)) {
return;
}
setWhoIsTalkingState(newTalkingUsers);
};

View File

@ -1,4 +1,5 @@
import { useEffect } from 'react';
import { isEqual } from 'radash';
import { makeVar, useReactiveVar } from '@apollo/client';
import { VoiceActivityResponse } from '/imports/ui/core/graphql/queries/whoIsTalking';
@ -34,6 +35,10 @@ const createUseWhoIsUnmuted = () => {
newUnmutedUsers[userId] = true;
});
if (isEqual(getWhoIsUnmuted(), newUnmutedUsers)) {
return;
}
setWhoIsUnmutedState(newUnmutedUsers);
};