Skip to main content
Version: 3.x.x

PubSubPublishOptions Class - Android

Options for publish(). Pass them to the constructor, PubSubPublishOptions(persist = ..., sendOnly = ...), and read them back as properties. Both have defaults, so pass only the ones you need.

Without options, publish() sends the message to everyone currently subscribed and does not store it.

Constructor parameters​

persist​

  • type: Boolean

  • defaultValue: false

  • This specifies whether to store messages on the server for participants who subscribe later.

  • If the value is true, the server stores the message, and participants who subscribe to the topic later receive it on onOldMessagesReceived(). With false, the message is delivered once to whoever is subscribed right now.


sendOnly​

  • type: Array<String>?

  • defaultValue: null

  • If you want to send a message to specific participants, you can pass their respective participantId here. If you pass null or an empty array, the message is sent to everyone subscribed to the topic.

note

Make sure that every participantId in the array is subscribed to that specific topic.

Example​

val publishOptions = PubSubPublishOptions(persist = true, sendOnly = arrayOf(participantId))

lifecycleScope.launch {
try {
room.pubSub.publish("CHAT", "Hello", publishOptions)
} catch (e: VideoSDKException) {
Log.d("VideoSDK", "publish failed: ${e.code} ${e.message}")
}
}

Got a Question? Ask us on discord