Skip to content

Broadcasting

Real-time event broadcasting lets external systems receive server events as they happen, using Server-Sent Events (SSE) or WebSockets.

SSE Stream

GET /api/v1/events
Authorization: Bearer <token>
Accept: text/event-stream

Events are sent as JSON:

event: player:connected
data: {"serverId": 1, "name": "John Doe"}

event: economy:moneyAdded
data: {"playerId": 1, "account": "bank", "amount": 1000}

Filtering Events

Subscribe only to specific event types:

GET /api/v1/events?filter=player:*,economy:*

WebSocket

js
const ws = new WebSocket('ws://your-api:3000/api/v1/ws', {
    headers: { Authorization: 'Bearer ' + token }
})

ws.on('message', (raw) => {
    const { event, data } = JSON.parse(raw)
    console.log(event, data)
})

Pushing Events to the Server

The API can also receive events and forward them into the server:

bash
POST /api/v1/events/emit
{ "event": "my-module:externalAction", "data": { "playerId": 5 } }

The server-side module must register a handler for this event.

Released under the MIT License.