import { useEffect } from 'react'; import { useSetAtom } from 'jotai'; import { Icons } from 'folds'; import { CallEmbed } from '../plugins/call'; import { toastQueueAtom } from '../state/toast'; export type ScreenshareNoticeKind = 'ended' | 'no-frames' | 'alone'; export const describeScreenshareNotice = (kind: ScreenshareNoticeKind): string | undefined => { switch (kind) { case 'ended': return 'Screen sharing stopped — the shared window was closed.'; case 'no-frames': return 'Your screen share is showing nothing — the shared window may be minimised or hidden.'; case 'alone': return "Still sharing? You've been sharing your screen for 30 minutes with nobody else in the call."; default: return undefined; } }; /** * [Gitea EC#39] Toast the fork's io.lotus.screenshare_notice: shared window * closed, no frames for a while, or a long share with nobody watching. */ export function useScreenshareNotices(embed: CallEmbed): void { const setToast = useSetAtom(toastQueueAtom); useEffect( () => embed.listenAction<{ data?: { kind?: ScreenshareNoticeKind } }>( 'io.lotus.screenshare_notice', (evt) => { const body = describeScreenshareNotice(evt.detail?.data?.kind as ScreenshareNoticeKind); if (!body) return; setToast({ id: `screenshare-${evt.detail?.data?.kind}-${Date.now()}`, iconSrc: Icons.ScreenShare, displayName: 'Screen share', body, roomName: embed.room.name ?? 'Voice call', roomId: embed.roomId, sticky: evt.detail?.data?.kind === 'alone', }); }, ), [embed, setToast], ); }