Fix live site

This commit is contained in:
Jeff Emmett 2024-10-17 16:21:00 -04:00
parent 700875434f
commit 900833c06c
2 changed files with 31 additions and 10 deletions

View File

@ -12,7 +12,7 @@
"preview": "vite preview"
},
"keywords": [],
"author": "Orion Reed",
"author": "Jeff Emmett",
"license": "ISC",
"dependencies": {
"@dimforge/rapier2d": "^0.11.2",

View File

@ -27,7 +27,7 @@ export class VideoChatShape extends BaseBoxShapeUtil<IVideoChatShape> {
return <rect x={0} y={0} width={shape.props.w} height={shape.props.h} />;
}
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<IVideoChatShape> {
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) {
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);
} else {
setError(data.error || "Failed to join room. Please try again.");
}
} catch (e) {
console.error("Error joining room:", e);
setError("An error occurred. Please try again.");