Skip to content

Commit

Permalink
disabled controls
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronshiel committed Oct 8, 2024
1 parent fb74a9b commit 3735cdc
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
14 changes: 12 additions & 2 deletions client/src/components/video-player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { useWithVideoPlayerHeight } from "use-with-video-player-height";
import { useWithScreenOrientation } from "use-with-orientation";
import { useSelector } from "react-redux";
import { getUtterance } from "api";
import { controlsDisableHelper } from "hooks/controls-disable-helper";

export interface VideoPlayerData {
videoUrl: string;
Expand Down Expand Up @@ -88,6 +89,7 @@ export default function VideoPlayer(args: VideoPlayerParams): JSX.Element {
getUtterance(state.mentorsById[state.curMentor], UtteranceName.INTRO)
);
const [introEnded, setIntroEnded] = useState<boolean>(false);
const { enabled: controlsEnabled, interacted } = controlsDisableHelper();

useEffect(() => {
if (isIntro && videoUrl) {
Expand Down Expand Up @@ -356,14 +358,23 @@ export default function VideoPlayer(args: VideoPlayerParams): JSX.Element {
<div
data-cy={"answer-video-player-wrapper"}
style={{ width: "100%", height: "auto", justifyContent: "center" }}
onMouseOver={() => {
interacted();
}}
onClick={() => {
interacted();
}}
onMouseMove={() => {
interacted();
}}
>
{/* TODO: shouldDisplayWebLinks && !isIdle */}
{shouldDiplayWebLinks ? answerLinkCard : null}
{mentorName ? mentorNameCard : null}
<ReactPlayer
style={answerReactPlayerStyling}
className="player-wrapper react-player-wrapper"
data-cy="react-player-answer-video"
controls={controlsEnabled}
url={state.urlToPlay}
pip={false}
muted={false}
Expand Down Expand Up @@ -429,7 +440,6 @@ export default function VideoPlayer(args: VideoPlayerParams): JSX.Element {
}
}}
loop={false}
controls={true}
width="fit-content"
height="fit-content"
progressInterval={100}
Expand Down
39 changes: 39 additions & 0 deletions client/src/hooks/controls-disable-helper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
This software is Copyright ©️ 2020 The University of Southern California. All Rights Reserved.
Permission to use, copy, modify, and distribute this software and its documentation for educational, research and non-profit purposes, without fee, and without a written agreement is hereby granted, provided that the above copyright notice and subject to the full license file found in the root of this software deliverable. Permission to make commercial use of this software may be obtained by contacting: USC Stevens Center for Innovation University of Southern California 1150 S. Olive Street, Suite 2300, Los Angeles, CA 90115, USA Email: [email protected]
The full terms of this copyright and license should always be found in the root directory of this software deliverable as "license.txt" and if these terms are not found with this software, please contact the USC Stevens Center for the full license.
*/
import { useState } from "react";
import useInterval from "use-interval";

export interface ControlsDisableHelper {
enabled: boolean;
interacted: () => void;
}

export function controlsDisableHelper(): ControlsDisableHelper {
const [enabled, setEnabled] = useState(false);
const [lastInteractionTime, setLastInteractionTime] = useState(Date.now());

useInterval(
() => {
if (Date.now() - lastInteractionTime > 3000) {
setEnabled(false);
}
},
enabled ? 1000 : null
);

function interacted() {
setLastInteractionTime(Date.now());
if (!enabled) {
setEnabled(true);
}
}

return {
enabled,
interacted,
};
}

0 comments on commit 3735cdc

Please sign in to comment.