PubSub Class Methods - Android
publish()
publish()
is used to publish messages on a specified topic in the meeting.
Parameters
-
topic
- type:
String
- This is the name of the topic, for which message will be published.
- type:
-
message
- type:
String
- This is the actual message.
- type:
-
options
- type:
PubSubPublishOptions
- This specifies the options for publish.
- type:
-
payload
- type:
JSONObject
OPTIONAL
- If you need to include additional information along with a message, you can pass here as
JSONObject
.
- type:
Returns
void
Example
- Kotlin
- Java
// Publish message for 'CHAT' topic
val publishOptions = PubSubPublishOptions()
publishOptions.isPersist = true
meeting!!.pubSub.publish("CHAT", "Hello from Android", publishOptions)
// Publish message for 'CHAT' topic
PubSubPublishOptions publishOptions = new PubSubPublishOptions();
publishOptions.setPersist(true);
meeting.pubSub.publish("CHAT", "Hello from Android", publishOptions);
subscribe()
subscribe()
is used to subscribe a particular topic to get all the messages of that particular topic in the meeting.
Parameters
-
topic:
- type:
String
- Participants can listen to messages on that particular topic.
- type:
-
listener:
- type:
PubSubMessageListener
- type:
Returns
Example
- Kotlin
- Java
var pubSubMessageListener: ubSubMessageListener =
PubSubMessageListener { message ->
Log.d("#message","onMessageReceived: " + message.message)
}
// Subscribe for 'CHAT' topic
val pubSubMessageList = meeting!!.pubSub.subscribe("CHAT", pubSubMessageListener)
PubSubMessageListener pubSubMessageListener = new PubSubMessageListener() {
@Override
public void onMessageReceived(PubSubMessage message) {
Log.d("#message", "onMessageReceived: " + message.getMessage());
}
};
// Subscribe for 'CHAT' topic
List<PubSubMessage> pubSubMessageList = meeting.pubSub.subscribe("CHAT", pubSubMessageListener);
unsubscribe()
unsubscribe()
is used to unsubscribe a particular topic on which you have subscribed priviously.
Parameters
-
topic:
- type:
String
- This is the name of the topic to be unsubscribed.
- type:
-
listener:
- type:
PubSubMessageListener
- type:
Returns
void
Example
- Kotlin
- Java
// Unsubscribe for 'CHAT' topic
meeting!!.pubSub.unsubscribe("CHAT", pubSubMessageListener)
// Unsubscribe for 'CHAT' topic
meeting.pubSub.unsubscribe("CHAT", pubSubMessageListener);
Got a Question? Ask us on discord