π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
feat: new cast receiver, CSP change
httpjamesmdf93353513c0
diff --git a/apps/cast/configUtil.js b/apps/cast/configUtil.jsindex 679a92f30b..795cf15dc2 100644--- a/apps/cast/configUtil.js+++ b/apps/cast/configUtil.js@@ -30,6 +30,7 @@ module.exports = {'form-action': "'none'",'report-uri': ' https://csp-reporter.ente.io/local','report-to': ' https://csp-reporter.ente.io/local',+ 'script-src-elem': "'self' https://www.gstatic.com",},ALL_ROUTES: '/(.*)',diff --git a/apps/cast/src/pages/slideshow.tsx b/apps/cast/src/pages/slideshow.tsxindex 1084d0c4b3..84ca521dbd 100644--- a/apps/cast/src/pages/slideshow.tsx+++ b/apps/cast/src/pages/slideshow.tsx@@ -7,7 +7,7 @@ import { getCollection } from 'services/collectionService';import { syncFiles } from 'services/fileService';import { EnteFile } from 'types/file';import { downloadFileAsBlob, isRawFileFromFileName } from 'utils/file';-import { useCastSender } from '@ente/shared/hooks/useCastSender';+import { useCastReceiver } from '@ente/shared/hooks/useCastReceiver';export const SlideshowContext = createContext<{showNextSlide: () => void;@@ -27,18 +27,16 @@ export default function Slideshow() {Record<string, string>>({});- const { cast } = useCastSender();+ const { cast } = useCastReceiver();const init = async () => {- const options = new cast.framework.CastReceiverOptions();-- options.disableIdleTimeout = true;+ try {+ const options = new cast.framework.CastReceiverOptions();- const context = cast.framework.CastReceiverContext.getInstance();+ options.disableIdleTimeout = true;- context.start(options);+ cast.framework.CastReceiverContext.getInstance().start(options);- try {// get requested collection id from localStorageconst requestedCollectionID =window.localStorage.getItem('targetCollectionId');diff --git a/packages/shared/hooks/useCastReceiver.tsx b/packages/shared/hooks/useCastReceiver.tsxnew file mode 100644index 0000000000..31508edc10--- /dev/null+++ b/packages/shared/hooks/useCastReceiver.tsx@@ -0,0 +1,45 @@+declare const cast: any;++import { useEffect, useState } from 'react';++type Receiver = {+ cast: typeof cast;+};++const load = (() => {+ let promise: Promise<Receiver> | null = null;++ return () => {+ if (promise === null) {+ promise = new Promise((resolve) => {+ const script = document.createElement('script');+ script.src =+ 'https://www.gstatic.com/cast/sdk/libs/caf_receiver/v3/cast_receiver_framework.js';++ window.__onGCastApiAvailable = (isAvailable) => {+ if (isAvailable) {+ resolve({+ cast,+ });+ }+ };+ document.body.appendChild(script);+ });+ }+ return promise;+ };+})();++export const useCastReceiver = () => {+ const [receiver, setReceiver] = useState<Receiver | null>({+ cast: null,+ });++ useEffect(() => {+ load().then((receiver) => {+ setReceiver(receiver);+ });+ });++ return receiver;+};