From 3ac37630dfc9293a7139ce4d516fca345b93bf0c Mon Sep 17 00:00:00 2001 From: Jeff Emmett <46964190+Jeff-Emmett@users.noreply.github.com> Date: Sun, 8 Dec 2024 19:46:29 -0500 Subject: [PATCH] fix videochat bugs --- src/shapes/VideoChatShapeUtil.tsx | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/shapes/VideoChatShapeUtil.tsx b/src/shapes/VideoChatShapeUtil.tsx index 6c971fc..7666c21 100644 --- a/src/shapes/VideoChatShapeUtil.tsx +++ b/src/shapes/VideoChatShapeUtil.tsx @@ -82,6 +82,8 @@ export class VideoChatShape extends BaseBoxShapeUtil { } try { + const roomName = `canvas-room-${shape.id.replace(/[^A-Za-z0-9-_]/g, "-")}` + // Create room using the worker endpoint const response = await fetch(`${WORKER_URL}/daily/rooms`, { method: "POST", @@ -89,7 +91,7 @@ export class VideoChatShape extends BaseBoxShapeUtil { "Content-Type": "application/json", }, body: JSON.stringify({ - name: `canvas-room-${shape.id.replace(/[^A-Za-z0-9-_]/g, "-")}`, + name: roomName, privacy: "public", properties: { enable_chat: true, @@ -111,6 +113,21 @@ export class VideoChatShape extends BaseBoxShapeUtil { if (!response.ok) { const errorData = (await response.json()) as { message: string } + + // If room already exists, construct the URL using the room name + if (errorData.message.includes("already exists")) { + const url = `https://${import.meta.env.VITE_DAILY_DOMAIN}/${roomName}` + this.editor.updateShape({ + id: shape.id, + type: "VideoChat", + props: { + ...shape.props, + roomUrl: url, + }, + }) + return + } + throw new Error(errorData.message || "Failed to create room") }