JavaScript SDK — Realtime

Realtime — mp.realtime + RealtimeClient

realtime.get
await mp.realtime.get(playerToken)

Mints the realtime credential for the player's current realtime-enabled room — one live token per player, ~5-minute connect window. Returns token + realtime_server coordinates.

connect
const rt = mp.createRealtime(opts); await rt.connect(token, realtimeServer)

Opens the WebSocket control lane (wss://, client=json). Resolves on the server's connected envelope — exposes connectionId, playerInfo, udpEnabled.

send
rt.send(target, command, data, { targetIds?, seq? })

Reliable ordered message — targets 'all' | 'host' | 'others' | 'specific'. Host ACL is enforced server-side: non-hosts may only target 'host'.

connectUdp (Node.js)
await rt.connectUdp()

Binds the MUR1 UDP fast lane via node:dgram — datagrams authenticate through the WS-issued connection id. Node-only; rejects with ConfigurationError in browsers.

sendUnreliable
rt.sendUnreliable(target, command, data, { targetIds?, seq? })

UDP when bound, automatic WebSocket fallback otherwise — browsers get WS delivery since they physically cannot send UDP.

heartbeat / close
rt.heartbeat()
rt.close()

Keepalive (auto-scheduled every 20s vs the 60s idle close) and clean shutdown — closes UDP socket and WS.

events
onConnected · onReceive · onSent · onError · onClose

Assign handlers via options or properties: onReceive(command, data, sender, seq) fires per peer message.