Merge remote-tracking branch 'origin/livekit' into hs/emoji-reactions

This commit is contained in:
Half-Shot
2024-11-07 09:10:42 +00:00
60 changed files with 2437 additions and 1097 deletions

View File

@@ -37,8 +37,8 @@ import {
interface ReactionsContextType {
raisedHands: Record<string, Date>;
supportsReactions: boolean;
myReactionId: string | null;
reactions: Record<string, ReactionOption>;
lowerHand: () => Promise<void>;
}
const ReactionsContext = createContext<ReactionsContextType | undefined>(
@@ -94,13 +94,6 @@ export const ReactionsProvider = ({
{},
);
// Calculate our own reaction event.
const myReactionId = useMemo(
(): string | null =>
(myUserId && raisedHands[myUserId]?.reactionEventId) ?? null,
[raisedHands, myUserId],
);
// Reduce the data down for the consumers.
const resultRaisedHands = useMemo(
() =>
@@ -295,13 +288,38 @@ export const ReactionsProvider = ({
};
}, [room, addRaisedHand, removeRaisedHand, memberships, raisedHands]);
const lowerHand = useCallback(async () => {
if (
!myUserId ||
clientState?.state !== "valid" ||
!clientState.authenticated ||
!raisedHands[myUserId]
) {
return;
}
const myReactionId = raisedHands[myUserId].reactionEventId;
if (!myReactionId) {
logger.warn(`Hand raised but no reaction event to redact!`);
return;
}
try {
await clientState.authenticated.client.redactEvent(
rtcSession.room.roomId,
myReactionId,
);
logger.debug("Redacted raise hand event");
} catch (ex) {
logger.error("Failed to redact reaction event", myReactionId, ex);
}
}, [myUserId, raisedHands, clientState, rtcSession]);
return (
<ReactionsContext.Provider
value={{
raisedHands: resultRaisedHands,
supportsReactions,
myReactionId,
reactions,
lowerHand,
}}
>
{children}