mirror of
https://github.com/videojs/video.js.git
synced 2026-11-21 08:24:15 +01:00
30 lines
1.0 KiB
TypeScript
30 lines
1.0 KiB
TypeScript
import type { PreloadValue } from '@app/constants';
|
|
import { onSandboxStateChange, readSandboxState, type SandboxState } from '@app/shared/sandbox-listener';
|
|
import { useEffect, useState } from 'react';
|
|
|
|
import { installSandboxMirror } from './../sandbox-mirror';
|
|
|
|
/** The attributes the settings menu controls, as props for a media component. */
|
|
export interface SandboxMediaProps {
|
|
autoPlay: boolean;
|
|
muted: boolean;
|
|
loop: boolean;
|
|
preload: PreloadValue;
|
|
}
|
|
|
|
export interface Sandbox extends SandboxState {
|
|
readonly mediaProps: SandboxMediaProps;
|
|
}
|
|
|
|
/** The shell's selections for this page, kept current as it streams changes after load. */
|
|
export function useSandbox(): Sandbox {
|
|
const [state, setState] = useState(() => readSandboxState('react'));
|
|
|
|
useEffect(() => onSandboxStateChange((change) => setState((current) => ({ ...current, ...change }))), []);
|
|
useEffect(() => installSandboxMirror(), []);
|
|
|
|
const { autoplay, muted, loop, preload } = state;
|
|
|
|
return { ...state, mediaProps: { autoPlay: autoplay, muted, loop, preload } };
|
|
}
|