Skip to content

Commit

Permalink
Added cam auto reset in asset config page (#6375)
Browse files Browse the repository at this point in the history
  • Loading branch information
thtauhid authored Oct 4, 2023
1 parent f8e9647 commit a4a4671
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/Components/Facility/Consultations/LiveFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const LiveFeed = (props: any) => {
const [streamStatus, setStreamStatus] = useState<StreamStatus>(
StreamStatus.Offline
);
const [videoStartTime, setVideoStartTime] = useState<Date | null>(null);
const [bed, setBed] = useState<BedModel>({});
const [preset, setNewPreset] = useState<string>("");
const [loading, setLoading] = useState<string | undefined>();
Expand Down Expand Up @@ -100,6 +101,16 @@ const LiveFeed = (props: any) => {
},
});

const calculateVideoLiveDelay = () => {
const video = liveFeedPlayerRef.current as HTMLVideoElement;
if (!video || !videoStartTime) return 0;

const timeDifference =
(new Date().getTime() - videoStartTime.getTime()) / 1000;

return timeDifference - video.currentTime;
};

const getBedPresets = async (id: any) => {
const bedAssets = await dispatch(
listAssetBeds({
Expand Down Expand Up @@ -223,6 +234,7 @@ const LiveFeed = (props: any) => {
},
reset: () => {
setStreamStatus(StreamStatus.Loading);
setVideoStartTime(null);
startStream({
onSuccess: () => setStreamStatus(StreamStatus.Playing),
onError: () => setStreamStatus(StreamStatus.Offline),
Expand Down Expand Up @@ -344,8 +356,25 @@ const LiveFeed = (props: any) => {
playsInline
className="z-10 h-full w-full"
ref={liveFeedPlayerRef}
onPlay={() => {
setVideoStartTime(() => new Date());
}}
onWaiting={() => {
const delay = calculateVideoLiveDelay();
if (delay > 5) {
setStreamStatus(StreamStatus.Loading);
}
}}
></video>

{streamStatus === StreamStatus.Playing &&
calculateVideoLiveDelay() > 3 && (
<div className="absolute left-8 top-12 z-10 flex items-center gap-2 rounded-3xl bg-red-400 px-3 py-1.5 text-xs font-semibold text-gray-100">
<CareIcon className="care-l-wifi-slash h-4 w-4" />
<span>Slow Network Detected</span>
</div>
)}

{loading && (
<div className="absolute bottom-0 right-0 rounded-tl bg-white/75 p-4">
<div className="flex items-center gap-2">
Expand Down

0 comments on commit a4a4671

Please sign in to comment.