Skip to content

Commit

Permalink
Resolved merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
shyamprakash123 committed Nov 3, 2023
2 parents c4d8333 + ac405ce commit 65a5cc0
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 19 deletions.
2 changes: 2 additions & 0 deletions src/Common/hooks/useMSEplayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ interface UseMSEMediaPlayerOption {
export interface ICameraAssetState {
id: string;
accessKey: string;
middleware_address: string;
location_middleware: string;
}

export enum StreamStatus {
Expand Down
12 changes: 7 additions & 5 deletions src/Components/Assets/AssetType/ONVIFCamera.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ const ONVIFCamera = ({ assetId, facilityId, asset, onUpdated }: Props) => {
}
}, [facility, facilityId]);

const fallbackMiddleware =
asset?.location_object?.middleware_address || facilityMiddlewareHostname;

const currentMiddleware = middlewareHostname || fallbackMiddleware;

useEffect(() => {
if (asset) {
setAssetType(asset?.asset_class);
Expand Down Expand Up @@ -105,7 +110,7 @@ const ONVIFCamera = ({ assetId, facilityId, asset, onUpdated }: Props) => {
try {
setLoadingAddPreset(true);
const presetData = await axios.get(
`https://${facilityMiddlewareHostname}/status?hostname=${config.hostname}&port=${config.port}&username=${config.username}&password=${config.password}`
`https://${currentMiddleware}/status?hostname=${config.hostname}&port=${config.port}&username=${config.username}&password=${config.password}`
);

const { res } = await request(routes.createAssetBed, {
Expand Down Expand Up @@ -136,9 +141,6 @@ const ONVIFCamera = ({ assetId, facilityId, asset, onUpdated }: Props) => {
};
if (isLoading || loading || !facility) return <Loading />;

const fallbackMiddleware =
asset?.location_object?.middleware_address || facilityMiddlewareHostname;

return (
<div className="space-y-6">
{["DistrictAdmin", "StateAdmin"].includes(authUser.user_type) && (
Expand Down Expand Up @@ -223,7 +225,7 @@ const ONVIFCamera = ({ assetId, facilityId, asset, onUpdated }: Props) => {
addPreset={addPreset}
isLoading={loadingAddPreset}
refreshPresetsHash={refreshPresetsHash}
facilityMiddlewareHostname={facilityMiddlewareHostname}
facilityMiddlewareHostname={currentMiddleware}
/>
) : null}
</div>
Expand Down
20 changes: 12 additions & 8 deletions src/Components/Facility/ConsultationDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -348,14 +348,18 @@ export const ConsultationDetails = (props: any) => {
>
Doctor Connect
</button>
{patientData.last_consultation?.id && isCameraAttached && (
<Link
href={`/facility/${patientData.facility}/patient/${patientData.id}/consultation/${patientData.last_consultation?.id}/feed`}
className="btn btn-primary m-1 w-full hover:text-white"
>
Camera Feed
</Link>
)}
{patientData.last_consultation?.id &&
isCameraAttached &&
["DistrictAdmin", "StateAdmin", "Doctor"].includes(
authUser.user_type
) && (
<Link
href={`/facility/${patientData.facility}/patient/${patientData.id}/consultation/${patientData.last_consultation?.id}/feed`}
className="btn btn-primary m-1 w-full hover:text-white"
>
Camera Feed
</Link>
)}
</>
)}
<Link
Expand Down
27 changes: 21 additions & 6 deletions src/Components/Facility/Consultations/Feed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ export const Feed: React.FC<IFeedProps> = ({ consultationId, facilityId }) => {
const [cameraAsset, setCameraAsset] = useState<ICameraAssetState>({
id: "",
accessKey: "",
middleware_address: "",
location_middleware: "",
});
const [cameraMiddlewareHostname, setCameraMiddlewareHostname] = useState("");
const [facilityMiddlewareHostname, setFacilityMiddlewareHostname] =
useState("");
const [cameraConfig, setCameraConfig] = useState<any>({});
const [isLoading, setIsLoading] = useState(true);
const [bedPresets, setBedPresets] = useState<any>([]);
Expand All @@ -66,13 +69,19 @@ export const Feed: React.FC<IFeedProps> = ({ consultationId, facilityId }) => {
const res = await dispatch(getPermittedFacility(facilityId));

if (res.status === 200 && res.data) {
setCameraMiddlewareHostname(res.data.middleware_address);
setFacilityMiddlewareHostname(res.data.middleware_address);
}
};

if (facilityId) fetchFacility();
}, [dispatch, facilityId]);

const fallbackMiddleware =
cameraAsset.location_middleware || facilityMiddlewareHostname;

const currentMiddleware =
cameraAsset.middleware_address || fallbackMiddleware;

useEffect(() => {
if (cameraState) {
setCameraState({
Expand Down Expand Up @@ -128,6 +137,12 @@ export const Feed: React.FC<IFeedProps> = ({ consultationId, facilityId }) => {
setCameraAsset({
id: bedAssets.data.results[0].asset_object.id,
accessKey: config[2] || "",
middleware_address:
bedAssets.data.results[0].asset_object?.meta
?.middleware_hostname,
location_middleware:
bedAssets.data.results[0].asset_object.location_object
?.middleware_address,
});
setCameraConfig(bedAssets.data.results[0].meta);
setCameraState({
Expand Down Expand Up @@ -168,8 +183,8 @@ export const Feed: React.FC<IFeedProps> = ({ consultationId, facilityId }) => {
);

const url = !isIOS
? `wss://${cameraMiddlewareHostname}/stream/${cameraAsset?.accessKey}/channel/0/mse?uuid=${cameraAsset?.accessKey}&channel=0`
: `https://${cameraMiddlewareHostname}/stream/${cameraAsset?.accessKey}/channel/0/hls/live/index.m3u8?uuid=${cameraAsset?.accessKey}&channel=0`;
? `wss://${currentMiddleware}/stream/${cameraAsset?.accessKey}/channel/0/mse?uuid=${cameraAsset?.accessKey}&channel=0`
: `https://${currentMiddleware}/stream/${cameraAsset?.accessKey}/channel/0/hls/live/index.m3u8?uuid=${cameraAsset?.accessKey}&channel=0`;

const {
startStream,
Expand All @@ -180,7 +195,7 @@ export const Feed: React.FC<IFeedProps> = ({ consultationId, facilityId }) => {
: // eslint-disable-next-line react-hooks/rules-of-hooks
useMSEMediaPlayer({
config: {
middlewareHostname: cameraMiddlewareHostname,
middlewareHostname: currentMiddleware,
...cameraAsset,
},
url,
Expand Down Expand Up @@ -227,7 +242,7 @@ export const Feed: React.FC<IFeedProps> = ({ consultationId, facilityId }) => {
});
getBedPresets(cameraAsset);
}
}, [cameraAsset, cameraMiddlewareHostname]);
}, [cameraAsset, currentMiddleware]);

useEffect(() => {
let tId: any;
Expand Down

0 comments on commit 65a5cc0

Please sign in to comment.