fix daily API
This commit is contained in:
parent
9ff366c80b
commit
2bdd6a8dba
|
|
@ -91,7 +91,6 @@ export class VideoChatShape extends BaseBoxShapeUtil<IVideoChatShape> {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
Authorization: `Bearer ${DAILY_API_KEY}`,
|
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
name: `canvas-room-${shape.id}`,
|
name: `canvas-room-${shape.id}`,
|
||||||
|
|
@ -115,12 +114,11 @@ export class VideoChatShape extends BaseBoxShapeUtil<IVideoChatShape> {
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const error = await response.json()
|
const errorData = (await response.json()) as { message: string }
|
||||||
throw new Error(`Failed to create room: ${JSON.stringify(error)}`)
|
throw new Error(errorData.message || "Failed to create room")
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await response.json()
|
const { url } = (await response.json()) as { url: string }
|
||||||
const roomUrl = `https://${DAILY_DOMAIN}/${(data as any).name}`
|
|
||||||
|
|
||||||
// Update the shape with the room URL
|
// Update the shape with the room URL
|
||||||
this.editor.updateShape<IVideoChatShape>({
|
this.editor.updateShape<IVideoChatShape>({
|
||||||
|
|
@ -128,7 +126,7 @@ export class VideoChatShape extends BaseBoxShapeUtil<IVideoChatShape> {
|
||||||
type: "VideoChat",
|
type: "VideoChat",
|
||||||
props: {
|
props: {
|
||||||
...shape.props,
|
...shape.props,
|
||||||
roomUrl: roomUrl,
|
roomUrl: url,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
||||||
|
|
@ -127,7 +127,7 @@ const router = AutoRouter<IRequest, [env: Environment, ctx: ExecutionContext]>({
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a room using Daily.co API
|
// 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",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|
@ -139,21 +139,24 @@ const router = AutoRouter<IRequest, [env: Environment, ctx: ExecutionContext]>({
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!response.ok) {
|
const dailyData = await dailyResponse.json()
|
||||||
const error = (await response.json()) as { message: string }
|
|
||||||
return new Response(JSON.stringify({ message: error.message }), {
|
|
||||||
status: 400,
|
|
||||||
headers: { "Content-Type": "application/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(
|
return new Response(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
url: `https://${env.DAILY_DOMAIN}/${
|
url: `https://${env.DAILY_DOMAIN}/${(dailyData as any).name}`,
|
||||||
(data as Record<string, unknown>).name
|
|
||||||
}`,
|
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue