feat(cast): allow custom cast data and custom receivers

This commit is contained in:
2026-07-19 13:59:45 +02:00
parent 8656fb8068
commit ee4b1a3e32
6 changed files with 48 additions and 25 deletions
+15 -3
View File
@@ -9,7 +9,7 @@ import {
} from "react";
import { WebOmniPlayer } from "./player.web";
import type { OmniPlayer } from "./types/player";
import type { Source } from "./types/source";
import type { CastOptions, Source } from "./types/source";
import { useLazyRef } from "./utils/lazy-ref";
export const VideoPlayer = createPlayer({ features: videoFeatures });
@@ -19,15 +19,21 @@ const PlayerCtx = createContext<OmniPlayer>(null!);
export const OmniProvider = ({
children,
source,
cast,
showNotification = false,
}: {
source: Source;
cast?: CastOptions;
children: ReactNode;
showNotification?: boolean;
}) => {
return (
<VideoPlayer.Provider>
<PlayerInitializer source={source} showNotification={showNotification}>
<PlayerInitializer
source={source}
cast={cast}
showNotification={showNotification}
>
{children}
</PlayerInitializer>
</VideoPlayer.Provider>
@@ -37,10 +43,12 @@ export const OmniProvider = ({
const PlayerInitializer = ({
children,
source,
cast,
showNotification,
}: {
children: ReactNode;
source: Source;
cast?: CastOptions;
showNotification: boolean;
}) => {
const store = VideoPlayer.usePlayer();
@@ -52,10 +60,14 @@ const PlayerInitializer = ({
const uri = source.src[0]?.uri;
if (uri !== seekedForSrc.current) {
seekedForSrc.current = uri;
if (source.startTime) store.seek(source.startTime)
if (source.startTime) store.seek(source.startTime);
}
}, [source, store]);
useEffect(() => {
player.castOptions = cast ?? null;
}, [cast]);
useEffect(() => {
player.showNotification = showNotification;
}, [showNotification]);