Skip to main content
Reactor is the base class for every model on the platform. It speaks raw JSON over the wire: open a session, send commands by name, and receive generic message events. Typed model SDKs like HeliosModel extend Reactor with named, schema-matched methods over the same wire protocol. See the SDK Reference overview for how the two layers relate, and the Model API Reference for the commands and events a specific model accepts.

Constructor

new Reactor()

Creates a client for the given model. Call connect() afterward to open the session.
Signature
string
required
The name of the model to connect to.
string
default:"https://api.reactor.inc"
The API URL.
boolean
default:"false"
If true, connects to a local runtime at http://localhost:8080. Ignores apiUrl.
Example

Methods

connect()

Establishes a connection to the Reactor Platform, waits for GPU assignment, and opens a WebRTC connection to the model.
Signature
string
Token for authentication. See Authentication.
ConnectOptions
Connection behavior options.
number
default:"6"
Maximum SDP polling attempts before giving up.
boolean
default:"true"
When true, every output (recvonly) track starts streaming as soon as the connection is established. Set to false to leave output tracks paused on connect and start them individually with resumeTrack().
string
Attach to a session that already exists (for example, one created by your backend) instead of creating a new one. The token passed to connect() must be valid for the account that owns the session. A client that adopts a session leaves it running on disconnect; its creator owns the lifecycle.
number
Join the session using a specific WebRTC connection id already registered for it (for example, one your backend created and handed to this client). When omitted, the SDK registers a fresh connection and the server mints the id. connect() rejects if the id is unknown or already closed.

disconnect()

Closes the connection. Safe to call multiple times.
Signature
boolean
default:"false"
If true, the session is kept alive on the server and can be resumed with reconnect(). If false, the session is terminated.

reconnect()

Reconnects to an existing session after a recoverable disconnect. Requires an active sessionId from a previous connection.
Signature
ConnectOptions
Connection behavior options (e.g. maxAttempts).

sendCommand()

Sends a command to the model over the WebRTC data channel.
Signature
string
required
The command name. Must match a command defined on the model.
object
required
The command payload. Shape depends on the command.
Example
Pass FileRef values from uploadFile() as parameters. See File Uploads for details.

uploadFile()

Uploads a file and returns a FileRef that can be passed into sendCommand().
Signature
File | Blob
required
The file to upload.
string
Custom filename. Defaults to file.name for File objects, or "upload" for Blob objects.
Example
Can only be called when the status is "ready".

requestClip()

Captures the last durationSeconds of the live session and resolves with a Clip.
Signature
number
required
How many seconds back from “now” to capture. Capped server-side (5 minutes by default).
Example
Throws a RecordingError on invalid input, timeout, or disconnection. See Recordings.
Can only be called when the status is "ready".

requestRecording()

Captures the entire session, from the start of recording up to “now”, and resolves with a Clip.
Signature
Example
Behaves like requestClip() but covers the full session. See Recordings.
Can only be called when the status is "ready".

downloadClipAsFile()

Downloads a Clip as a single MP4. Triggers a browser download when filename is set, or returns the Blob when filename is null.
Signature
Clip
required
The clip to download.
string | null
default:"\"reactor-clip.mp4\""
Filename to save. Pass null to skip the browser download and just receive the Blob.
string
JWT to authenticate the request. Required against https://api.reactor.inc. See Authentication.
AbortSignal
Cancels both the metadata fetch and the segment downloads.
(info: { fetched: number; total: number; bytes: number }) => void
Called after each segment completes. Use for progress UI.
Example
Reactor does not host clips. The URL on clip.playlistUrl expires after 24 hours, so download the bytes if you need them later. See Recordings.

publishTrack()

Direction: client → model. Publishes a media track to the model. The track name must match a sendonly track declared in the model’s capabilities. Publishing is required and explicit: the model receives nothing on the track until you call this, and connecting alone never starts sending. Only one connection may publish a given input track at a time.
Signature
string
required
Track name. Must match a sendonly track name from the model’s capabilities.
MediaStreamTrack
required
A MediaStreamTrack from getUserMedia(), getDisplayMedia(), etc.
Example

unpublishTrack()

Direction: client → model. Stops publishing a track to the model, freeing the input track for another connection to publish.
Signature
string
required
The name of the track to stop publishing.

pauseTrack()

Direction: model → client. Unsubscribes from an output (recvonly) track so your client stops receiving it. The model keeps emitting frames to the track regardless; this only controls whether they reach you. Pair with autoResumeTracks: false to choose exactly which outputs you receive.
Signature
string
required
The name of the output track to unsubscribe from.

resumeTrack()

Direction: model → client. Subscribes to an output (recvonly) track so your client starts receiving it. This is a subscription, not a request to start generation: the model is already emitting frames, and there is no first-come ownership, so connections subscribe to the same output independently.
Signature
string
required
The name of the output track to subscribe to.

on()

Registers an event listener.
Signature
See Events for all available event types.
Example

off()

Removes an event listener.
Signature

getStatus()

Returns the current connection status.
Signature
Returns "disconnected", "connecting", "waiting", or "ready".

getState()

Returns the current status and last error.
Signature

getSessionId()

Returns the current session ID, or undefined if not connected.
Signature

getLastError()

Returns the most recent error, or undefined if no errors have occurred.
Signature

getCapabilities()

Returns the model’s capabilities (tracks, commands, emission FPS), or undefined if not yet connected.
Signature

getSessionInfo()

Returns the full session response from the Reactor Platform, or undefined if not connected.
Signature

getStats()

Returns the current WebRTC connection statistics, or undefined if not connected.
Signature