Skip to content

Commit

Permalink
Initital connect trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashesh3 committed Nov 16, 2023
1 parent 001278b commit f571281
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 18 deletions.
35 changes: 21 additions & 14 deletions src/Components/Facility/Consultations/Feed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,28 @@ export const Feed: React.FC<IFeedProps> = ({ 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: (_) => {
Expand All @@ -251,20 +271,7 @@ export const Feed: React.FC<IFeedProps> = ({ 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);
}
},
});
startStreamFeed();
}, 5000);
} else if (!statusReported) {
triggerGoal("Camera Feed Viewed", {
Expand Down
15 changes: 11 additions & 4 deletions src/Components/Facility/Consultations/LiveFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ const LiveFeed = (props: any) => {
useEffect(() => {
if (cameraAsset?.hostname) {
fetchCameraPresets();
setTimeout(() => {
startStreamFeed();
}, 1000);
}
}, []);

Expand All @@ -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)
Expand All @@ -207,10 +217,7 @@ const LiveFeed = (props: any) => {
if (streamStatus !== StreamStatus.Playing) {
setStreamStatus(StreamStatus.Loading);
tId = setTimeout(() => {
startStream({
onSuccess: () => setStreamStatus(StreamStatus.Playing),
onError: () => setStreamStatus(StreamStatus.Offline),
});
startStreamFeed();
}, 5000);
}

Expand Down

0 comments on commit f571281

Please sign in to comment.