"use client"; import React, { useState } from "react"; import { useDaily } from "@daily-co/daily-react"; import Setup from "./Setup"; import Story from "./Story"; type State = | "idle" | "connecting" | "connected" | "started" | "finished" | "error"; export default function Call() { const daily = useDaily(); const [state, setState] = useState("idle"); const [room, setRoom] = useState(null); async function start() { setState("connecting"); if (!daily) return; // Create a new room for the story session try { console.log("POSTing to /api") const response = await fetch("/api", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ "createDailyRoom": true }) }); const {dailyRoom, dailyToken} = await response.json(); console.log({dailyRoom, dailyToken}) // Keep a reference to the room url for later setRoom(dailyRoom); // Join the WebRTC session await daily.join({ url: dailyRoom, token: dailyToken, videoSource: false, startAudioOff: true, }); setState("connected"); // Disable local audio, the bot will say hello first daily.setLocalAudio(false); setState("started"); } catch (error) { setState("error"); } } async function leave() { await daily?.leave(); setState("finished"); } if (state === "error") { return (

This demo is currently at capacity. Please try again later.

); } if (state === "started") { return leave()} />; } return start()} />; }