diff --git a/src/_oldvideo/components/internal/ThumbnailGeneratorInternal.tsx b/src/_oldvideo/components/internal/ThumbnailGeneratorInternal.tsx index 2ed36d69..702b687c 100644 --- a/src/_oldvideo/components/internal/ThumbnailGeneratorInternal.tsx +++ b/src/_oldvideo/components/internal/ThumbnailGeneratorInternal.tsx @@ -54,6 +54,7 @@ export default function ThumbnailGeneratorInternal() { const descriptor = useVideoPlayerDescriptor(); const source = useSource(descriptor); + // TODO fix memory leak const videoRef = useRef(document.createElement("video")); const canvasRef = useRef(document.createElement("canvas")); const hlsRef = useRef(new Hls()); diff --git a/src/components/player/Player.ts b/src/components/player/Player.ts deleted file mode 100644 index 0931ffa1..00000000 --- a/src/components/player/Player.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from "./atoms"; -export * from "./base/Container"; diff --git a/src/components/player/Player.tsx b/src/components/player/Player.tsx index 4cd0f48e..0931ffa1 100644 --- a/src/components/player/Player.tsx +++ b/src/components/player/Player.tsx @@ -1,3 +1,2 @@ -import { ReactNode } from "react"; -export * as Atoms from "./atoms/index"; -export \ No newline at end of file +export * from "./atoms"; +export * from "./base/Container"; diff --git a/src/components/player/README.md b/src/components/player/README.md new file mode 100644 index 00000000..d85289fd --- /dev/null +++ b/src/components/player/README.md @@ -0,0 +1,16 @@ +# Video player component + +Video player is quite a complex component, so here is a rundown of all the parts + +# Composable parts +These parts can be used to build any shape of a video player. + - `/atoms`- any ui element that controls the player. (Seekbar, Pause button, quality selection, etc) + - `/base` - base components that are used to build a player. Like the main container + +# internal parts +These parts are internally used, they aren't exported. Do not use them outside of player internals. +- `/display` - display interface, abstraction on how to actually play the content (e.g Video element, HLS player, Standard video element, etc) +- `/internals` - Internal components that are always rendered on every player. +- `/utils` - miscellaneous logic +- `/hooks` - hooks only used for video player +- `~/src/stores/player` - state for the video player. Should only be used by internal parts diff --git a/src/components/player/display/displayInterface.ts b/src/components/player/display/displayInterface.ts new file mode 100644 index 00000000..99ddc52c --- /dev/null +++ b/src/components/player/display/displayInterface.ts @@ -0,0 +1,22 @@ +import { Source } from "@/components/player/hooks/usePlayer"; + +type EventMap = Record; +type EventKey = string & keyof T; +type EventReceiver = (params: T) => void; + +export interface Emitter { + on>(eventName: K, fn: EventReceiver): void; + off>(eventName: K, fn: EventReceiver): void; + emit>(eventName: K, params: T[K]): void; +} + +interface Listener { + on>(eventName: K, fn: EventReceiver): void; +} + +export interface DisplayInterface + extends Listener { + play(): void; + pause(): void; + load(source: Source): void; +} diff --git a/src/components/player/internals/VideoContainer.tsx b/src/components/player/internals/VideoContainer.tsx index 1cd28f51..39076e67 100644 --- a/src/components/player/internals/VideoContainer.tsx +++ b/src/components/player/internals/VideoContainer.tsx @@ -1,14 +1,36 @@ -import { useEffect, useRef } from "react"; +import { RefObject, useEffect, useRef } from "react"; +import { MWStreamType } from "@/backend/helpers/streams"; +import { SourceSliceSource } from "@/stores/player/slices/source"; +import { AllSlices } from "@/stores/player/slices/types"; import { usePlayerStore } from "@/stores/player/store"; -export function VideoContainer() { - const player = usePlayerStore(); - const videoEl = useRef(null); - - useEffect(() => { - if (videoEl.current) videoEl.current.src = player.source?.url ?? ""; - }, [player.source?.url]); - - return