import { useEffect, useRef } from 'react'; import { useSetAtom } from 'jotai'; import { CallEmbed, useCallControlState } from '../plugins/call'; import { useRoomCallPolicy } from './useRoomCallPolicy'; import { toastQueueAtom } from '../state/toast'; /** * [Gitea #223] When a room admin turns Allow Screen Sharing / Allow Camera * off mid-call, the voice-limit-guard revokes the publish permission and the * SFU drops our track within seconds — the button just vanishes with no * explanation. Tell the user why: a track that went away while the room policy * forbids it was not their doing. */ export function useCallPolicyRevokedToast(embed: CallEmbed, joined: boolean): void { const { screenshare, video } = useCallControlState(embed.control); const { allowScreenshare, allowCamera } = useRoomCallPolicy(embed.room); const setToast = useSetAtom(toastQueueAtom); const prev = useRef({ screenshare, video }); useEffect(() => { const was = prev.current; prev.current = { screenshare, video }; if (!joined) return; const notify = (body: string) => setToast({ id: `call-policy-${Date.now()}`, displayName: 'Lotus Chat', body, roomName: embed.room.name ?? 'Voice call', roomId: embed.roomId, }); if (was.screenshare && !screenshare && !allowScreenshare) { notify('Screen sharing was turned off by a room admin.'); } if (was.video && !video && !allowCamera) { notify('Your camera was turned off by a room admin.'); } }, [screenshare, video, allowScreenshare, allowCamera, joined, setToast, embed]); }