Skip to content

Tutorial: an agent with a camera ​

Feeder is an agent that watches a bird feeder through a camera of its own. In this tutorial you build its view, a page that renders the frames of that camera live and lets the person chat with Feeder and send it a photo taken with their own camera. The finished view also fits a phone screen while the on-screen keyboard is open.

What you will build ​

The finished view runs below. Ask Feeder something and then show it a bird with your camera or with the sample picture.

Live, on a fake world
Open

The fake agent of the example fails your first message on purpose (failNext: true) to show the Retry button.

What you will learn ​

  • Show an agent together with the camera frames that arrive in its data.
  • Follow frames that change ten times a second with onData without re-rendering the whole view.
  • Chat with the agent through messages, send and canSend.
  • Open the camera of the person with askFor and getUserMedia and fall back on a sample picture when there is no camera.
  • Take a photo on a canvas and send it with send({ image, text }).
  • Fit the view to a phone with the keyboard height and the safe areas that webapp reports.
  • Handle what goes wrong: an agent that cannot be reached, a message that is not delivered and an error of the webapp.

Before you start ​

You need to know how a view connects and re-renders on every change (Quick start). Because the view of an agent reads a name, data and messages like the view of a world, you can start here without Tutorial: the view of a world.

Every step has a complete example in React and in plain JavaScript. Each example runs without an account or a network on a fake agent defined in the same file. You can copy the code of any step into your project and continue from there.

The steps ​

  1. Show the agent and its camera: connectToHost with a fake agent and the frames in data.
  2. Follow the pictures of the camera: onData, a frame counter and a pause button.
  3. Talk with the agent: the conversation and a box where the person writes.
  4. Open the person's camera: askFor, getUserMedia and a sample picture.
  5. Take a photo and send it: a canvas and send({ image, text }).
  6. Fit the phone screen: the keyboard and the safe areas.
  7. Finish the view: the status of the agent, delivery and retry, the errors of send and two final touches.

Next steps ​

Start with step 1: Show the agent and its camera.

The UNaIVERSE GUI kit, released under the Apache License 2.0. Copyright 2024-2026 UNaIVERSE S.r.l.