Skip to main content

Protocol

It is a protocol about data communication between client and a Live Assistant WebSocket server.

Install Package

yarn add @live-assistant/protocols-data

Server

In most cases, the server runs on a localhost port like ws://localhost:[PORT]/data. But it could also be a public server like wss://example.com:[PORT]/data.

To connect to it, try open a WebSocket connection with ws://localhost:[PORT]/data?authorization=[PASSWORD]&types=[TYPES]&version=[VERSION] or wss://example.com:[PORT]/data?authorization=[PASSWORD]&types=[TYPES]&version=[VERSION] in your client.

Port

The server runs on the port 7196 by default, but it could also be changed by user.

Password

If the user set a password, it will be required to connect to the server.

Version

The version of the protocol. The server will only accept the connection if the version provided is smaller than or equal to the version supported by the server. Otherwise, the server will close the connection.

Types

The types of the data requested by the client. The server will only accept the connection if all the requested types are available. Otherwise, the server will close the connection.

It should be a comma separated list of data types. For example, types=message,gift will request the server to send message and gift data. To lean more about the data types, see Data Types.

Heartbeat

Since the only server implementation for now is Live Assistant desktop app, the protocol does not requires client to send heartbeat to the server. This behavior may change in the future.

Message Format

The message sent via WebSocket is a serialized JSON string in this format:

type DataType = {
| 'enter'
| 'follow'
| 'audienceUpdate'
| 'message'
| 'superChat'
| 'gift'
| 'membership'
| 'viewersCount'
| 'caption'
| 'heartRate'
| 'mediaInfo'
| 'inputAudioSpectrum'
| 'outputAudioSpectrum'
| 'karaokeStation'
| 'mousePosition'
| 'mouseButton'
| 'keyboardButton'
| 'gamepad'
}

type Message = {
type: DataType
payload: Payload
}

The real type of payload in the above code is corresponding to the type. For more information, see Data Types.