This commit is contained in:
Manav Rathi 2024-05-04 11:18:23 +05:30
parent efdf980558
commit 882af50507
No known key found for this signature in database

View file

@ -14,6 +14,10 @@ export default function Index() {
const router = useRouter();
useEffect(() => {
init();
}, []);
const init = () => {
register().then((r) => {
setPublicKeyB64(r.publicKeyB64);
@ -22,16 +26,19 @@ export default function Index() {
});
};
useEffect(() => {
init();
}, []);
useEffect(() => {
castReceiverLoadingIfNeeded().then((cast) =>
advertiseCode(cast, () => pairingCode),
);
}, []);
useEffect(() => {
if (!publicKeyB64 || !privateKeyB64 || !pairingCode) return;
const interval = setInterval(pollTick, 2000);
return () => clearInterval(interval);
}, [publicKeyB64, privateKeyB64, pairingCode]);
const pollTick = async () => {
const registration = { publicKeyB64, privateKeyB64, pairingCode };
try {
@ -52,13 +59,6 @@ export default function Index() {
}
};
useEffect(() => {
if (!publicKeyB64 || !privateKeyB64 || !pairingCode) return;
const interval = setInterval(pollTick, 2000);
return () => clearInterval(interval);
}, [publicKeyB64, privateKeyB64, pairingCode]);
return (
<>
<div