From 43d08e124154c77e1c331d71224e2387515abcd1 Mon Sep 17 00:00:00 2001 From: Ashesh <3626859+Ashesh3@users.noreply.github.com> Date: Thu, 16 Nov 2023 17:15:25 +0530 Subject: [PATCH] Add delay before live feed reconnect (#6655) * Add delay before live feed reconnect * change to 5s * Initital connect trigger --- .../Facility/Consultations/Feed.tsx | 37 +++++++++++-------- .../Facility/Consultations/LiveFeed.tsx | 17 ++++++--- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/src/Components/Facility/Consultations/Feed.tsx b/src/Components/Facility/Consultations/Feed.tsx index ac39be325e9..25b656a0a79 100644 --- a/src/Components/Facility/Consultations/Feed.tsx +++ b/src/Components/Facility/Consultations/Feed.tsx @@ -230,8 +230,28 @@ export const Feed: React.FC = ({ consultationId, facilityId }) => { } }; + const startStreamFeed = () => { + startStream({ + onSuccess: () => setStreamStatus(StreamStatus.Playing), + onError: () => { + setStreamStatus(StreamStatus.Offline); + if (!statusReported) { + triggerGoal("Camera Feed Viewed", { + consultationId, + userId: authUser.id, + result: "error", + }); + setStatusReported(true); + } + }, + }); + }; + useEffect(() => { if (cameraAsset.id) { + setTimeout(() => { + startStreamFeed(); + }, 1000); getPresets({ onSuccess: (resp) => setPresets(resp), onError: (_) => { @@ -251,21 +271,8 @@ export const Feed: React.FC = ({ consultationId, facilityId }) => { setStreamStatus(StreamStatus.Loading); } tId = setTimeout(() => { - startStream({ - onSuccess: () => setStreamStatus(StreamStatus.Playing), - onError: () => { - setStreamStatus(StreamStatus.Offline); - if (!statusReported) { - triggerGoal("Camera Feed Viewed", { - consultationId, - userId: authUser.id, - result: "error", - }); - setStatusReported(true); - } - }, - }); - }, 100); + startStreamFeed(); + }, 5000); } else if (!statusReported) { triggerGoal("Camera Feed Viewed", { consultationId, diff --git a/src/Components/Facility/Consultations/LiveFeed.tsx b/src/Components/Facility/Consultations/LiveFeed.tsx index aba473e958d..cd3f055921e 100644 --- a/src/Components/Facility/Consultations/LiveFeed.tsx +++ b/src/Components/Facility/Consultations/LiveFeed.tsx @@ -177,6 +177,9 @@ const LiveFeed = (props: any) => { useEffect(() => { if (cameraAsset?.hostname) { fetchCameraPresets(); + setTimeout(() => { + startStreamFeed(); + }, 1000); } }, []); @@ -192,6 +195,13 @@ const LiveFeed = (props: any) => { } }, [page.offset, cameraAsset.id, refreshPresetsHash]); + const startStreamFeed = () => { + startStream({ + onSuccess: () => setStreamStatus(StreamStatus.Playing), + onError: () => setStreamStatus(StreamStatus.Offline), + }); + }; + const viewOptions = (page: number) => { return presets ? Object.entries(presets) @@ -207,11 +217,8 @@ const LiveFeed = (props: any) => { if (streamStatus !== StreamStatus.Playing) { setStreamStatus(StreamStatus.Loading); tId = setTimeout(() => { - startStream({ - onSuccess: () => setStreamStatus(StreamStatus.Playing), - onError: () => setStreamStatus(StreamStatus.Offline), - }); - }, 500); + startStreamFeed(); + }, 5000); } return () => {