94 lines
4.0 KiB
TypeScript
94 lines
4.0 KiB
TypeScript
import { useLocalStorage } from "@/hooks/useLocalStorage"
|
|
import { PREF } from "@/utils/const"
|
|
import ChargedButton from "../ChargedButton";
|
|
import { usePermissions } from "@/hooks/usePermission";
|
|
import styles from "@/css/Intro.module.css";
|
|
import { InputEvent, MouseEvent, MouseEventHandler, PointerEvent, useRef, useState } from "react";
|
|
|
|
export default function Intro() {
|
|
const [ stepStr, setStep ] = useLocalStorage(PREF.step, "0");
|
|
const { gpsStatus, cameraStatus, refresh } = usePermissions();
|
|
const [ rewatchScreen, setRewatchScreen ] = useState(false);
|
|
const [ videoEnded, setVideoEnded ] = useState(false);
|
|
const introVideoRef = useRef<HTMLVideoElement | null>(null);
|
|
|
|
const requestGPSPermission = () => {
|
|
navigator.geolocation.getCurrentPosition(() => refresh, () => refresh);
|
|
}
|
|
const requestCamPermission = () => {
|
|
navigator.mediaDevices.getUserMedia({
|
|
"video": { facingMode: { ideal: "environment" } },
|
|
"audio": false,
|
|
}).then((stream) => {
|
|
refresh();
|
|
stream.getTracks().forEach(track => track.stop());
|
|
alert("Keine Sorge! Die Kamera ist wieder ausgeschalten. Der Gerät zeigt Ihnen nur, dass darauf kurz zugegriffen wurde.");
|
|
}).catch((e) => refresh);
|
|
}
|
|
|
|
const handleVideoClick = (e: PointerEvent<HTMLVideoElement>): boolean => {
|
|
e.currentTarget.play();
|
|
return true;
|
|
};
|
|
|
|
return (
|
|
<div className="screen-container">
|
|
{ !rewatchScreen ?
|
|
<div>
|
|
<p>CODE EINGELÖST</p>
|
|
<p>TON AN</p>
|
|
<p>Für diese Tour werden extra Berechtigungen gebraucht.</p>
|
|
<p>Kamera: {cameraStatus}</p>
|
|
<p>GPS: {gpsStatus}</p>
|
|
<br></br>
|
|
<button onClick={requestGPSPermission} style={{marginBottom: "2rem", marginRight: "3rem"}}>GPS</button>
|
|
<button onClick={requestCamPermission} style={{marginBottom: "2rem", marginRight: "3rem"}}>Cam</button>
|
|
<button onClick={refresh} style={{marginBottom: "2rem", marginRight: "3rem"}}>Refresh</button>
|
|
<br></br>
|
|
<ChargedButton onAction={() => {
|
|
setRewatchScreen(true);
|
|
}} holdDuration={500} disabled={gpsStatus !== "granted" || cameraStatus !== "granted"}>
|
|
Video ansehen
|
|
</ChargedButton>
|
|
<div className={styles["overlay-video"]}>
|
|
|
|
</div>
|
|
</div>
|
|
:
|
|
<div className={styles["intro-video-container"]}>
|
|
<video
|
|
ref={introVideoRef}
|
|
disablePictureInPicture={true}
|
|
autoPlay={true}
|
|
loop={false}
|
|
autoFocus={true}
|
|
width={"100%"}
|
|
onEnded={() => setVideoEnded(true)}
|
|
onAbort={() => setVideoEnded(true)}
|
|
onError={() => setVideoEnded(true)}
|
|
onClick={handleVideoClick}
|
|
onContextMenu={(e) => {
|
|
e.preventDefault();
|
|
return false;
|
|
}}
|
|
>
|
|
<source src="/res/testvid.webm" type="video/webm"/>
|
|
</video>
|
|
{ videoEnded ? <div className={styles["rewatch-controls"]}>
|
|
<ChargedButton holdDuration={500} onAction={() => {
|
|
if (introVideoRef.current) {
|
|
introVideoRef.current.pause();
|
|
introVideoRef.current.currentTime = 0;
|
|
introVideoRef.current.play();
|
|
setVideoEnded(false);
|
|
}
|
|
}}>Video wiederholen?</ChargedButton>
|
|
<ChargedButton holdDuration={500} onAction={() => {
|
|
setStep("2");
|
|
}}>Wir sind bereit!</ChargedButton>
|
|
</div> : null }
|
|
</div>
|
|
}
|
|
</div>
|
|
)
|
|
} |