fix daily API
This commit is contained in:
parent
87f5da0d3a
commit
f8dd874ee3
|
|
@ -91,7 +91,6 @@ export class VideoChatShape extends BaseBoxShapeUtil<IVideoChatShape> {
|
|||
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<IVideoChatShape> {
|
|||
})
|
||||
|
||||
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<IVideoChatShape>({
|
||||
|
|
@ -128,7 +126,7 @@ export class VideoChatShape extends BaseBoxShapeUtil<IVideoChatShape> {
|
|||
type: "VideoChat",
|
||||
props: {
|
||||
...shape.props,
|
||||
roomUrl: roomUrl,
|
||||
roomUrl: url,
|
||||
},
|
||||
})
|
||||
} catch (error) {
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ const router = AutoRouter<IRequest, [env: Environment, ctx: ExecutionContext]>({
|
|||
}
|
||||
|
||||
// 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<IRequest, [env: Environment, ctx: ExecutionContext]>({
|
|||
}),
|
||||
})
|
||||
|
||||
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<string, unknown>).name
|
||||
}`,
|
||||
url: `https://${env.DAILY_DOMAIN}/${(dailyData as any).name}`,
|
||||
}),
|
||||
{
|
||||
headers: { "Content-Type": "application/json" },
|
||||
|
|
|
|||
Loading…
Reference in New Issue