Wait for pairing code before initializing cast
This commit is contained in:
parent
8f2580e13f
commit
943f9ea9c1
2 changed files with 10 additions and 7 deletions
|
@ -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();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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({});
|
||||
|
|
Loading…
Add table
Reference in a new issue