Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track camera feed views and display offline status #6408

Merged
merged 2 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Common/hooks/useMSEplayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ export const useMSEMediaPlayer = ({
readPacket(event.data);
}
};
ws.onerror = function (event) {
onError && onError(event);
};
},
false
);
Expand Down
30 changes: 26 additions & 4 deletions src/Components/Facility/Consultations/Feed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import useKeyboardShortcut from "use-keyboard-shortcut";
import useFullscreen from "../../../Common/hooks/useFullscreen.js";
import { triggerGoal } from "../../../Integrations/Plausible.js";
import useAuthUser from "../../../Common/hooks/useAuthUser.js";
import Spinner from "../../Common/Spinner.js";

interface IFeedProps {
facilityId: string;
Expand All @@ -57,6 +58,7 @@ export const Feed: React.FC<IFeedProps> = ({ consultationId, facilityId }) => {
const [cameraState, setCameraState] = useState<PTZState | null>(null);
const [isFullscreen, setFullscreen] = useFullscreen();
const [videoStartTime, setVideoStartTime] = useState<Date | null>(null);
const [statusReported, setStatusReported] = useState(false);
const authUser = useAuthUser();

useEffect(() => {
Expand Down Expand Up @@ -232,13 +234,32 @@ export const Feed: React.FC<IFeedProps> = ({ consultationId, facilityId }) => {
useEffect(() => {
let tId: any;
if (streamStatus !== StreamStatus.Playing) {
setStreamStatus(StreamStatus.Loading);
if (streamStatus !== StreamStatus.Offline) {
setStreamStatus(StreamStatus.Loading);
}
tId = setTimeout(() => {
startStream({
onSuccess: () => setStreamStatus(StreamStatus.Playing),
onError: () => setStreamStatus(StreamStatus.Offline),
onError: () => {
setStreamStatus(StreamStatus.Offline);
if (!statusReported) {
triggerGoal("Camera Feed Viewed", {
consultationId,
userId: authUser.id,
result: "error",
});
setStatusReported(true);
}
},
});
}, 100);
} else if (!statusReported) {
triggerGoal("Camera Feed Viewed", {
consultationId,
userId: authUser.id,
result: "success",
});
setStatusReported(true);
}

return () => {
Expand Down Expand Up @@ -505,8 +526,9 @@ export const Feed: React.FC<IFeedProps> = ({ consultationId, facilityId }) => {
STATUS: <span className="text-red-600">OFFLINE</span>
</p>
<p className="font-semibold ">Feed is currently not live.</p>
<p className="font-semibold ">
Click refresh button to try again.
<p className="font-semibold ">Trying to connect... </p>
<p className="mt-2 flex justify-center">
<Spinner circle={{ fill: "none" }} />
</p>
</div>
)}
Expand Down
Loading