Reactor Class
The core class for connecting to and interacting with Reactor machines.Constructor
Options
Parameter | Type | Required | Description |
---|---|---|---|
modelName | string | Yes | The name of the Reactor model to connect to |
queueing | boolean | No | When true, users are queued (FIFO) if no machines are available. When false, users are disconnected immediately if no machines are available (default: false) |
insecureApiKey | string | Yes | Your Reactor API key for authentication |
Methods
connect()
Connects to the Reactor coordinator and waits for GPU assignment. Once assigned, establishes connection to the GPU machine.disconnect()
Disconnects from both the coordinator and GPU machine. Safe to call multiple times.sendMessage()
Sends a message to the model. Provided that the message is valid for the selected model, the message will be used by the model.message
- Any JSON-serializable data to send to the machine
ready
state (except in development mode)
Always check that the reactor status is
"ready"
before sending messages to ensure they are processed correctly.publishVideoStream()
Publishes a video stream to the machine. The video stream will be sent to the GPU for processing by video-to-video models.videoStream
- A MediaStream object containing video tracks (typically fromgetUserMedia()
or other video sources)
ready
state (except in development mode)
This method is particularly useful for video-to-video (V2V) models like StreamDiffusionV2 that transform incoming video streams in real-time.
unpublishVideoStream()
Stops publishing the video stream to the machine. This unpublishes the video track that was previously sent.on()
Registers an event listener for Reactor events.event
- The event type to listen forhandler
- Callback function to execute when event fires
off()
Removes an event listener.getStatus()
Returns the current connection status."disconnected"
, "connecting"
, "waiting"
, or "ready"
Example:
getState()
Returns the complete current state including status, error, and waiting information.status
, waitingInfo
, and lastError
properties
Example:
getWaitingInfo()
Returns queue information when inwaiting
state.
undefined
if not waiting
Example:
getLastError()
Returns the most recent error that occurred.undefined
if no errors
Example: