From b917237db23258d9195468c46c27774b70f49118 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Mon, 6 May 2024 11:23:24 +0530 Subject: [PATCH] Code can become invalid after timeout --- web/apps/cast/src/pages/index.tsx | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/web/apps/cast/src/pages/index.tsx b/web/apps/cast/src/pages/index.tsx index 98dabd97e..5cf3f8f3a 100644 --- a/web/apps/cast/src/pages/index.tsx +++ b/web/apps/cast/src/pages/index.tsx @@ -11,6 +11,9 @@ export default function Index() { const [publicKeyB64, setPublicKeyB64] = useState(); const [privateKeyB64, setPrivateKeyB64] = useState(); const [pairingCode, setPairingCode] = useState(); + // TODO: This needs to change, since there is an interim period when the + // code becomes invalid. + const [haveInitializedCast, setHaveInitializedCast] = useState(false); const router = useRouter(); @@ -27,10 +30,11 @@ export default function Index() { }; useEffect(() => { - if (pairingCode) { - castReceiverLoadingIfNeeded().then((cast) => - advertiseCode(cast, () => pairingCode), - ); + if (pairingCode && !haveInitializedCast) { + castReceiverLoadingIfNeeded().then((cast) => { + setHaveInitializedCast(true); + advertiseCode(cast, () => pairingCode); + }); } }, [pairingCode]); @@ -54,10 +58,11 @@ export default function Index() { storeCastData(data); await router.push("/slideshow"); } catch (e) { + // Code has become invalid log.error("Failed to get cast data", e); // Start again from the beginning. - // setPairingCode(undefined); - // init(); + setPairingCode(undefined); + init(); } };