diff --git a/.env b/.env index c4631bc8..da5be75a 100644 --- a/.env +++ b/.env @@ -1,2 +1,3 @@ # Backend url VITE_BACKEND_URL=https://intercom-manager.prod.eyevinn.technology/ +VITE_BACKEND_API_VERSION=api/v1/ diff --git a/.env.local.sample b/.env.local.sample index a50103bb..865463e8 100644 --- a/.env.local.sample +++ b/.env.local.sample @@ -1,2 +1,3 @@ # Example .env.local file VITE_BACKEND_URL=https://intercom-manager.dev.eyevinn.technology/ +VITE_BACKEND_API_VERSION=api/v1/ diff --git a/.env.staging b/.env.staging index a50103bb..865463e8 100644 --- a/.env.staging +++ b/.env.staging @@ -1,2 +1,3 @@ # Example .env.local file VITE_BACKEND_URL=https://intercom-manager.dev.eyevinn.technology/ +VITE_BACKEND_API_VERSION=api/v1/ diff --git a/src/api/api.ts b/src/api/api.ts index d3314075..74f2177a 100644 --- a/src/api/api.ts +++ b/src/api/api.ts @@ -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; @@ -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 & { @@ -41,12 +43,10 @@ type TOfferAudioSessionOptions = { type TOfferAudioSessionResponse = { sdp: string; - sessionid: string; + sessionId: string; }; type TPatchAudioSessionOptions = { - productionId: number; - lineId: number; sessionId: string; sdpAnswer: string; }; @@ -54,8 +54,6 @@ type TPatchAudioSessionOptions = { type TPatchAudioSessionResponse = null; type TDeleteAudioSessionOptions = { - productionId: number; - lineId: number; sessionId: string; }; @@ -79,23 +77,23 @@ export const API = { ), listProductions: (): Promise => handleFetchRequest( - fetch(`${API_URL}productions/`, { method: "GET" }) + fetch(`${API_URL}production/`, { method: "GET" }) ), fetchProduction: (id: number): Promise => handleFetchRequest( - fetch(`${API_URL}productions/${id}`, { method: "GET" }) + fetch(`${API_URL}production/${id}`, { method: "GET" }) ), deleteProduction: (id: number): Promise => handleFetchRequest( - fetch(`${API_URL}productions/${id}`, { method: "DELETE" }) + fetch(`${API_URL}production/${id}`, { method: "DELETE" }) ), listProductionLines: (id: number) => handleFetchRequest( - fetch(`${API_URL}productions/${id}/lines`, { method: "GET" }) + fetch(`${API_URL}production/${id}/line`, { method: "GET" }) ), fetchProductionLine: (productionId: number, lineId: number): Promise => handleFetchRequest( - fetch(`${API_URL}productions/${productionId}/lines/${lineId}`, { + fetch(`${API_URL}production/${productionId}/line/${lineId}`, { method: "GET", }) ), @@ -105,36 +103,38 @@ export const API = { username, }: TOfferAudioSessionOptions): Promise => handleFetchRequest( - 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 => handleFetchRequest( - 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 => handleFetchRequest( - fetch( - `${API_URL}productions/${productionId}/lines/${lineId}/session/${sessionId}`, - { method: "DELETE" } - ) + fetch(`${API_URL}session/${sessionId}`, { method: "DELETE" }) ), heartbeat: ({ sessionId }: THeartbeatOptions): Promise => handleFetchRequest( diff --git a/src/components/landing-page/create-production.tsx b/src/components/landing-page/create-production.tsx index 0583cd96..7f1917cf 100644 --- a/src/components/landing-page/create-production.tsx +++ b/src/components/landing-page/create-production.tsx @@ -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) => { diff --git a/src/components/landing-page/productions-list.tsx b/src/components/landing-page/productions-list.tsx index 0cadcbe4..4def1446 100644 --- a/src/components/landing-page/productions-list.tsx +++ b/src/components/landing-page/productions-list.tsx @@ -115,9 +115,9 @@ export const ProductionsList = () => { {error && } {!error && productions.map((p) => ( - + {p.name} - {p.productionid} + {p.productionId} ))} diff --git a/src/components/production-line/production-line.tsx b/src/components/production-line/production-line.tsx index c0735d3c..868be3ce 100644 --- a/src/components/production-line/production-line.tsx +++ b/src/components/production-line/production-line.tsx @@ -308,7 +308,7 @@ export const ProductionLine: FC = () => { {line && ( { if (aborted) return; - setSessionId(response.sessionid); + setSessionId(response.sessionId); setSdpOffer(response.sdp); }) .catch((e) => { @@ -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); } }, diff --git a/src/components/production-line/use-rtc-connection.ts b/src/components/production-line/use-rtc-connection.ts index 051fe042..8b2003ac 100644 --- a/src/components/production-line/use-rtc-connection.ts +++ b/src/components/production-line/use-rtc-connection.ts @@ -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, }); diff --git a/src/components/production-line/user-list.tsx b/src/components/production-line/user-list.tsx index 5a7de4c3..08a44bda 100644 --- a/src/components/production-line/user-list.tsx +++ b/src/components/production-line/user-list.tsx @@ -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) => { @@ -99,10 +99,10 @@ export const UserList = ({ Participants {participants.map((p) => ( - +