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 join completes — before onMeetingJoined fires, even if the connection is already up — it throws and onError fires with code 3001 (ERROR_ACTION_PERFORMED_BEFORE_MEETING_JOINED), whose message names this method. While the meeting is RECONNECTING it throws and onError fires with code 3014 (ERROR_MEETING_RECONNECTING); the call is not replayed for you once the meeting reconnects.

Publishing while the pubsub connection is down and has not yet been re-established throws and fires onError with code 3013 (OPERATION_TIMEOUT); the message is not sent. A message published before pubsub has connected for the very first time is queued instead, and sent once the connection is up. If the message cannot be delivered later — the server rejects it, or the connection drops before it is acknowledged — 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 after the meeting has joined or finished reconnecting