diff --git a/web/apps/cast/src/pages/index.tsx b/web/apps/cast/src/pages/index.tsx index bc0f6253d..98dabd97e 100644 --- a/web/apps/cast/src/pages/index.tsx +++ b/web/apps/cast/src/pages/index.tsx @@ -27,10 +27,12 @@ export default function Index() { }; useEffect(() => { - castReceiverLoadingIfNeeded().then((cast) => - advertiseCode(cast, () => pairingCode), - ); - }, []); + if (pairingCode) { + castReceiverLoadingIfNeeded().then((cast) => + advertiseCode(cast, () => pairingCode), + ); + } + }, [pairingCode]); useEffect(() => { if (!publicKeyB64 || !privateKeyB64 || !pairingCode) return; @@ -54,8 +56,8 @@ export default function Index() { } catch (e) { log.error("Failed to get cast data", e); // Start again from the beginning. - setPairingCode(undefined); - init(); + // setPairingCode(undefined); + // init(); } }; diff --git a/web/apps/cast/src/services/pair.ts b/web/apps/cast/src/services/pair.ts index 66f9feddd..987dfd5c9 100644 --- a/web/apps/cast/src/services/pair.ts +++ b/web/apps/cast/src/services/pair.ts @@ -116,8 +116,9 @@ export const advertiseCode = ( const namespace = "urn:x-cast:pair-request"; const options = new cast.framework.CastReceiverOptions(); + options.skipPlayersLoad = true; // Do not automatically close the connection when the sender disconnects. - options.maxInactivity = 3600; /* 1 hour */ + // options.maxInactivity = 3600; /* 1 hour */ // TODO:Is this required? The docs say "(The default type of a message bus // is JSON; if not provided here)." options.customNamespaces = Object.assign({});