Add premid support back (in different format)

This commit is contained in:
mrjvs 2023-11-20 20:09:50 +01:00
parent 340673237b
commit 9c1195e131
2 changed files with 90 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import { OverlayDisplay } from "@/components/overlays/OverlayDisplay";
import { CastingInternal } from "@/components/player/internals/CastingInternal";
import { HeadUpdater } from "@/components/player/internals/HeadUpdater";
import { KeyboardEvents } from "@/components/player/internals/KeyboardEvents";
import { MetaReporter } from "@/components/player/internals/MetaReporter";
import { ProgressSaver } from "@/components/player/internals/ProgressSaver";
import { ThumbnailScraper } from "@/components/player/internals/ThumbnailScraper";
import { VideoClickTarget } from "@/components/player/internals/VideoClickTarget";
@ -84,6 +85,7 @@ export function Container(props: PlayerProps) {
return (
<div className="relative">
<BaseContainer>
<MetaReporter />
<ThumbnailScraper />
<CastingInternal />
<VideoContainer />

View File

@ -0,0 +1,88 @@
import { useEffect } from "react";
import { usePlayerStore } from "@/stores/player/store";
export type WindowMeta = {
meta: {
type: "show" | "movie";
tmdbId: string;
title: string;
year: number;
poster?: string;
};
episode?: {
number: number;
tmdbId: string;
title: string;
};
season?: {
number: number;
tmdbId: string;
title: string;
};
progress: {
time: number;
duration: number;
};
controls: {
isPlaying: boolean;
isLoading: boolean;
};
};
declare global {
interface Window {
meta?: {
player?: WindowMeta;
};
}
}
export function MetaReporter() {
const meta = usePlayerStore((s) => s.meta);
const progress = usePlayerStore((s) => s.progress);
const mediaPlaying = usePlayerStore((s) => s.mediaPlaying);
useEffect(() => {
if (!window.meta) window.meta = {};
if (meta) {
window.meta.player = {
meta: {
title: meta.title,
type: meta.type,
tmdbId: meta.tmdbId,
year: meta.releaseYear,
poster: meta.poster,
},
controls: {
isPlaying: mediaPlaying.isPlaying,
isLoading: mediaPlaying.isLoading,
},
season: meta.season
? {
number: meta.season.number,
tmdbId: meta.season.tmdbId,
title: meta.season.title,
}
: undefined,
episode: meta.episode
? {
number: meta.episode.number,
tmdbId: meta.episode.tmdbId,
title: meta.episode.title,
}
: undefined,
progress: {
time: progress.time,
duration: progress.duration,
},
};
}
return () => {
if (window.meta) delete window.meta.player;
};
}, [meta, progress, mediaPlaying]);
return null;
}