feat(metadata): change window.meta

This commit is contained in:
Jordaar 2023-06-26 19:16:29 +05:30
parent 8acf4ef478
commit bfa9638d0e

View File

@ -1,29 +1,21 @@
import { useEffect } from "react"; import { useEffect } from "react";
import { MWCaption } from "@/backend/helpers/streams";
import { DetailedMeta } from "@/backend/metadata/getmeta";
import { useVideoPlayerDescriptor } from "@/video/state/hooks"; import { useVideoPlayerDescriptor } from "@/video/state/hooks";
import {
VideoMediaPlayingEvent,
useMediaPlaying,
} from "@/video/state/logic/mediaplaying";
import { useMeta } from "@/video/state/logic/meta"; import { useMeta } from "@/video/state/logic/meta";
import { useProgress } from "@/video/state/logic/progress"; import { VideoProgressEvent, useProgress } from "@/video/state/logic/progress";
import { VideoPlayerMeta } from "@/video/state/types";
export type WindowMeta = { export type WindowMeta = {
meta: DetailedMeta; media: VideoPlayerMeta;
captions: MWCaption[]; state: {
episode?: { mediaPlaying: VideoMediaPlayingEvent;
episodeId: string; progress: VideoProgressEvent;
seasonId: string;
}; };
seasons?: { };
id: string;
number: number;
title: string;
episodes?: { id: string; number: number; title: string }[];
}[];
progress: {
time: number;
duration: number;
};
} | null;
declare global { declare global {
interface Window { interface Window {
@ -35,18 +27,16 @@ export function MetaAction() {
const descriptor = useVideoPlayerDescriptor(); const descriptor = useVideoPlayerDescriptor();
const meta = useMeta(descriptor); const meta = useMeta(descriptor);
const progress = useProgress(descriptor); const progress = useProgress(descriptor);
const mediaPlaying = useMediaPlaying(descriptor);
useEffect(() => { useEffect(() => {
if (!window.meta) window.meta = {}; if (!window.meta) window.meta = {};
if (meta) { if (meta) {
window.meta[descriptor] = { window.meta[descriptor] = {
meta: meta.meta, media: meta,
captions: meta.captions, state: {
seasons: meta.seasons, mediaPlaying,
episode: meta.episode, progress,
progress: {
time: progress.time,
duration: progress.duration,
}, },
}; };
} }
@ -54,7 +44,7 @@ export function MetaAction() {
return () => { return () => {
if (window.meta) delete window.meta[descriptor]; if (window.meta) delete window.meta[descriptor];
}; };
}, [meta, descriptor, progress]); }, [meta, descriptor, mediaPlaying, progress]);
return null; return null;
} }