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

Feat/new api #134

Merged
merged 6 commits into from
May 3, 2024
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
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Backend url
VITE_BACKEND_URL=https://intercom-manager.prod.eyevinn.technology/
VITE_BACKEND_API_VERSION=api/v1/
1 change: 1 addition & 0 deletions .env.local.sample
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Example .env.local file
VITE_BACKEND_URL=https://intercom-manager.dev.eyevinn.technology/
VITE_BACKEND_API_VERSION=api/v1/
1 change: 1 addition & 0 deletions .env.staging
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Example .env.local file
VITE_BACKEND_URL=https://intercom-manager.dev.eyevinn.technology/
VITE_BACKEND_API_VERSION=api/v1/
68 changes: 34 additions & 34 deletions src/api/api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { handleFetchRequest } from "./handle-fetch-request.ts";

const API_VERSION = import.meta.env.VITE_BACKEND_API_VERSION ?? "api/v1/";
const API_URL =
import.meta.env.VITE_BACKEND_URL ?? `${window.location.origin}/api/v1/`;
`${import.meta.env.VITE_BACKEND_URL}${API_VERSION}` ??
`${window.location.origin}/${API_VERSION}`;

type TCreateProductionOptions = {
name: string;
Expand All @@ -10,21 +12,21 @@ type TCreateProductionOptions = {

type TParticipant = {
name: string;
sessionid: string;
endpointid: string;
sessionId: string;
endpointId: string;
isActive: boolean;
};

type TLine = {
name: string;
id: string;
smbconferenceid: string;
smbConferenceId: string;
participants: TParticipant[];
};

type TBasicProductionResponse = {
name: string;
productionid: string;
productionId: string;
};

type TFetchProductionResponse = TBasicProductionResponse & {
Expand All @@ -41,21 +43,17 @@ type TOfferAudioSessionOptions = {

type TOfferAudioSessionResponse = {
sdp: string;
sessionid: string;
sessionId: string;
};

type TPatchAudioSessionOptions = {
productionId: number;
lineId: number;
sessionId: string;
sdpAnswer: string;
};

type TPatchAudioSessionResponse = null;

type TDeleteAudioSessionOptions = {
productionId: number;
lineId: number;
sessionId: string;
};

Expand All @@ -79,23 +77,23 @@ export const API = {
),
listProductions: (): Promise<TListProductionsResponse> =>
handleFetchRequest<TListProductionsResponse>(
fetch(`${API_URL}productions/`, { method: "GET" })
fetch(`${API_URL}production/`, { method: "GET" })
),
fetchProduction: (id: number): Promise<TFetchProductionResponse> =>
handleFetchRequest<TFetchProductionResponse>(
fetch(`${API_URL}productions/${id}`, { method: "GET" })
fetch(`${API_URL}production/${id}`, { method: "GET" })
),
deleteProduction: (id: number): Promise<string> =>
handleFetchRequest<string>(
fetch(`${API_URL}productions/${id}`, { method: "DELETE" })
fetch(`${API_URL}production/${id}`, { method: "DELETE" })
),
listProductionLines: (id: number) =>
handleFetchRequest<TLine[]>(
fetch(`${API_URL}productions/${id}/lines`, { method: "GET" })
fetch(`${API_URL}production/${id}/line`, { method: "GET" })
),
fetchProductionLine: (productionId: number, lineId: number): Promise<TLine> =>
handleFetchRequest<TLine>(
fetch(`${API_URL}productions/${productionId}/lines/${lineId}`, {
fetch(`${API_URL}production/${productionId}/line/${lineId}`, {
method: "GET",
})
),
Expand All @@ -105,36 +103,38 @@ export const API = {
username,
}: TOfferAudioSessionOptions): Promise<TOfferAudioSessionResponse> =>
handleFetchRequest<TOfferAudioSessionResponse>(
fetch(
`${API_URL}productions/${productionId}/lines/${lineId}/users/${username}`,
{ method: "POST" }
)
fetch(`${API_URL}session/`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
productionId,
lineId,
username,
}),
})
),
patchAudioSession: ({
productionId,
lineId,
sessionId,
sdpAnswer,
}: TPatchAudioSessionOptions): Promise<TPatchAudioSessionResponse> =>
handleFetchRequest<TPatchAudioSessionResponse>(
fetch(
`${API_URL}productions/${productionId}/lines/${lineId}/session/${sessionId}`,
{
method: "PATCH",
body: sdpAnswer,
}
)
fetch(`${API_URL}session/${sessionId}`, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
sdpAnswer,
}),
})
),
deleteAudioSession: ({
productionId,
lineId,
sessionId,
}: TDeleteAudioSessionOptions): Promise<string> =>
handleFetchRequest<string>(
fetch(
`${API_URL}productions/${productionId}/lines/${lineId}/session/${sessionId}`,
{ method: "DELETE" }
)
fetch(`${API_URL}session/${sessionId}`, { method: "DELETE" })
),
heartbeat: ({ sessionId }: THeartbeatOptions): Promise<string> =>
handleFetchRequest<string>(
Expand Down
2 changes: 1 addition & 1 deletion src/components/landing-page/create-production.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export const CreateProduction = () => {
lines: [{ name: value.defaultLine }, ...value.lines],
})
.then((v) => {
setCreatedProductionId(v.productionid);
setCreatedProductionId(v.productionId);
setLoading(false);
})
.catch((error) => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/landing-page/productions-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ export const ProductionsList = () => {
{error && <LocalError error={error} />}
{!error &&
productions.map((p) => (
<ProductionItem key={p.productionid}>
<ProductionItem key={p.productionId}>
<ProductionName>{p.name}</ProductionName>
<ProductionId>{p.productionid}</ProductionId>
<ProductionId>{p.productionId}</ProductionId>
</ProductionItem>
))}
</ProductionListContainer>
Expand Down
2 changes: 1 addition & 1 deletion src/components/production-line/production-line.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ export const ProductionLine: FC = () => {
<ListWrapper>
{line && (
<UserList
sessionid={sessionId}
sessionId={sessionId}
participants={line.participants}
dominantSpeaker={dominantSpeaker}
audioLevelAboveThreshold={audioLevelAboveThreshold}
Expand Down
6 changes: 3 additions & 3 deletions src/components/production-line/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export type TJoinProductionOptions = {

export type TParticipant = {
name: string;
sessionid: string;
endpointid: string;
sessionId: string;
endpointId: string;
isActive: boolean;
};

Expand All @@ -23,7 +23,7 @@ export type TLine = {

export type TBasicProduction = {
name: string;
productionid: string;
productionId: string;
};

export type TProduction = TBasicProduction & {
Expand Down
7 changes: 1 addition & 6 deletions src/components/production-line/use-establish-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const useEstablishSession = ({
.then((response) => {
if (aborted) return;

setSessionId(response.sessionid);
setSessionId(response.sessionId);
setSdpOffer(response.sdp);
})
.catch((e) => {
Expand All @@ -57,14 +57,9 @@ export const useEstablishSession = ({
() => () => {
if (!joinProductionOptions) return;

const productionId = parseInt(joinProductionOptions.productionId, 10);
const lineId = parseInt(joinProductionOptions.lineId, 10);

if (sessionId) {
API.deleteAudioSession({
sessionId,
productionId,
lineId,
}).catch(console.error);
}
},
Expand Down
2 changes: 0 additions & 2 deletions src/components/production-line/use-rtc-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ const establishConnection = ({
console.log("sdp PATCH sent");

await API.patchAudioSession({
productionId: parseInt(joinProductionOptions.productionId, 10),
lineId: parseInt(joinProductionOptions.lineId, 10),
sessionId,
sdpAnswer: sdpAnswer.sdp,
});
Expand Down
8 changes: 4 additions & 4 deletions src/components/production-line/user-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ const IconWrapper = styled.div`

type TUserListOptions = {
participants: TParticipant[];
sessionid: string | null;
sessionId: string | null;
dominantSpeaker: string | null;
audioLevelAboveThreshold: boolean;
};

export const UserList = ({
participants,
sessionid,
sessionId,
dominantSpeaker,
audioLevelAboveThreshold,
}: TUserListOptions) => {
Expand All @@ -99,10 +99,10 @@ export const UserList = ({
<DisplayContainerHeader>Participants</DisplayContainerHeader>
<ListWrapper>
{participants.map((p) => (
<User key={p.sessionid} isYou={p.sessionid === sessionid}>
<User key={p.sessionId} isYou={p.sessionId === sessionId}>
<IsTalkingIndicator
isTalking={
audioLevelAboveThreshold && p.endpointid === dominantSpeaker
audioLevelAboveThreshold && p.endpointId === dominantSpeaker
}
>
<OnlineIndicator isActive={p.isActive}>
Expand Down
Loading