Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashesh3 committed Mar 22, 2023
1 parent 4a8b3d9 commit 521fe19
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/Common/LiveKit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,34 @@ import { LiveKitRoom } from "@livekit/react-components";
import "@livekit/react-components/dist/index.css";
import { useEffect, useState } from "react";
import ButtonV2 from "../Components/Common/components/ButtonV2";
import { getLiveKitToken } from "../Redux/actions";
import { Error } from "../Utils/Notifications";
import { useDispatch } from "react-redux";

export const LiveKit = (props: {
sourceUsername: string;
targetUsername: string;
}) => {
const dispatch = useDispatch<any>();
const [status, setStatus] = useState("Disconnected");
const [connect, setConnect] = useState(false);
const [token, setToken] = useState("");

const getToken = () => {
const url = `http://127.0.0.1:8000/api/v1/livekit/get_token?source_username=${props.sourceUsername}&target_username=${props.targetUsername}`;
fetch(url)
.then((res) => res.json())
.then((data) => {
setToken(data.access);
console.log(data);
const getToken = async () => {
const tokenData = await dispatch(
getLiveKitToken({
source: props.sourceUsername,
target: props.targetUsername,
})
);
if (tokenData) {
setToken(tokenData.access);
console.log(tokenData);
} else {
Error({
msg: "Error fetching token",
});
}
};

useEffect(() => {
Expand Down
4 changes: 4 additions & 0 deletions src/Redux/actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -911,3 +911,7 @@ export const HCXActions = {
return fireRequest("hcxMakeClaim", [], { claim });
},
};

export const getLiveKitToken = (params: object) => {
return fireRequest("getLiveKitToken", [], params);
};
5 changes: 5 additions & 0 deletions src/Redux/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,11 @@ const routes: Routes = {
path: "/api/v1/hcx/make_claim/",
method: "POST",
},

getLiveKitToken: {
path: "/api/v1/livekit/get_token/",
method: "POST",
},
};

export default routes;

0 comments on commit 521fe19

Please sign in to comment.