Fix do not rely on useEffect to set google cast function before script load

This commit is contained in:
Merlin Scheurer 2026-05-23 11:02:49 +02:00
parent 92af2f586f
commit 9bf2050111
1 changed files with 7 additions and 9 deletions

View File

@ -138,6 +138,13 @@ const GoogleCast = ({ video, setRefresh, onWatchStateChanged }: GoogleCastProps)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [setRefresh, video]);
// @ts-expect-error __onGCastApiAvailable is the google cast window hook ( source: https://developers.google.com/cast/docs/web_sender/integrate )
window['__onGCastApiAvailable'] ??= function (isAvailable: boolean) {
if (isAvailable) {
setup();
}
};
const startPlayback = useCallback(() => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const chrome = (globalThis as any).chrome;
@ -195,15 +202,6 @@ const GoogleCast = ({ video, setRefresh, onWatchStateChanged }: GoogleCastProps)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [video?.media_url, video?.subtitles, video?.title, video?.vid_thumb_url]);
useEffect(() => {
// @ts-expect-error __onGCastApiAvailable is the google cast window hook ( source: https://developers.google.com/cast/docs/web_sender/integrate )
window['__onGCastApiAvailable'] = function (isAvailable: boolean) {
if (isAvailable) {
setup();
}
};
}, [setup]);
useEffect(() => {
console.log('isConnected', isConnected);
if (isConnected) {