瀏覽代碼

Wait for pairing code before initializing cast

Manav Rathi 1 年之前
父節點
當前提交
943f9ea9c1
共有 2 個文件被更改,包括 10 次插入7 次删除
  1. 8 6
      web/apps/cast/src/pages/index.tsx
  2. 2 1
      web/apps/cast/src/services/pair.ts

+ 8 - 6
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();
         }
     };
 

+ 2 - 1
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({});