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
The model to connect to, as
owner/name, for example reactor/helios. The Reactor API refuses a
name without the owner.The API URL. Overrides the default URL, including when
local is true.If
true, uses http://localhost:8080 as the default API URL.
Set apiUrl to use a different host or port.How the session generates.
"stepped" asks the runtime for a session that generates one step at a
time, driven by step(). connect() fails with a
GenerationModeMismatchError when the runtime does not start the session that way. See
GenerationMode.The largest data-channel message the client declares and accepts, in bytes, from 256 KiB
(
262144) to 1 GiB (1073741824). A stepped session returns each step’s result in one message.
Raise this for a model that raises its own limit and returns a larger step. The tab holds a whole
message in memory while it arrives.Example
Methods
connect()
Establishes a connection to the Reactor Platform, waits for GPU assignment, and opens a WebRTC connection to the model.
Signature
Token for authentication, or a resolver the SDK calls before each request the session makes. See Authentication.
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().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.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
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
sendCommand()
Sends a command to the model over the WebRTC data channel and waits for the model’s correlated
reply.
Signature
Kept for compatibility.
"runtime" only has a destination for internal SDK commands
(requestSchema); anything else sent with it falls through to a normal application-scope send.MESSAGE_TOO_LARGE.
Example
{ type, data }), bounded by a timeout, or undefined if the
handler acknowledged the command without sending one back. A call site that never awaits the
returned promise is unaffected — it fires and moves on exactly as before.
This method never rejects. A failure — the connection isn’t
"ready", the send itself fails —
is reported through getLastError() and the error
event instead of a thrown/rejected error, so a fire-and-forget call site never produces an
unhandled rejection.undefined. The error event fires before the call
resolves, with operation: "sendCommand", the model’s own code, and a message of the form
command '<name>' failed (<code>): <reason>. For a command whose schema declares a reply,
undefined therefore means it was refused. See
Replies and refusals.
Pass FileRef values from uploadFile() as parameters. A FileRef can sit at the top level of data, or inside an array or object for a parameter that takes several files. See File Uploads for details.
uploadFile()
Uploads a file and returns a FileRef that can be passed into sendCommand().
Signature
Example
Can only be called when the status is
"ready".step()
Runs one step of a session created with generation: "stepped", and resolves with a
StepResult. The step applies state, then commands, then
every frame pushed since the previous step, and then generates. Every part is optional, so step()
on its own runs on the model’s current state.
Signature
Values for the model’s state fields. Each key runs as the model’s
set_<key> command.Commands to run after the state, in order. See
StepCommand.This step’s own frames, by input track name. The SDK pushes them after the frames already
buffered on that track. A bad track or frame anywhere in
media fails the step before the SDK
pushes any of it.Example
pushFrame() buffers one input frame on a track published on this connection, for the next step.
clearStepInputs() drops every frame the buffer holds. The buffer holds one data-channel message’s
worth of frames, and a push past that drops the oldest.
pushEncodedFrame() buffers one EncodedFrame instead: one
H.264 access unit on a sendonly video track. The runtime decodes a track’s encoded frames before
the step runs, so the model reads RGB frames as it does for a raw push. Give one step’s encoded
frames in decode order, and start with a keyframe. A step whose frames do not decode rejects with
StepRefusedError.
A step that ran and that the model reported as failed still resolves, with result.error set. A
refused step rejects and changed nothing. StepRefusedError, StepNotReadyError and
StepCommandFailedError carry entry, the part of the request at fault. StepCommandFailedError
also carries command_code, the code the failing handler raised.
requestClip()
Captures the last durationSeconds of the live session and resolves with a Clip.
Signature
How many seconds back from “now” to capture. Capped server-side (5 minutes by default).
Example
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
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
Filename to save. Pass
null to skip the browser download and just receive the Blob.JWT to authenticate the request, or a resolver the SDK calls before every poll of the clip’s metadata, with the clip’s session. A resolver lets a slow clip finish downloading after the token that started it expires. Required against
https://api.reactor.inc. See Authentication.Called after each segment completes. Use for progress UI.
Example
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
A
MediaStreamTrack from getUserMedia(), getDisplayMedia(), etc. Required in a streamed
session. A stepped session sends no RTP, so it ignores a track passed here and takes its frames
through step() instead.Example
PublishedTrack handle, whose pushFrame()
feeds this track in a stepped session.
unpublishTrack()
Direction: client → model.
Stops publishing a track to the model, freeing the input track for another connection to publish.
Signature
setTrackBitrate()
Direction: client → model.
Sets bitrate bounds on a track you publish. With no bound set, a Chromium-based browser caps a sender above 960x540 at 2500 kbps, even on a fast connection. Raise maxBps to give a 720p or 1080p publish more room.
Signature
The name of a track you already published with
publishTrack().Example
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
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
tracks()
Returns the track declarations negotiated for the current connection.
Signature
TrackCapability.
trackMapping()
Same as tracks(), plus each entry’s negotiated mid — the id used by
getTrackByMid() / getStreamByMid().
Signature
TrackMappingEntry.
pausedTracks()
Returns the names of output (recvonly) tracks currently unsubscribed via
pauseTrack().
Signature
getTrackByName() / getStreamByName()
Resolves a named track to the actual MediaStreamTrack (or the MediaStream containing it).
Signature
getTrackByMid() / getStreamByMid()
Resolves a track by its negotiated SDP media-section id (mid) instead of its declared name — the
id trackReceived and trackMapping()
carry alongside the name.
Signature
getSchema()
Returns the model’s command schema, or undefined before it has been fetched. Fetched
automatically once the connection reaches "ready"; most callers should read this instead of
requesting it directly.
Signature
schemaReceived for the corresponding event.
on()
Registers an event listener.
Signature
Example
off()
Removes an event listener.
Signature
once()
Registers an event listener that fires at most once, then removes itself.
Signature
getStatus()
Returns the current connection status.
Signature
"disconnected", "connecting", "waiting", or "ready".
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
received. Resets to undefined on disconnect, though nothing pushes that transition as an event —
re-check the snapshot after a statusChanged to "disconnected" rather than trusting a value from
before it.
Signature
This is a translated, camelCase
Capabilities — a different
shape from getSessionInfo()?.capabilities below, which is the server’s raw wire format. Prefer
this method (and the capabilitiesReceived event)
over reading capabilities off getSessionInfo().getSessionInfo()
Returns the full session response from the Reactor Platform exactly as the server sent it
(snake_case field names, e.g. session_id, capabilities.protocol_version), or undefined if not
connected.
Signature
getStats()
Returns the current WebRTC connection statistics, or undefined if not connected.
Signature