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. Overrides the default URL, including when
local is true.boolean
default:"false"
If
true, uses http://localhost:8080 as the default API URL.
Set apiUrl to use a different host or port.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 and waits for the model’s correlated
reply.
Signature
string
required
The command name. Must match a command defined on the model.
object
The command payload. Shape depends on the command.
"application" | "runtime"
default:"\"application\""
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.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
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
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
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
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.
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
string
required
The name of a track you already published with
publishTrack().number
Ceiling in bits per second. Omit it to keep the browser default.
number
Floor in bits per second. Chromium honors this one. Other browsers ignore it.
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
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.
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
string
required
The track name, as declared in the model’s capabilities.
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
string
required
The track’s negotiated
mid.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