Riff

Server API

Players send messages through the SDK. Your own backend can send messages too, with one HTTPS call, without joining a room or holding a connection. Use it for announcements ("maintenance in 5 minutes"), results computed on your server, scheduled events, and anything else that should reach players but does not start with a player.

Send a message

POST https://api.riffserver.com/v1/broadcast
X-App-Id:  <your appId>
X-App-Key: <your app key>
Content-Type: application/json
{
  "target": "room",
  "roomName": "arena-1",
  "eventName": "announcement",
  "data": { "text": "Double points for the next 5 minutes" }
}
FieldRequiredMeaning
targetyesroom, player or app
roomNamefor roomThe room to send to (same naming as joinRoom)
playerIdfor playerThe player to send to (all of their connections)
eventNameyesYour own event name, up to 100 characters
datanoAny JSON value

Targets:

  • room: everyone currently in the room.
  • player: one player, wherever they are.
  • app: everyone connected to your app. A single call reaches up to 5,000 connections; the response says when it was cut short.

Response

{ "delivered": 7, "attempted": 8, "truncated": false }

attempted is how many connections were found, delivered is how many were reachable (someone may have just left). A room that does not exist, or a player who is offline, gives 0 and 0, not an error.

StatusMeaning
200Processed. Check delivered.
400The request was malformed. The error field says what is wrong.
401The app id or key is missing or wrong, or the app is disabled.

How players receive it

Exactly like a room message, so no client changes are needed:

{ "event": "message", "data": { "eventName": "announcement", "data": { "text": "..." }, "fromPlayerId": "server" } }

fromPlayerId is always "server". In Unity it arrives on OnMessageReceived like any other message, so you can tell it apart from player messages by that id.

Keep the app key on your server

The app key proves the call comes from you. Never put it in a game client or in anything a player can read. Rotate it in your dashboard if it leaks; the old key stops working immediately. Requests are rate limited, so a loop that sends too fast receives errors instead of flooding your players.

Example (Node)

async function announce(roomName, text) {
  const res = await fetch(`${process.env.SERVER_API_URL}/v1/broadcast`, {
    method: "POST",
    headers: {
      "X-App-Id": process.env.APP_ID,
      "X-App-Key": process.env.APP_KEY,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({ target: "room", roomName, eventName: "announcement", data: { text } }),
  });
  return res.json(); // { delivered, attempted, truncated }
}