From 4df8b511e7f97f3f4ad61ea73b11474e87e30354 Mon Sep 17 00:00:00 2001 From: koryphaee Date: Sat, 9 May 2026 18:38:44 +0200 Subject: [PATCH] Fix cast initialization order (#1168) --- frontend/src/components/GoogleCast.tsx | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/frontend/src/components/GoogleCast.tsx b/frontend/src/components/GoogleCast.tsx index d862d343..f89b3903 100644 --- a/frontend/src/components/GoogleCast.tsx +++ b/frontend/src/components/GoogleCast.tsx @@ -197,11 +197,22 @@ const GoogleCast = ({ video, setRefresh, onWatchStateChanged }: GoogleCastProps) useEffect(() => { // @ts-expect-error __onGCastApiAvailable is the google cast window hook ( source: https://developers.google.com/cast/docs/web_sender/integrate ) + // this needs to be registered before the script below is executed window['__onGCastApiAvailable'] = function (isAvailable: boolean) { if (isAvailable) { setup(); } }; + + const scriptId = 'google-cast-sdk'; + // avoid injecting the script multiple times + if (!document.getElementById(scriptId)) { + const script = document.createElement('script'); + script.id = scriptId; + script.src = 'https://www.gstatic.com/cv/js/sender/v1/cast_sender.js?loadCastFramework=1'; + script.async = true; + document.body.appendChild(script); + } }, [setup]); useEffect(() => { @@ -217,12 +228,6 @@ const GoogleCast = ({ video, setRefresh, onWatchStateChanged }: GoogleCastProps) return (
-