Riff

Messaging and events

All messaging is room-scoped: you must be in a room, and you can only reach players in the same room.

The three ways to send

ActionGoes toArrives as
sendToRoomeveryone in the room (not you, unless includeSelf)event message
sendToPlayerone player in the roomevent directMessage
sendToMasterthe masterevent message

Data you send:

{ "action": "sendToRoom", "data": { "eventName": "chat", "data": { "text": "gg" }, "includeSelf": false } }
  • eventName is required. It is your event name (chat, cast, scoreUpdated...).
  • data is any JSON value you like.
  • includeSelf (sendToRoom only) also delivers the message back to you.
  • sendToPlayer also needs targetPlayerId (the player's playerId, not connection id). If they are not in your room you get PLAYER_NOT_FOUND.

How a message arrives

Riff wraps your payload. Receivers get:

{ "event": "message", "data": { "eventName": "chat", "data": { "text": "gg" }, "fromPlayerId": "p-123" }, "timestamp": 1760000000000 }

So there are two names: the outer event (message or directMessage, set by Riff) and your inner eventName. Your code switches on the inner one. fromPlayerId is set by the server and cannot be forged by the sender.

Events Riff sends on its own

EventWhendata
roomJoinedyou joined{ room, players }
roomLeftyou left{ roomId, playerId }
roomList / roomStatereplies to listRooms / getRoomStatesee Lobby and rooms
playerJoinedsomeone joined{ playerId, playerName, connectionId, joinedAt }
playerLeftsomeone left{ playerId, playerName }
hostChangedmaster changed{ newHostConnectionId }
roomPropertiesChangedmaster changed room props{ properties } (full merged set)
playerPropertiesChangeda player changed theirs{ playerId, playerName, properties }
positionUpdatesee Gameplay{ playerId, x, y, z, rotation?, animState? }
eventRaiseda raiseTurnEvent{ eventCode, data, fromPlayerId, fromPlayerName }
turnChangedmaster set the turn{ targetPlayerId }
gameEndedmaster ended the game{ results }
pongreply to pingnone
errorsomething was refusedcode, message (top level, not inside data)

Every server message carries a timestamp (server milliseconds).

Errors

Errors arrive as { "event": "error", "code": "ROOM_FULL", "message": "..." }. The full list is in the reference. Refused actions are never silent, with one exception: the WebSocket handshake itself (see Connecting).

RATE_LIMITED means you exceeded 30 in-room messages in one second. Messages over the budget are dropped, the budget refills the next second, and the connection stays open. Batch high-frequency data (see position updates) instead of sending every frame.

Delivery guarantees

  • Messages are delivered in the order Riff processes them, but there is no guaranteed ordering between different senders and no acknowledgements or retries. A player who has just dropped misses the message.
  • There is no history: late joiners do not receive earlier messages. Put state they need in room properties or player properties, which are stored, and use messages for things that happen once.

Unity

await client.SendToRoomAsync("chat", new { text = "gg" });
await client.SendToPlayerAsync(targetPlayerId, "invite", new { room = "arena-1" });
await client.SendToMasterAsync("buyItem", new { itemId = 7 });

client.OnMessageReceived.AddListener(msg => {
    // Outer event: "message" or "directMessage" (anything the SDK does not handle itself)
    var name = msg.Data?["eventName"]?.ToString();     // your event name
    var from = msg.Data?["fromPlayerId"]?.ToString();
    var payload = msg.Data?["data"];
    switch (name) { case "chat": /* ... */ break; }
});

The SDK's SendToRoomAsync sends without includeSelf; to echo to yourself, handle your own action locally.