mirror of
https://github.com/zoriya/v10.git
synced 2026-08-16 02:45:09 +00:00
feat(media)!: add Google Cast by default to HLS, DASH media (#1661)
This commit is contained in:
@@ -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))
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user