feat(media)!: add Google Cast by default to HLS, DASH media (#1661)

This commit is contained in:
Wesley Luyten
2026-06-12 17:34:14 -07:00
committed by GitHub
parent 1145f09e52
commit 0ffe1a9197
64 changed files with 2684 additions and 1300 deletions
+11 -2
View File
@@ -12,16 +12,25 @@ import { useDestroy } from './use-destroy';
* Instantiates the media class once, attaches it to the player on mount,
* and safely detaches on unmount using a functional updater to avoid race
* conditions when swapping media components (e.g. DashVideo → HlsVideo).
*
* An optional `setup` callback runs once on mount — e.g. to add media
* components via `addComponent`. Components registered there are destroyed
* together with the media instance on unmount (`media.destroy()` destroys
* all of its registered components).
*/
export function useMediaInstance<Instance extends Media & { destroy(): void }>(
MediaClass: new () => Instance
MediaClass: new () => Instance,
setup?: (media: Instance) => void
): Instance {
const [instance] = useState(() => new MediaClass());
const setMedia = useMediaAttach();
useDestroy(
instance,
() => setMedia?.(instance),
() => {
setup?.(instance);
setMedia?.(instance);
},
() => setMedia?.((prev) => (prev === instance ? null : prev))
);