Skip to content

WebSocket Integration

MateoF24 edited this page Aug 15, 2026 · 3 revisions

WebSocket Integration

A live feed of what timers are doing, for things that are not a browser: Discord bots, stream overlays, scoreboards on a wall, whatever you are building.

It is a real WebSocket (RFC 6455), written into the mod itself — OnTime has no dependencies, so there is nothing to install alongside it.

Turning it on

It is enabled by default and listens on 25581. Both are settings — see Settings — and the port applies at the next server start.

ws://your-server:25581

The token

A connection without the right token is refused. This is not optional and there is no way to switch it off.

The token is the same one the Web Panel uses, printed by /timer webpanel info. Send it one of two ways:

As a query parameter, which most libraries make easy:

ws://your-server:25581/?t=<token>

As a subprotocol, which is what a browser has to use because it cannot set headers on a WebSocket:

new WebSocket("ws://your-server:25581", ["ontime.token." + token]);

Wrong tokens from one address are counted, and after a few of them that address is refused outright rather than answered.

Coming from 4.0.0 or earlier? The feed used to be open to anyone who could reach the port. Existing consumers will need the token added before they connect. This was changed deliberately: the feed describes a server whose timers run commands at operator level.

What arrives

One JSON object per event, per execution:

{
  "event": "TICK",
  "name": "round",
  "runId": "3f2a...",
  "currentSeconds": 245,
  "targetSeconds": 300,
  "formattedTime": "04:05",
  "percentage": 81.6,
  "countUp": false,
  "running": true,
  "scope": "GLOBAL",
  "audienceSize": 0
}
Event When
START an execution begins
PAUSE it is paused
RESUME it is resumed
TICK once a second while it runs
FINISH it reaches its end

Every message names its runId, because one timer can be running many times at once — see Runs and Audiences. A bot that only cares about one clock should watch that id rather than the timer's name.

scope is GLOBAL, PLAYERS or SELECTOR, and audienceSize is how many people can see it — 0 for a global one, which everybody sees.

Notes

  • Messages are sent from a thread of their own, so a slow or stuck consumer cannot hold up the server.
  • The feed is one-way. To change something, use the commands, the Admin Panel, the Web Panel, or the API from another mod.
  • Stopping the server closes every connection cleanly.

Clone this wiki locally