publish

suspend fun publish(topic: String, message: String, options: PubSubPublishOptions? = null, payload: JSONObject? = null)

Publishes a message on a topic.

Requires a joined room. Before join completes it throws and RoomEventListener.onError fires with 3035 (ERROR_ACTION_PERFORMED_BEFORE_ROOM_JOINED), whose message names this method; while the room is RoomState.RECONNECTING it throws 3065 (ERROR_ROOM_RECONNECTING) without reporting it on onError. Rejected calls are not replayed once the room reconnects.

Suspends until the server has taken the message.

Parameters

topic

the channel to publish on; subscribers of that topic receive it, including this participant when it is subscribed.

message

the message body.

options

persistence and who receives it; null sends to everyone currently subscribed, with no history kept.

payload

optional JSON delivered alongside message

Throws

3035 / 3065 if the room is not joined or is reconnecting, or 4087 (PUBSUB_PUBLISH_FAILED) when the message could not be sent. Every failure but 3065 also reaches onError.