import React, { useEffect, useState } from 'react'; import FocusTrap from 'focus-trap-react'; import { useSetAtom } from 'jotai'; import { Box, Button, Dialog, Header, Icons, Overlay, OverlayBackdrop, OverlayCenter, Text, config, } from 'folds'; import { CallEmbed } from '../../plugins/call'; import { MissingDevice, acceptForSession, describeLost, describeMissing, isAcceptedThisSession, parseDeviceLost, parseDeviceMissing, } from '../../plugins/call/expectedDevices'; import { toastQueueAtom } from '../../state/toast'; import { useModalStyle } from '../../hooks/useModalStyle'; /** * [Gitea #121] "Your usual headset isn't connected": the fork holds the join * until we answer. Join anyway (not asked again this session for the same * device) or Cancel (closes the call before it starts). A device lost mid-call * is only a toast. */ export function ExpectedDevicesPrompt({ embed, onCancel, }: { embed: CallEmbed; onCancel: () => void; }) { const [missing, setMissing] = useState([]); const setToast = useSetAtom(toastQueueAtom); const modalStyle = useModalStyle(440); useEffect(() => { const offMissing = embed.listenAction<{ data?: unknown }>('io.lotus.device_missing', (evt) => { const list = parseDeviceMissing(evt.detail?.data); if (list.length === 0) return; if (isAcceptedThisSession(list)) { embed.control.sendDeviceDecision(true); return; } setMissing(list); }); const offLost = embed.listenAction<{ data?: unknown }>('io.lotus.device_lost', (evt) => { const lost = parseDeviceLost(evt.detail?.data); if (!lost) return; setToast({ id: `device-lost-${lost.kind}-${Date.now()}`, iconSrc: lost.kind === 'audioinput' ? Icons.Mic : Icons.VolumeHigh, displayName: 'Audio device', body: describeLost(lost), roomName: embed.room.name ?? 'Voice call', roomId: embed.roomId, }); }); return () => { offMissing(); offLost(); }; }, [embed, setToast]); if (missing.length === 0) return null; const joinAnyway = () => { acceptForSession(missing); embed.control.sendDeviceDecision(true); setMissing([]); }; const cancel = () => { embed.control.sendDeviceDecision(false); setMissing([]); onCancel(); }; return ( }>
{missing.length === 1 ? describeMissing(missing[0]).title : "Your usual audio devices aren't connected"}
{missing.map((d) => { const t = describeMissing(d); return ( {t.expected} isn't connected. Join with {t.fallback} instead? ); })} Plug it in and choose Cancel to start over with it.
); }