diff --git a/.eslintrc.js b/.eslintrc.js index c1a2b2a7..a2da2b2a 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -52,6 +52,7 @@ module.exports = { "no-await-in-loop": "off", "no-nested-ternary": "off", "prefer-destructuring": "off", + "no-param-reassign": "off", "@typescript-eslint/no-unused-vars": ["warn", { argsIgnorePattern: "^_" }], "react/jsx-filename-extension": [ "error", diff --git a/package.json b/package.json index 22fa2e07..ad03942a 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "hls.js": "^1.0.7", "i18next": "^22.4.5", "i18next-browser-languagedetector": "^7.0.1", + "immer": "^10.0.2", "json5": "^2.2.0", "lodash.throttle": "^4.1.1", "nanoid": "^4.0.0", diff --git a/src/components/player/Player.tsx b/src/components/player/Player.tsx new file mode 100644 index 00000000..4cd0f48e --- /dev/null +++ b/src/components/player/Player.tsx @@ -0,0 +1,3 @@ +import { ReactNode } from "react"; +export * as Atoms from "./atoms/index"; +export \ No newline at end of file diff --git a/src/components/player/base/Container.tsx b/src/components/player/base/Container.tsx index 5b682393..d8e3cb93 100644 --- a/src/components/player/base/Container.tsx +++ b/src/components/player/base/Container.tsx @@ -1,9 +1,16 @@ import { ReactNode } from "react"; +import { VideoContainer } from "@/components/player/internals/VideoContainer"; + export interface PlayerProps { children?: ReactNode; } export function Container(props: PlayerProps) { - return
{props.children}
; + return ( +
+ + {props.children} +
+ ); } diff --git a/src/components/player/hooks/usePlayer.ts b/src/components/player/hooks/usePlayer.ts new file mode 100644 index 00000000..0db61398 --- /dev/null +++ b/src/components/player/hooks/usePlayer.ts @@ -0,0 +1,20 @@ +import { MWStreamType } from "@/backend/helpers/streams"; +import { playerStatus } from "@/stores/player/slices/source"; +import { usePlayerStore } from "@/stores/player/store"; + +export interface Source { + url: string; + type: MWStreamType; +} + +export function usePlayer() { + const setStatus = usePlayerStore((s) => s.setStatus); + const setSource = usePlayerStore((s) => s.setSource); + + return { + playMedia(source: Source) { + setSource(source.url, source.type); + setStatus(playerStatus.PLAYING); + }, + }; +} diff --git a/src/components/player/internals/VideoContainer.tsx b/src/components/player/internals/VideoContainer.tsx index 53907341..1cd28f51 100644 --- a/src/components/player/internals/VideoContainer.tsx +++ b/src/components/player/internals/VideoContainer.tsx @@ -1,3 +1,14 @@ +import { useEffect, useRef } from "react"; + +import { usePlayerStore } from "@/stores/player/store"; + export function VideoContainer() { - return
; + const player = usePlayerStore(); + const videoEl = useRef(null); + + useEffect(() => { + if (videoEl.current) videoEl.current.src = player.source?.url ?? ""; + }, [player.source?.url]); + + return