Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Update based on new API spec

Neeraj Gupta89f8e2f5649c
diff --git a/apps/cast/src/pages/index.tsx b/apps/cast/src/pages/index.tsx
index f0dd64b6e5..fe043d4698 100644
--- a/apps/cast/src/pages/index.tsx
+++ b/apps/cast/src/pages/index.tsx
@@ -61,24 +61,23 @@ export default function PairingMode() {
useEffect(() => {
if (!cast) return;
const context = cast.framework.CastReceiverContext.getInstance();
+ if (!context.isInitialized) {
+ const options = new cast.framework.CastReceiverOptions();
+ options.customNamespaces = Object.assign({});
+ options.customNamespaces['urn:x-cast:pair-request'] =
+ cast.framework.system.MessageType.JSON;
- const options = new cast.framework.CastReceiverOptions();
- options.customNamespaces = Object.assign({});
- options.customNamespaces['urn:x-cast:pair-request'] =
- cast.framework.system.MessageType.JSON;
+ options.disableIdleTimeout = true;
- options.disableIdleTimeout = true;
-
- context.addCustomMessageListener(
- 'urn:x-cast:pair-request',
- messageReceiveHandler
- );
-
- context.start(options);
-
- return () => {
- context.stop(options);
- };
+ context.addCustomMessageListener(
+ 'urn:x-cast:pair-request',
+ messageReceiveHandler
+ );
+ context.start(options);
+ return () => {
+ context.stop(options);
+ };
+ }
}, [cast]);
const messageReceiveHandler = (message: {
@@ -115,13 +114,20 @@ export default function PairingMode() {
};
const pollForCastData = async () => {
- if (codePending) return;
+ if (codePending) {
+ console.log('code pending');
+ return;
+ }
// see if we were acknowledged on the client.
// the client will send us the encrypted payload using our public key that we advertised.
// then, we can decrypt this and store all the necessary info locally so we can play the collection slideshow.
let devicePayload = '';
try {
- devicePayload = await castGateway.getCastData(`${digits.join('')}`);
+ const encDastData = await castGateway.getCastData(
+ `${digits.join('')}`
+ );
+ if (!encDastData) return;
+ devicePayload = encDastData;
} catch (e) {
return;
}
@@ -155,6 +161,8 @@ export default function PairingMode() {
`${digits.join('')}`,
publicKeyB64
);
+ setCodeGeneratedAt(new Date());
+ setCodePending(false);
} catch (e) {
// schedule init after 5 seconds
setTimeout(() => {
@@ -162,9 +170,6 @@ export default function PairingMode() {
}, 5000);
return;
}
-
- setCodeGeneratedAt(new Date());
- setCodePending(false);
};
const router = useRouter();
@@ -174,7 +179,6 @@ export default function PairingMode() {
const interval = setInterval(async () => {
const data = await pollForCastData();
-
if (!data) return;
storePayloadLocally(data);
await router.push('/slideshow');
@@ -183,7 +187,7 @@ export default function PairingMode() {
return () => {
clearInterval(interval);
};
- }, [digits, publicKeyB64, privateKeyB64]);
+ }, [digits, publicKeyB64, privateKeyB64, codePending]);
useEffect(() => {
if (!publicKeyB64) return;
diff --git a/packages/shared/network/cast.ts b/packages/shared/network/cast.ts
index 9c1f9e14f1..41f1673357 100644
--- a/packages/shared/network/cast.ts
+++ b/packages/shared/network/cast.ts
@@ -6,7 +6,7 @@ import { getEndpoint } from './api';
class CastGateway {
constructor() {}
- public async getCastData(code: string): Promise<string> {
+ public async getCastData(code: string): Promise<string | null> {
let resp;
try {
resp = await HTTPService.get(
@@ -16,7 +16,7 @@ class CastGateway {
logError(e, 'failed to getCastData');
throw e;
}
- return resp.data.encPayload;
+ return resp.data.encCastData;
}
public async getPublicKey(code: string): Promise<string> {