Client Callbacks
Connection Callbacks
Every callback on this page is a client event, except for the custom-event subscriptions listed under Event Subscriptions.
In C++ each one is a public Broadcaster member of RealtimeClient: subscribe with client.OnXxx.Subscribe(handler), which returns a Subscription.
In JavaScript each one is a named event: subscribe with client.on('name', handler), which returns an unsubscribe function, and the handler receives the single payload listed in the JavaScript column.
See Callbacks and Subscriptions for the lifetime rules in both languages.
Over the C API there is nothing to subscribe to: every callback below is pre-subscribed and delivered as a numbered event on the client's event queue. Broadcaster Events maps each callback to its event number and to the fields its parameters arrive in.
| C++ | JavaScript | Fires When | Manual Page |
|---|---|---|---|
OnDisconnected(DisconnectCause cause) |
disconnected with { cause } |
The connection ends, requested or not; cause carries the reason. |
Errors and Disconnects |
OnError(ClientError code, StringViewType message) |
error with a RealtimeError whose code is a ClientErrorCode |
An asynchronous error occurs outside a pending operation. | Errors and Disconnects |
OnCustomAuthStep(const RealtimeDictionary& data) |
customAuthStep with { data } |
A custom authentication provider requests another authentication step. | Authentication |
Room and Player Callbacks
| C++ | JavaScript | Fires When | Manual Page |
|---|---|---|---|
OnRoomJoined() |
roomJoined, no payload |
The local client enters a room, by creating or joining it. | Rooms and Players |
OnRoomLeft() |
roomLeft, no payload |
The local client leaves the current room. | Rooms and Players |
OnPlayerJoined(const Player& player) |
playerJoined with { player } |
A remote player joins the current room. | Rooms and Players |
OnPlayerLeft(int playerNumber, bool isInactive) |
playerLeft with { playerNumber, isInactive } |
A player leaves the current room; isInactive is true when the player may still rejoin. |
Rooms and Players |
OnMasterClientChanged(int newId, int oldId) |
masterClientChanged with { newMasterNumber, oldMasterNumber } |
Mastership moves from one player to another; the parameters carry the player numbers of the new and the previous master client. | Rooms and Players |
Property Callbacks
| C++ | JavaScript | Fires When | Manual Page |
|---|---|---|---|
OnRoomPropertiesChanged(const RealtimeMap& changes) |
roomPropertiesChanged with { changed } |
The room's custom properties change; the payload contains only the changed keys. | Custom Properties |
OnPlayerPropertiesChanged(int playerNumber, const RealtimeMap& changes) |
playerPropertiesChanged with { playerNumber, changed } |
A player's custom properties change. | Custom Properties |
OnPropertiesChangeFailed() |
propertiesChangeFailed, no payload |
The server rejects a property update, for example a failed compare-and-swap. | Custom Properties |
Event Subscriptions
Custom events are not a client event of their own. They are registered on the client itself, with an event-code filter baked into the subscription.
In C++ every SubscribeEvent overload returns the same Subscription type as Subscribe() does.
The payload form is deduced from the callback: std::span<const uint8_t> delivers raw bytes, const RealtimeValue& delivers the decoded payload.
In JavaScript onEvent(), onEventRange() and onAnyEvent() return an unsubscribe function, and the handler receives { code, senderNumber, data }.
data is the decoded value, or the raw Uint8Array with the option { asBytes: true }.
| C++ | JavaScript | Delivers | Manual Page |
|---|---|---|---|
SubscribeEvent(callback) |
onAnyEvent(handler) |
Every event code, 0 through 255. |
Custom Events |
SubscribeEvent(uint8_t eventCode, callback) |
onEvent(code, handler) |
Only that event code. | Custom Events |
SubscribeEvent(uint8_t firstEventCode, uint8_t lastEventCode, callback) |
onEventRange(firstCode, lastCode, handler) |
The inclusive code range. | Custom Events |
SubscribeEvent<Payload>(...) |
The { asBytes: true } option of the three methods above |
The same three subscriptions with the payload form named explicitly: in C++ std::span<const uint8_t> or const RealtimeValue& (plain RealtimeValue is accepted as shorthand), in JavaScript raw bytes or the decoded value. |
Custom Events |
SubscribeEvent<T>(uint8_t eventCode, callback) |
No counterpart; receive the bytes with { asBytes: true } and read them with a DataView |
One event code only, decoded into a trivially-copyable T; the callback takes (int senderId, const T& value). |
Custom Events |
In C++ the callback signature of the untyped overloads is (uint8_t eventCode, int senderId, PayloadType payload).
A byte-span payload points into a decode buffer owned by the subscription and is only valid during the call.
Direct Messaging Callbacks
| C++ | JavaScript | Fires When | Manual Page |
|---|---|---|---|
OnDirectMessage(int senderId, std::span<const uint8_t> data, bool isRelay) |
directMessage with { senderNumber, data, isRelay } |
A direct message arrives; isRelay is true when it traveled through the server instead of peer-to-peer. |
Direct Messaging |
OnDirectConnectionEstablished(int remotePlayerId) |
directConnectionEstablished with { playerNumber } |
A peer-to-peer connection to a remote player is established. | Direct Messaging |
OnDirectConnectionFailed(int remotePlayerId) |
directConnectionFailed with { playerNumber } |
A peer-to-peer connection attempt to a remote player fails. | Direct Messaging |
Lobby Callbacks
| C++ | JavaScript | Fires When | Manual Page |
|---|---|---|---|
OnRoomListUpdated(const std::vector<RoomListing>& rooms) |
roomListUpdated with { rooms } |
The room list of the joined lobby changes. | Lobbies and Matchmaking |
OnLobbyStats(const std::vector<LobbyStats>& stats) |
lobbyStats with { stats } |
Lobby statistics arrive, requested explicitly or pushed when automatic lobby statistics are enabled (AutoLobbyStats in C++, autoLobbyStats in JavaScript). |
Lobbies and Matchmaking |
Advanced Callbacks
| C++ | JavaScript | Fires When | Manual Page |
|---|---|---|---|
OnWarning(WarningCode code, StringViewType message) |
warning with { code, message }, code a WarningCode string |
The SDK reports a non-fatal warning, such as an internal queue filling up. | Errors and Disconnects |
OnAppStatsUpdated() |
appStatsUpdated, no payload |
The server pushes fresh application statistics; read them from the network statistics (GetStats() in C++, client.stats in JavaScript). |
Statistics |
Last updated on
Back to top