Skip to main content
Everything here is exported by import Reactor.

ReactorStatus

Definition
Four states, in the order they happen. Read the current one with reactor.status, or subscribe with onStatus(_:). An unrecognised status the library reports is read as .disconnected rather than trapping: a client that cannot understand what the library is telling it should behave as though it has no session, rather than assume the most capable state it knows.
Several calls require .ready and throw ReactorError.invalidState otherwise — uploadFile(at:), publish(), pushFrame.

ReactorError

Thrown when an operation fails, and the same payload onError delivers — one struct either way, so a failure caught from a call and the event describing it can never disagree about what happened.
Definition
Code
A stable, matchable code — see the table below, or a code the platform sent for a request it rejected. Never empty.
String
The human-readable explanation, and the only field guaranteed to be worth printing.
Bool
Whether the same call could succeed later. true is about the moment — a timeout, a 5xx, a transport that dropped — so waiting or reconnecting is worth something. false is about the request itself. Decided by the core and carried in the payload, never recomputed here.
Int?
The HTTP status, when the failure came from one.
String?
Which call failed, e.g. "connect", "send_command". nil for a failure not tied to a specific call, like a transport that dropped on its own.
Double?
A backoff hint, when the platform sent one.
Double?
When this happened. Only ever set on the onError event — a thrown error is already happening now, so there is nothing this would tell you that catching it does not.
Code is a struct wrapping a String, not a closed enum: the platform’s code list is open-ended — a command or recording it rejects reports the platform’s own code, which this SDK cannot enumerate — so a closed enum would make every new platform code either a breaking change or an unrepresentable value. A ~= overload lets catch ReactorError.unauthorized read the way the Python SDK’s except UnauthorizedError does, for the codes below:
Example
This is the one deliberate divergence from the Python and C++ surfaces, which model this as a class hierarchy (except UnauthorizedError, catch (const UnauthorizedError&)). Swift has no base class to catch generically the way those do, and an open code set rules out a closed enum, so one struct with pattern-matchable static members is the shape that keeps catch ReactorError.unauthorized reading the same way.

Error codes

.internalError exists as a fallback for a failure with no better classification, the same role every other SDK’s base error class plays — it never gets a dedicated row here, same as those.
Codes are open-ended. A command or control request the model itself rejects reports the platform’s own code, which this list cannot enumerate — that arrives as a ReactorError with code set to whatever came, round-tripping through Code’s rawValue unchanged. Match on code for anything not in the table, and never assume an unrecognised code means the payload was malformed.

Subscription

What every on* registration hands back — a token that cancels the handler when it is released.
Definition
Example
It cancels when it is released, not when a block returns. _ = reactor.onStatus { print($0) } registers a handler and cancels it on the same line, because nothing holds the token. Store it in a property, an array, or anything else that outlives the period you want the handler to fire.
cancel() is idempotent and safe from any thread. A handler already running when it is called runs to completion; it is the next event that does not arrive. This is the same shape the C++ SDK’s Subscription takes, for the same reason: two closures cannot be compared, so there is no honest off(event:handler:) and a token is the only removal that works.

FileRef

A file the platform is holding, ready to be passed into a command. Returned by uploadFile(at:) and uploadData(_:name:mimeType:).
Definition
Handed to sendCommand(_:_:uploads:) as a named upload rather than embedded in the arguments — the platform resolves the reference on its side, so the bytes cross the wire once. See File Uploads.

Clip

A clip or a full-session recording, once the platform has accepted the request — which is not the same as it being ready. Returned by requestClip(_:) and requestRecording().
Definition
predictedReadyAtMS is a wall clock plus media seconds, so it is only right for a model generating at real time — treat it as an anchor for a grace period, never a deadline. Reactor does not host clips: playlistURL names a short-lived HLS playlist, and download(_:to:readyTimeout:progress:) is what fetches and assembles it. See Recordings.

DownloadResult and DownloadProgress

Returned by, and passed to the progress callback of, download(_:to:readyTimeout:progress:).
Definition

CommandReply

What a model answered a command with. Returned by sendCommand(_:_:uploads:).
Definition
nil where a reply would be is not a failure — sendCommand itself returns nil for that case rather than a CommandReply with empty fields. decode(_:) throws ReactorError.decodeFailed when data does not match the type asked for, or is absent.

TokenOptions

What a token minted with Reactor.fetchJWT(apiKey:apiURL:options:local:) is allowed to do.
Definition
[String]?
The models this token may reach, as owner/name. Left empty, the token carries everything the key’s roles allow — fine server-to-server, wrong to hand to a client you do not control.
Int?
How many sessions the token may open. Scoped tokens only.
Int?
How long the token should live, in seconds. The server clamps it.
The three fields are exactly what the platform’s token endpoint accepts, and no others — an unrecognised key there is an error, so a struct with three fields makes a misspelt option impossible rather than silently dropped into an unscoped token. See Authentication.

JSONValue

A JSON value, for the places where the shape is the model’s rather than this SDK’s — a command’s arguments, a model’s reply.
Definition
ExpressibleBy*Literal for every case, so a literal reads like plain JSON:
Example
Reading accessors answer nil rather than trapping when the value is not the case asked for: stringValue, doubleValue, intValue (nil for a NaN, an infinity, or a fraction — use doubleValue for those), boolValue, objectValue, arrayValue, and a subscript(key:) for reaching into an object directly. A caller who has modelled the command should reach for the Encodable/Decodable overloads on sendCommand and CommandReply.decode(_:) instead, and skip JSONValue entirely — this type is for the ad-hoc case, which is most of a first script.

Duration

requestClip(_:) and the readyTimeout parameter on download take Swift’s standard library Duration (.seconds(10), .milliseconds(250)) rather than a raw Double — the same reasoning that keeps a NaN or an infinite timeout unrepresentable at the call site, since Duration is stored as an exact (seconds, attoseconds) pair.