import * as React from "react"; import { DailyProvider } from "@daily-co/daily-react"; import DailyIframe, { type DailyCall } from "@daily-co/daily-js"; import { logger } from "@buzztrail/shared-utils"; export const CVIProvider = ({ children }: { children: React.ReactNode }): React.JSX.Element => { const callObject = React.useMemo(() => { logger.debug("[CVIProvider] Creating Daily callObject"); const co = DailyIframe.createCallObject({ // Disable Daily.co's built-in UI elements showLeaveButton: false, // Note: showLocalVideo and showParticipantsBar are not available in call object mode // These will be handled by our custom UI components }); logger.debug("[CVIProvider] Daily callObject created", { success: !!co, callObject: co ? 'DailyCall instance' : 'null/undefined' }); // Note: We can't set initial video/audio state here because the call object // needs to be properly initialized first. The initial state will be handled // by the individual hooks when they're ready. logger.debug("[CVIProvider] Call object created - initial device states will be set by hooks"); return co as DailyCall; }, []); React.useEffect((): (() => void) => { return () => { try { logger.debug("[CVIProvider] Destroying Daily callObject"); void callObject?.destroy(); } catch { // Ignore destroy errors } }; }, [callObject]); return {children}; };