diff --git a/src/shapes/VideoChatShapeUtil.tsx b/src/shapes/VideoChatShapeUtil.tsx index 13b9dbf..a588097 100644 --- a/src/shapes/VideoChatShapeUtil.tsx +++ b/src/shapes/VideoChatShapeUtil.tsx @@ -91,7 +91,6 @@ export class VideoChatShape extends BaseBoxShapeUtil { method: "POST", headers: { "Content-Type": "application/json", - Authorization: `Bearer ${DAILY_API_KEY}`, }, body: JSON.stringify({ name: `canvas-room-${shape.id}`, @@ -115,12 +114,11 @@ export class VideoChatShape extends BaseBoxShapeUtil { }) if (!response.ok) { - const error = await response.json() - throw new Error(`Failed to create room: ${JSON.stringify(error)}`) + const errorData = (await response.json()) as { message: string } + throw new Error(errorData.message || "Failed to create room") } - const data = await response.json() - const roomUrl = `https://${DAILY_DOMAIN}/${(data as any).name}` + const { url } = (await response.json()) as { url: string } // Update the shape with the room URL this.editor.updateShape({ @@ -128,7 +126,7 @@ export class VideoChatShape extends BaseBoxShapeUtil { type: "VideoChat", props: { ...shape.props, - roomUrl: roomUrl, + roomUrl: url, }, }) } catch (error) { diff --git a/worker/worker.ts b/worker/worker.ts index 3d0eeb2..c504905 100644 --- a/worker/worker.ts +++ b/worker/worker.ts @@ -127,7 +127,7 @@ const router = AutoRouter({ } // Create a room using Daily.co API - const response = await fetch("https://api.daily.co/v1/rooms", { + const dailyResponse = await fetch("https://api.daily.co/v1/rooms", { method: "POST", headers: { "Content-Type": "application/json", @@ -139,21 +139,24 @@ const router = AutoRouter({ }), }) - if (!response.ok) { - const error = (await response.json()) as { message: string } - return new Response(JSON.stringify({ message: error.message }), { - status: 400, - headers: { "Content-Type": "application/json" }, - }) - } + const dailyData = await dailyResponse.json() - const data = await response.json() + if (!dailyResponse.ok) { + return new Response( + JSON.stringify({ + message: + (dailyData as any).info || "Failed to create Daily.co room", + }), + { + status: 400, + headers: { "Content-Type": "application/json" }, + }, + ) + } return new Response( JSON.stringify({ - url: `https://${env.DAILY_DOMAIN}/${ - (data as Record).name - }`, + url: `https://${env.DAILY_DOMAIN}/${(dailyData as any).name}`, }), { headers: { "Content-Type": "application/json" },