obs-websocket provides a feature-rich RPC communication protocol, giving access to much of OBS's feature set. This document contains everything you should know in order to make a connection and use obs-websocket's functionality to the fullest.
These steps should be followed precisely. Failure to connect to the server as instructed will likely result in your client being treated in an undefined way.
- Initial HTTP request made to obs-websocket server.
- HTTP request headers can be used to set the websocket communication type. The default format is JSON. Example headers:
-`Content-Type: application/json`
-`Content-Type: application/msgpack`*Not currently planned for v5.0.0*
- If an invalid `Content-Type` is specified, the connection will be closed.
- Once the connection is upgraded, the websocket server will immediately send a [`Hello`](#hello) message to the client.
- The client listens for the `Hello` and responds with an [`Identify`](#identify) containing all appropriate session parameters.
- The server receives and processes the `Identify`.
- If authentication is required and the `Identify` does not contain an `authentication` string, or the string is not correct, the connection is dropped with `WebsocketCloseCode::AuthenticationFailed`
- If the client has requested an `rpcVersion` which the server cannot use, the connection is dropped with `WebsocketCloseCode::UnsupportedProtocolVersion`
- If any other parameters are malformed (invalid type, etc), the connection is dropped with `WebsocketCloseCode::InvalidIdentifyParameter`
- Once identification is processed on the server, the server responds to the client with an [`Identified`](#identified).
- The client will begin receiving events from obs-websocket and may now make requests to obs-websocket.
- At any time after a client has been identified, it may send a `Reidentify` message to update certain allowed session parameters. The server will respond in the same way it does during initial identification.
- The obs-websocket server listens for any messages containing a `request-type` field in the first level JSON from unidentified clients. If a message matches, the connection is dropped with `WebsocketCloseCode::UnsupportedProtocolVersion`.
- If a message with a `messageType` is not recognized to the obs-websocket server, the connection is dropped with `WebsocketCloseCode::UnknownMessageType`.
- At no point may the client send any message other than a single `Identify` before it has received an `Identified`. Breaking this rule will result in the connection being dropped by the server with `WebsocketCloseCode::NotIdentified`.
- The `Hello` object contains an `rpcVersion` field, which is the latest RPC version that the server supports.
- If the server's version is is older than the client's, the client is allowed the capability to support older RPC versions. The client determines which RPC version it hopes to communicate on, and sends it via the `rpcVersion` field in the `Identify`.
- If the server's version is newer than the client's, the client sends its highest supported version in its `Identify` in hopes that the server is backwards compatible to that version.
- If the `Hello` does not contain an `authentication` object, the resulting `Identify` object sent to the server does not need to have an `authentication` string.
obs-websocket uses SHA256 to transmit authentication credentials. The server starts by sending an object in the `authentication` field of its `Hello`. The client processes the authentication challenge and responds via the `authentication` string in `Identify`.
For this guide, we'll be using `supersecretpassword` as the password.
The `authentication` object in `Hello` looks like this (example):
- Description: First message sent from the server immediately on client connection. Contains authentication information if auth is required. Also contains RPC version for version negotiation.
**Additional Base Object Fields:**
```
{
"obsWebsocketVersion": string,
"rpcVersion": number,
"availableEvents": array<string>,
"availableRequests": array<string>,
"authentication": object(optional)
}
```
-`rpcVersion` is a version number which gets incremented on each **breaking change** to the obs-websocket protocol. Its usage in this context is to provide the current rpc version that the server would like to use.
- Description: Response to `Hello` message, should contain authentication string if authentication is required, along with PubSub subscriptions and other session parameters.
-`rpcVersion` is the version number that the client would like the obs-websocket server to use.
- When `ignoreInvalidMessages` is true, the socket will not be closed for `WebsocketCloseCode``MessageDecodeError`, `UnknownMessageType`, or `RequestMissingRequestId`. Instead, the message will be logged and dropped.
- When `ignoreNonFatalRequestChecks` is true, requests will ignore checks which are not critical to the function of the request. Eg calling `DeleteScene` when the target scene does not exist would still return `RequestStatus::Success` if this flag is enabled.
- When `eventWhitelist` is specified, only the specified events will be sent to the client.
- When `eventBlacklist` is specified, all events except those specified will be sent to the client.
- Only `eventWhitelist` or `eventBlacklist` may be provided. If both are provided, the connection will be closed with `WebsocketCloseCode::InvalidIdentifyParameter`.
- Description: Sent at any time after initial identification to update the provided session parameters.
**Additional Base Object Fields:**
```
{
"ignoreInvalidMessages": bool(optional),
"ignoreNonFatalRequestChecks": bool(optional),
"eventWhitelist": array<string>(optional),
"eventBlacklist": array<string>(optional)
}
```
- Only the listed parameters may be changed by `Reidentify` after initial identification. To change a parameter not listed, you must reconnect to the obs-websocket server.
- Description: Client is making a batch of requests for obs-websocket. Requests are processed serially (in order) by the server.
**Additional Base Object Fields:**
```
{
"requestId": string,
"haltOnFailure": bool(optional) = false,
"requests": array<object>
}
```
- When `haltOnFailure` is `true`, the processing of requests will be halted on first failure. Returns only the processed requests in [`RequestBatchResponse`](#requestbatchresponse).