Realtime
Server-Sent Events
Subscribe to one-way event streams from MUDBASE for notifications, progress updates, and live activity.
Overview
Server-Sent Events (SSE) let the server push updates to the client over a single HTTP connection. Use SSE when you need a simple, one-way stream (e.g. task progress, notifications). For two-way real-time communication, use Socket.IO (WebSockets).
Endpoint
text
GET https://cloud.mudbase.dev/realtime/events
Authorization: Bearer YOUR_API_KEY
Accept: text/event-streamGET https://cloud.mudbase.dev/realtime/events
Authorization: Bearer YOUR_API_KEY
Accept: text/event-streamConnecting with EventSource
// Browser EventSource (automatically reconnects)
const es = new EventSource(
'https://cloud.mudbase.dev/realtime/events',
{ withCredentials: true }
);
// Send API key via query param or use a session cookie
const es = new EventSource(
'https://cloud.mudbase.dev/realtime/events?token=YOUR_API_KEY'
);
es.onmessage = (event) => {
const data = JSON.parse(event.data);
console.log('Event:', data.type, data);
};
es.onerror = (err) => {
console.error('SSE error:', err);
};// Browser EventSource (automatically reconnects)
const es = new EventSource(
'https://cloud.mudbase.dev/realtime/events',
{ withCredentials: true }
);
// Send API key via query param or use a session cookie
const es = new EventSource(
'https://cloud.mudbase.dev/realtime/events?token=YOUR_API_KEY'
);
es.onmessage = (event) => {
const data = JSON.parse(event.data);
console.log('Event:', data.type, data);
};
es.onerror = (err) => {
console.error('SSE error:', err);
};Event Format
Each event is a line of text starting with data: followed by JSON. Multiple lines are joined. Example:
textevent stream
data: {"type":"backup.progress","payload":{"percent":50,"id":"backup_abc"}}
data: {"type":"notification","payload":{"message":"Task completed"}}data: {"type":"backup.progress","payload":{"percent":50,"id":"backup_abc"}}
data: {"type":"notification","payload":{"message":"Task completed"}}Note
For bidirectional real-time (e.g. chat, presence), use the Socket.IO. For HTTP callbacks on events, see webhooks in the API reference.