-
Notifications
You must be signed in to change notification settings - Fork 475
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added livekit setup for doctor connect
- Loading branch information
1 parent
5534762
commit 1159011
Showing
11 changed files
with
675 additions
and
1,230 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,9 @@ | |
"@googlemaps/react-wrapper": "^1.1.35", | ||
"@googlemaps/typescript-guards": "^2.0.3", | ||
"@headlessui/react": "^2.1.2", | ||
"@livekit/components-react": "^0.4.1", | ||
"@livekit/react-components": "^1.1.0", | ||
"@loadable/component": "^5.16.4", | ||
"@pnotify/core": "^5.2.0", | ||
"@pnotify/mobile": "^5.2.0", | ||
"@sentry/browser": "^8.29.0", | ||
|
@@ -64,6 +67,7 @@ | |
"hi-profiles": "^1.0.6", | ||
"i18next": "^23.11.4", | ||
"i18next-browser-languagedetector": "^7.2.1", | ||
"livekit-client": "^1.6.8", | ||
"lodash-es": "^4.17.21", | ||
"postcss-loader": "^7.3.3", | ||
"qrcode.react": "^3.1.0", | ||
|
@@ -94,6 +98,7 @@ | |
"@types/cypress": "^1.1.3", | ||
"@types/events": "^3.0.3", | ||
"@types/google.maps": "^3.55.8", | ||
"@types/loadable__component": "^5.13.9", | ||
"@types/lodash-es": "^4.17.12", | ||
"@types/qrcode.react": "^1.0.5", | ||
"@types/react": "18.3.2", | ||
|
@@ -155,4 +160,4 @@ | |
"node": ">=20.12.0" | ||
}, | ||
"packageManager": "[email protected]" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { useState } from "react"; | ||
|
||
export default function useMergeState(initialState: any) { | ||
const [state, setState] = useState(initialState); | ||
|
||
const setMergedState = (newState: any) => | ||
setState((prevState: any) => Object.assign({}, prevState, newState)); | ||
|
||
return [state, setMergedState]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import "@livekit/react-components/dist/index.css"; | ||
|
||
import { useEffect, useState } from "react"; | ||
|
||
import ButtonV2 from "./components/ButtonV2"; | ||
import { LiveKitRoom } from "@livekit/react-components"; | ||
import request from "../../Utils/request/request"; | ||
import routes from "../../Redux/api"; | ||
|
||
export const Livekit = (props: { | ||
sourceUsername: string; | ||
targetUsername: string; | ||
}) => { | ||
const [status, setStatus] = useState("Disconnected"); | ||
const [connect, setConnect] = useState(false); | ||
const [token, setToken] = useState(""); | ||
|
||
const getToken = async () => { | ||
const { res, data } = await request(routes.livekit.create_room, { | ||
body: { | ||
source: props.sourceUsername, | ||
target: props.targetUsername, | ||
}, | ||
}); | ||
|
||
if (res?.status === 201 && data) { | ||
setToken(data.access); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
getToken(); | ||
}, []); | ||
|
||
return ( | ||
<div className="roomContainer"> | ||
<p className="text-md">Welcome {props.sourceUsername} !</p> | ||
<p className="font-semibold text-md my-4"> | ||
Status:{" "} | ||
<span | ||
className={status === "Connected" ? "text-green-600" : "text-red-500"} | ||
> | ||
{status} | ||
</span> | ||
</p> | ||
<ButtonV2 | ||
onClick={() => { | ||
setConnect(!connect); | ||
if (status != "Connected") { | ||
setStatus("Connecting..."); | ||
} else { | ||
setStatus("Disconnected"); | ||
} | ||
}} | ||
variant={status === "Connected" ? "danger" : "primary"} | ||
> | ||
{status === "Connected" ? "Disconnect" : "Connect"} | ||
</ButtonV2> | ||
{connect && token && ( | ||
<LiveKitRoom | ||
token={token} | ||
url="wss://care-22km03y2.livekit.cloud" | ||
onConnected={() => { | ||
setStatus("Connected"); | ||
}} | ||
onLeave={() => { | ||
setStatus("Disconnected"); | ||
setConnect(false); | ||
}} | ||
/> | ||
)} | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { Livekit } from "../Common/Livekit"; | ||
import loadable from "@loadable/component"; | ||
import routes from "../../Redux/api"; | ||
import useAuthUser from "../../Common/hooks/useAuthUser"; | ||
import useQuery from "../../Utils/request/useQuery"; | ||
import { useState } from "react"; | ||
|
||
const PageTitle = loadable(() => import("../Common/PageTitle")); | ||
|
||
const DoctorLiveConnect = (props: { facilityId: string; userId: string }) => { | ||
const { facilityId, userId } = props; | ||
const [user, setUser] = useState<any>(null); | ||
const currentUser = useAuthUser(); | ||
|
||
useQuery(routes.getFacilityUsers, { | ||
pathParams: { facility_id: facilityId }, | ||
query: { limit: 50 }, | ||
onResponse: (res) => { | ||
setUser(res.data?.results.find((user: any) => user.id == userId)); | ||
}, | ||
}); | ||
|
||
return ( | ||
user && ( | ||
<div className="px-2 pb-2"> | ||
<PageTitle title="Doctor Live Connect" /> | ||
<div className="flex flex-col xl:flex-row gap-8"> | ||
<div className="bg-white rounded-lg md:rounded-xl w-full flex service-panel"> | ||
<div className="w-full md:p-8 md:pt-6 p-6 pt-4 flex flex-col justify-between gap-6"> | ||
<div> | ||
<div className="flex flex-wrap items-center gap-2 justify-between w-full"> | ||
<div className="flex items-center gap-3"> | ||
<span className="text-2xl md:text-3xl font-bold break-words"> | ||
Connect to Doctor {user.first_name} {user.last_name} | ||
</span> | ||
</div> | ||
</div> | ||
<div className="mt-8"> | ||
<Livekit | ||
sourceUsername={currentUser.username} | ||
targetUsername={ | ||
user.username === currentUser.username | ||
? "devdistrictadmin" | ||
: user.username | ||
} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
); | ||
}; | ||
|
||
export default DoctorLiveConnect; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.