Skip to main content

Broadcast

OBR.broadcast

The broadcast api allows you to send ephemeral messages to other players in the room.

Reference

Methods

sendMessage

async sendMessage(channel, data)

Send a message to other players on a given channel.

Parameters

NAMETYPEDESCRIPTION
channelstringThe channel to send to
dataanyAny value that can be JSON serialized. Limited to 16KB in size
optionsBroadcastOptionsOptions to control how the message is sent (optional)

Example

OBR.broadcast.sendMessage("rodeo.owlbear.example", "Hello, World!");

onMessage

onMessage(channel, callback);

Parameters

NAMETYPEDESCRIPTION
channelstringThe channel to receive from
callback(event: BroadcastEvent) => voidA callback for when a message is sent from another player on this channel

Returns a function that when called will unsubscribe from message events for this channel.

Example

/**
* Use an `onMessage` event with a React `useEffect`.
* `onMessage` returns an unsubscribe event to make this easy.
*/
useEffect(
() =>
OBR.broadcast.onMessage("rodeo.owlbear.example", (event) => {
// Use the data from the event
}),
[]
);

Type Definitions

BroadcastEvent

TYPE
object

Properties

NAMETYPEDESCRIPTION
dataanyThe data for this event
connectionIdstringThe connection id of the player who sent the event

BroadcastOptions

TYPE
object

Properties

NAMETYPEDESCRIPTION
destination"REMOTE" | "LOCAL" | "ALL"Choose where the broadcast is sent. "REMOTE" sends to other connected players, "LOCAL" will send to the current player and "ALL" will send to all connected players. Defaults to "REMOTE"