|
|
OpenLP provides a simple WebSocket server to provide up to date information about the state of the program. Once connected to the server, OpenLP will provide updates whenever the state of the program changes.
|
|
|
|
|
|
The default port for the WebSocket server is `4317`. This is not the same as the [HTTP API](HTTP-API) and web remote.
|
|
|
|
|
|
> **Note**
|
|
|
>
|
|
|
> The OpenLP server is only available on your local network. OpenLP does not perform any sort of port forwarding and the server is not capable of handling large loads. It is not recommended to expose the OpenLP server to the internet unless you know what you are doing.
|
|
|
|
|
|
## Program State
|
|
|
|
|
|
The state of OpenLP is sent in a JSON format. The response will contain JSON data types including <mark>{ }</mark> JSON object, <mark>St</mark> JSON string, <mark>TF</mark> JSON boolean and <mark>Nm</mark> JSON number as described below:
|
|
|
|
|
|
<pre>
|
|
|
<mark>{}</mark> - Root of the response
|
|
|
└── <mark>{}</mark> <b>results:</b> - Containing object for state.
|
|
|
├── <mark>Nm</mark> <b>counter:</b> - Number incremented if the live display has changed.
|
|
|
├── <mark>Nm</mark> <b>service:</b> - Number incremented if the service is modified.
|
|
|
├── <mark>Nm</mark> <b>slide:</b> - Number incremented if the service is modified.
|
|
|
├── <mark>St</mark> <b>item:</b> - The service unique identifier for the current service item.
|
|
|
├── <mark>TF</mark> <b>twelve:</b> - Is using twelve hour time.
|
|
|
├── <mark>TF</mark> <b>blank:</b> - Is display blank.
|
|
|
├── <mark>TF</mark> <b>theme:</b> - Is display showing the theme.
|
|
|
├── <mark>TF</mark> <b>display:</b> - Is display showing the desktop.
|
|
|
├── <mark>TF</mark> <b>display:</b> - Is display showing the desktop.
|
|
|
├── <mark>Nm</mark> <b>version:</b> - Version number (not sure what for, hard coded as 3 atm).
|
|
|
├── <mark>TF</mark> <b>isSecure:</b> - Is authentication enabled for login required HTTP API endpoints.
|
|
|
└── <mark>St</mark> <b>chordNotation:</b> - Notation used for chords, can be `english`, `german` or `neo-latin`.</pre>
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
### Javascript
|
|
|
|
|
|
This script connects to the WebSockets server and prints to the console every time the state changes:
|
|
|
```javascript
|
|
|
const host = window.location.hostname;
|
|
|
const websocket_port = 4317;
|
|
|
|
|
|
ws = new WebSocket(`ws://${host}:${websocket_port}`);
|
|
|
ws.onmessage = (event) => {
|
|
|
const reader = new FileReader();
|
|
|
reader.onload = () => {
|
|
|
const state = JSON.parse(reader.result.toString()).results;
|
|
|
|
|
|
// Do stuff here
|
|
|
console.log(state);
|
|
|
|
|
|
};
|
|
|
reader.readAsText(event.data);
|
|
|
};
|
|
|
```
|
|
|
If you are not running this on a OpenLP stage view, you might want to change `window.location.hostname` to the IP of the computer running OpenLP. |
|
|
\ No newline at end of file |