Skip to content

WebSocket Integration

MateoF24 edited this page Mar 10, 2026 · 3 revisions

WebSocket Integration

OnTime includes an optional TCP server that broadcasts timer events as JSON lines. It is intended for external tools such as Discord bots, stream overlays, or admin dashboards.

Enabling

In config/ontime/config.json, set:

"webSocketEnabled": true,
"webSocketPort": 8765

The server starts automatically when the Minecraft server starts and stops when it shuts down. The default port is 8765.


Event Format

Each event is a single JSON object followed by a newline. Fields are always present.

{
  "event": "FINISH",
  "name": "speedrun",
  "currentSeconds": 0,
  "targetSeconds": 1800,
  "formattedTime": "00:00",
  "percentage": 0.0,
  "countUp": false,
  "running": false
}

Event types

event Fired when
START A timer becomes active
FINISH A timer reaches its end (or condition is met)
PAUSE The active timer is paused
RESUME The active timer is resumed
TICK Once per second while the timer is running

Connecting

Any TCP client that reads newline-delimited text can connect. Example with Python:

import socket

s = socket.socket()
s.connect(("localhost", 8765))
f = s.makefile()
for line in f:
    print(line.strip())

API Control

The WebSocket server can also be started or stopped programmatically:

OnTimeAPI api = OnTimeAPI.getInstance();
api.startWebSocket(8765);
api.stopWebSocket();
boolean running = api.isWebSocketRunning();

Clone this wiki locally