import { createPlayer } from "@videojs/react"; import { GoogleCast } from "@videojs/react/media/google-cast"; import { videoFeatures } from "@videojs/react/video"; import { createContext, type ReactNode, useContext, useEffect } from "react"; import { usePlayerState } from "./events"; import { WebOmniPlayer } from "./player.web"; import type { OmniPlayer, PlayerBackend } from "./types/player"; import type { CastOptions, Source } from "./types/source"; import { useLazyRef } from "./utils/lazy-ref"; export const VideoPlayer = createPlayer({ features: videoFeatures }); const PlayerCtx = createContext(null!); export const OmniProvider = ({ children, source, cast, // Web always uses video.js; accepted for API parity with native. backend: _backend, showNotification = false, }: { source?: Source; cast?: CastOptions; backend?: PlayerBackend; children: ReactNode; showNotification?: boolean; }) => { return ( {children} ); }; const PlayerInitializer = ({ children, source, cast, showNotification, }: { children: ReactNode; source?: Source; cast?: CastOptions; showNotification: boolean; }) => { const store = VideoPlayer.usePlayer(); const player = useLazyRef(() => new WebOmniPlayer(store)); useEffect(() => { player.source = source; }, [source]); useEffect(() => { player.showNotification = showNotification; }, [showNotification]); return ( {children} ); }; const CastBridge = ({ cast }: { cast?: CastOptions | null }) => { const source = usePlayerState("source"); return ( ); }; export const usePlayer = () => useContext(PlayerCtx);