import React from "react"; import HappyrobotClient from "@happyrobot-ai/happyrobot-js"; type State = "init" | "connecting" | "waiting" | "ready" | "error"; function App() { // Create happyrobot client const [client] = React.useState(() => new HappyrobotClient("")); // Create state const [state, setState] = React.useState("init"); const start = () => { // Start the call for the given assistant id client.start(""); setState("connecting"); // Subscribe to event listeners client.on("call-started", () => { setState("waiting"); }); client.on("call-ended", () => { setState("init"); }); client.on("participant-joined", () => { setState("ready"); }); client.on("participant-left", () => { // When the user leaves, stop the call client.stop(); }); client.on("error", (e) => { console.error("Error", e); setState("error"); }); }; const stop = () => { client.stop(); }; if (state == "init") { return (
); } if (state === "connecting") { return (

Preparing Web Call...

); } if (state === "waiting") { return (

Waiting for the assistant...

); } if (state === "error") { return (

There was an error...

); } return (
); } export default App;