π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
feat: theatre component with video support
httpjamesm4441d8228ba6
diff --git a/apps/cast/package.json b/apps/cast/package.jsonindex f99ab8b2b4..23c612dde3 100644--- a/apps/cast/package.json+++ b/apps/cast/package.json@@ -9,6 +9,7 @@"lint": "next lint"},"dependencies": {+ "mime-types": "^2.1.35","next": "14.0.2","react": "^18","react-dom": "^18"diff --git a/apps/cast/src/components/Theatre/PhotoAuditorium.tsx b/apps/cast/src/components/Theatre/PhotoAuditorium.tsxnew file mode 100644index 0000000000..98ea68d23d--- /dev/null+++ b/apps/cast/src/components/Theatre/PhotoAuditorium.tsx@@ -0,0 +1,41 @@+import { SlideshowContext } from 'pages/slideshow';+import { useContext, useEffect } from 'react';++export default function PhotoAuditorium({ url }: { url: string }) {+ const { showNextSlide } = useContext(SlideshowContext);++ useEffect(() => {+ const timeout = setTimeout(() => {+ showNextSlide();+ }, 5000);++ return () => {+ clearTimeout(timeout);+ };+ }, [url]);++ return (+ <div+ style={{+ width: '100vw',+ height: '100vh',+ display: 'flex',+ justifyContent: 'center',+ alignItems: 'center',+ backgroundImage: `url(${url})`,+ backgroundSize: 'cover',+ backgroundPosition: 'center',+ backgroundRepeat: 'no-repeat',+ backgroundBlendMode: 'multiply',+ backgroundColor: 'rgba(0, 0, 0, 0.5)',+ }}>+ <img+ src={url}+ style={{+ maxWidth: '100%',+ maxHeight: '100%',+ }}+ />+ </div>+ );+}diff --git a/apps/cast/src/components/Theatre/VideoAuditorium.tsx b/apps/cast/src/components/Theatre/VideoAuditorium.tsxnew file mode 100644index 0000000000..230d30312f--- /dev/null+++ b/apps/cast/src/components/Theatre/VideoAuditorium.tsx@@ -0,0 +1,53 @@+import mime from 'mime-types';+import { SlideshowContext } from 'pages/slideshow';+import { useContext, useEffect, useRef } from 'react';++export default function VideoAuditorium({+ name,+ url,+}: {+ name: string;+ url: string;+}) {+ const { showNextSlide } = useContext(SlideshowContext);++ const videoRef = useRef<HTMLVideoElement>(null);++ useEffect(() => {+ attemptPlay();+ }, [url, videoRef]);++ const attemptPlay = async () => {+ if (videoRef.current) {+ try {+ await videoRef.current.play();+ } catch {+ showNextSlide();+ }+ }+ };++ return (+ <div+ style={{+ width: '100vw',+ height: '100vh',+ display: 'flex',+ justifyContent: 'center',+ alignItems: 'center',+ }}>+ <video+ ref={videoRef}+ autoPlay+ controls+ style={{+ maxWidth: '100vw',+ maxHeight: '100vh',+ }}+ onError={showNextSlide}+ onEnded={showNextSlide}>+ <source src={url} type={mime.lookup(name)} />+ </video>+ </div>+ );+}diff --git a/apps/cast/src/components/Theatre/index.tsx b/apps/cast/src/components/Theatre/index.tsxnew file mode 100644index 0000000000..071ba46316--- /dev/null+++ b/apps/cast/src/components/Theatre/index.tsx@@ -0,0 +1,20 @@+import { FILE_TYPE } from 'constants/file';+import PhotoAuditorium from './PhotoAuditorium';+import VideoAuditorium from './VideoAuditorium';++interface IProps {+ fileName: string;+ fileURL: string;+ type: FILE_TYPE;+}++export default function Theatre(props: IProps) {+ switch (props.type) {+ case FILE_TYPE.IMAGE:+ return <PhotoAuditorium url={props.fileURL} />;+ case FILE_TYPE.VIDEO:+ return (+ <VideoAuditorium name={props.fileName} url={props.fileURL} />+ );+ }+}diff --git a/apps/cast/src/pages/slideshow.tsx b/apps/cast/src/pages/slideshow.tsxindex becf4ad2dd..535439c0c4 100644--- a/apps/cast/src/pages/slideshow.tsx+++ b/apps/cast/src/pages/slideshow.tsx@@ -1,13 +1,17 @@-// import { Inter } from 'next/font/google';import PairedSuccessfullyOverlay from 'components/PairedSuccessfullyOverlay';+import Theatre from 'components/Theatre';import { FILE_TYPE } from 'constants/file';import { useRouter } from 'next/router';-import { useEffect, useState } from 'react';+import { createContext, useEffect, useState } from 'react';import { syncCollections } from 'services/collectionService';import { syncFiles } from 'services/fileService';import { EnteFile } from 'types/file';import { downloadFileAsBlob, isRawFileFromFileName } from 'utils/file';+export const SlideshowContext = createContext<{+ showNextSlide: () => void;+}>(null);+export default function Slideshow() {const [collectionFiles, setCollectionFiles] = useState<EnteFile[]>([]);@@ -17,6 +21,10 @@ export default function Slideshow() {const [loading, setLoading] = useState(true);+ const [renderableFileURLCache, setRenderableFileURLCache] = useState<+ Record<string, string>+ >({});+const init = async () => {try {const collections = await syncCollections();@@ -50,6 +58,12 @@ export default function Slideshow() {return false;}+ const fileSizeLimit = 100 * 1024 * 1024;++ if (file.info.fileSize > fileSizeLimit) {+ return false;+ }+const name = file.metadata.title;if (fileType === FILE_TYPE.IMAGE) {@@ -73,33 +87,42 @@ export default function Slideshow() {useEffect(() => {if (collectionFiles.length < 1) return;- // create interval to change slide- const interval = setInterval(() => {- // set the currentFile to the next file in the collection for the slideshow- const currentIndex = collectionFiles.findIndex(- (file) => file.id === currentFile?.id- );+ showNextSlide();+ }, [collectionFiles]);- const nextIndex = (currentIndex + 1) % collectionFiles.length;+ const showNextSlide = () => {+ const currentIndex = collectionFiles.findIndex(+ (file) => file.id === currentFile?.id+ );- const nextFile = collectionFiles[nextIndex];+ const nextIndex = (currentIndex + 1) % collectionFiles.length;- setCurrentFile(nextFile);- }, 5000);+ const nextFile = collectionFiles[nextIndex];- return () => {- clearInterval(interval);- };- }, [collectionFiles, currentFile]);+ setCurrentFile(nextFile);+ };const [renderableFileURL, setRenderableFileURL] = useState<string>('');const getRenderableFileURL = async () => {+ if (!currentFile) return;++ if (renderableFileURLCache[currentFile.id]) {+ setRenderableFileURL(renderableFileURLCache[currentFile.id]);+ setLoading(false);+ return;+ }+try {const blob = await downloadFileAsBlob(currentFile as EnteFile);const url = URL.createObjectURL(blob);+ setRenderableFileURLCache({+ ...renderableFileURLCache,+ [currentFile?.id]: url,+ });+setRenderableFileURL(url);} catch (e) {return;@@ -116,22 +139,13 @@ export default function Slideshow() {return (<>- <div- style={{- width: '100vw',- height: '100vh',- display: 'flex',- justifyContent: 'center',- alignItems: 'center',- }}>- <img- src={renderableFileURL}- style={{- maxWidth: '100%',- maxHeight: '100%',- }}+ <SlideshowContext.Provider value={{ showNextSlide }}>+ <Theatre+ fileURL={renderableFileURL}+ type={currentFile?.metadata.fileType}+ fileName={currentFile?.metadata.title}/>- </div>+ </SlideshowContext.Provider>{loading && <PairedSuccessfullyOverlay />}</>);diff --git a/yarn.lock b/yarn.lockindex 40f33f9b26..1313499b05 100644--- a/yarn.lock+++ b/yarn.lock@@ -3880,7 +3880,7 @@ [email protected]:resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.52.0.tgz#bbabcdc02859f4987301c856e3387ce5ec43bf70"integrity sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==-mime-types@^2.1.12:+mime-types@^2.1.12, mime-types@^2.1.35:version "2.1.35"resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.35.tgz#381a871b62a734450660ae3deee44813f70d959a"integrity sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==