From 900833c06c2e3330933a0aabee9c63f8a90da587 Mon Sep 17 00:00:00 2001 From: Jeff Emmett <46964190+Jeff-Emmett@users.noreply.github.com> Date: Thu, 17 Oct 2024 16:21:00 -0400 Subject: [PATCH] Fix live site --- package.json | 4 ++-- src/shapes/VideoChatShapeUtil.tsx | 37 ++++++++++++++++++++++++------- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 6b0e345..f9d59d9 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "preview": "vite preview" }, "keywords": [], - "author": "Orion Reed", + "author": "Jeff Emmett", "license": "ISC", "dependencies": { "@dimforge/rapier2d": "^0.11.2", @@ -55,4 +55,4 @@ "vite-plugin-wasm": "^3.2.2", "wrangler": "^3.72.3" } -} +} \ No newline at end of file diff --git a/src/shapes/VideoChatShapeUtil.tsx b/src/shapes/VideoChatShapeUtil.tsx index 1b3d7b0..edc4941 100644 --- a/src/shapes/VideoChatShapeUtil.tsx +++ b/src/shapes/VideoChatShapeUtil.tsx @@ -27,7 +27,7 @@ export class VideoChatShape extends BaseBoxShapeUtil { return ; } - component(shape: IVideoChatShape) { + component() { const [roomUrl, setRoomUrl] = useState(""); // Added roomUrl state const [isInRoom, setIsInRoom] = useState(false); const [error, setError] = useState(""); @@ -43,14 +43,35 @@ export class VideoChatShape extends BaseBoxShapeUtil { setError(""); setIsLoading(true); try { - const response = await fetch('/api/get-or-create-room', { method: 'GET' }); - const data: { roomUrl?: string; error?: string } = await response.json(); // Explicitly type 'data' - if (data.roomUrl) { - setRoomUrl(data.roomUrl); // Set the room URL - setIsInRoom(true); - } else { - setError(data.error || "Failed to join room. Please try again."); + const apiKey = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJodHRwczovL2FjY291bnRzLmFwcGVhci5pbiIsImF1ZCI6Imh0dHBzOi8vYXBpLmFwcGVhci5pbi92MSIsImV4cCI6OTAwNzE5OTI1NDc0MDk5MSwiaWF0IjoxNzI5MTkzOTE3LCJvcmdhbml6YXRpb25JZCI6MjY2MDk5LCJqdGkiOiI0MzI0MmUxMC1kZmRjLTRhYmEtYjlhOS01ZjcwNTFlMTYwZjAifQ.RaxXpZKYl_dOWyoATQZrzyMR2XRh3fHf02mALQiuTTs'; // Replace with your actual API key + console.log(apiKey) + // Generate a room name based on a default slug or any logic you prefer + const roomNamePrefix = 'default-room'; // You can modify this logic as needed + + const response = await fetch('https://cors-anywhere.herokuapp.com/https://api.whereby.dev/v1/meetings', { + method: 'POST', + headers: { + 'Authorization': `Bearer ${apiKey}`, + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + isLocked: false, + roomNamePrefix: roomNamePrefix, + roomMode: 'normal', + endDate: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000).toISOString(), // 7 days from now + fields: ['hostRoomUrl'], + }), + }); + + if (!response.ok) { + const errorData: { message?: string } = await response.json(); // Explicitly type errorData + console.error('Whereby API error:', errorData); + throw new Error(`Whereby API error: ${errorData.message || 'Unknown error'}`); } + + const data: { roomUrl: string } = await response.json(); // Explicitly type the response + setRoomUrl(data.roomUrl); // Set the room URL + setIsInRoom(true); } catch (e) { console.error("Error joining room:", e); setError("An error occurred. Please try again.");