Skip to main content
This tutorial builds a browser client with the base JavaScript SDK. By the end, the app can:
  • publish your camera and show the edited video
  • start an edit from an uploaded reference image
  • switch the image or edit type while the edit runs
  • end the edit, and handle an edit that ends on its own or a switch that fails
If this is your first Reactor app, read the Quickstart to learn how a browser client connects. The schema lists every command and field. Add two video elements to your page: <video id="camera"> previews the webcam, and <video id="edited"> shows the model’s output. Add a button with id="switch" if you want to change the look. The snippets use showStatus(), hideStatus(), showMessage(), and offerStartAgain() as placeholders for your own UI. The render() and showError() functions appear later in this tutorial. Get jwtToken from your server as Authentication describes.

Install the SDK

Understand the model

The session works like this:
  1. Your camera is the whole input. The model edits nothing until your camera reaches it. Publish it, and watch camera_forwarding on the snapshot.
  2. session_state shows the current edit. It arrives on connect and on every change. Use it to show progress and decide when controls are available.
  3. Model refusals and edit failures arrive as command_error. Check its code. Use origin to distinguish invalid input from a service failure. Handle SDK connection and upload errors separately. A failed switch can send this error after its reply.

Connect

Mint a token on your server, as Authentication describes, and pass it to connect(). Subscribe to messages and tracks before you connect, so you do not miss the first snapshot.
The model sends its first session_state when the session connects. Wait for it before you send a command. The wasLive check resumes the output track each time an edit enters live, including later edits in the same session. Style the output <video> with object-fit: contain so the whole edited frame stays visible. The output can differ from the camera in size and orientation.

Publish the camera

Publish the camera as soon as the connection is ready. Show it in a second <video> so the user can see what goes in.
This example requests 1280 × 720. The browser may choose different dimensions.

Start an edit

Let the user pick a reference image and an edit type, then start the edit.
The phase moves through starting and warming_up to live. The first edited frame can arrive after the phase becomes live. Drive the loading state from the snapshot:

Switch the look

Call switch_reference with what you want to change. What you omit stays as it is.
The reply, reference_switched, means the switch was sent. The picture changes within a few seconds. There is no later success message, so do not wait for one, and do not resend the switch when nothing seems to change. If the switch fails, a command_error for switch_reference can arrive after the reply. The edit keeps running with the previous look. Handle that error in Surface errors.

End the edit

The phase moves through ending to ended. This tutorial leaves the camera published. A “Start again” button can send start_edit without another camera step. If your app unpublishes the camera between edits, publish it again before the next edit. A session bills while it is ready, including time between edits. Call reactor.disconnect() when the user is done, or after a few idle minutes with no edit. An edit can also end on its own. Handle it in render() from end_reason:
edit_max_seconds and edit_elapsed_seconds on the snapshot let you show how long the edit has left.

Surface errors

The command_error handler in Connect calls showError(). When a switch fails, tell the user and keep the previous look on screen. Use origin and retryable for other model errors:
Handle SDK connection and upload errors where those calls run. They do not arrive as command_error messages.