publish

fun publish(topic: String, message: String, @NonNull payload: JSONObject, options: PubSubPublishOptions)

Publishes a message to the specified topic.

Requires a joined meeting. Called before the meeting reaches CONNECTED, it throws and onError fires with code 3001 (ERROR_ACTION_PERFORMED_BEFORE_MEETING_JOINED). While the meeting is RECONNECTING it throws without an error event — the app already knows the state from onMeetingStateChanged.

If the message cannot be delivered — the server rejects it, the connection drops before it is acknowledged, or it is published while the pubsub connection is temporarily down (which also throws) — onError fires with code 4087 (PUBSUB_PUBLISH_FAILED) carrying the reason when the server supplies one.

Code Example:


JSONObject payload = new JSONObject();
payload.put("type", "reaction");
payload.put("emoji", "👍");
PubSubPublishOptions options = new PubSubPublishOptions();
try {
    meeting.pubSub.publish("REACTIONS", "reaction", payload, options);
} catch (Exception e) {
    Log.d("VideoSDK", "publish failed: " + e.getMessage());
}

Parameters

topic

the topic name to publish the message to

message

the message content to publish

payload

structured data to send alongside message; pass an empty JSONObject when there is none

options

the PubSubPublishOptions controlling persistence and other settings

Throws

if the meeting is not joined or is reconnecting, or the pubsub connection is temporarily down; the message is not sent — retry once the meeting is CONNECTED