From 5d39baaea8cc32ecaf163e195631fb9da6aa70db Mon Sep 17 00:00:00 2001 From: Jeff Emmett <46964190+Jeff-Emmett@users.noreply.github.com> Date: Sun, 8 Dec 2024 20:11:05 -0500 Subject: [PATCH] fix videochat --- src/shapes/VideoChatShapeUtil.tsx | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/shapes/VideoChatShapeUtil.tsx b/src/shapes/VideoChatShapeUtil.tsx index 926b6bb..213bf7a 100644 --- a/src/shapes/VideoChatShapeUtil.tsx +++ b/src/shapes/VideoChatShapeUtil.tsx @@ -19,6 +19,12 @@ export type IVideoChatShape = TLBaseShape< } > +interface DailyApiError { + error: string + info?: string + message?: string +} + // Simplified component using Daily Prebuilt const VideoChatComponent = ({ roomUrl }: { roomUrl: string }) => { const wrapperRef = useRef(null) @@ -119,10 +125,10 @@ export class VideoChatShape extends BaseBoxShapeUtil { }) if (!response.ok) { - const errorData = (await response.json()) as { message: string } + const errorData = (await response.json()) as DailyApiError - // If room already exists, construct the URL using the room name - if (errorData.message.includes("already exists")) { + // Handle the case where the room already exists + if (response.status === 409) { const url = `https://${import.meta.env.VITE_DAILY_DOMAIN}/${roomName}` this.editor.updateShape({ id: shape.id, @@ -135,7 +141,9 @@ export class VideoChatShape extends BaseBoxShapeUtil { return } - throw new Error(errorData.message || "Failed to create room") + throw new Error( + errorData.message || errorData.info || "Failed to create room", + ) } const { url } = (await response.json()) as { url: string }