PubSub class
Represents the PubSub (Publish-Subscribe) mechanism for the room.
-
This class allows participants to publish messages to topics and subscribe to topics to receive messages. It supports persistent messages and payload attachments.
-
publish and subscribe need a joined room: called before Room.join completes or after the room is left, they throw a VideoSDKError (
3035).
Example
// Publish a message
await room.pubSub.publish("CHAT", "Hello");
// Subscribe to a topic
await room.pubSub.subscribe(
"CHAT",
PubSubMessageListener(onMessageReceived: (m) => print(m.message)),
);
Properties
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
publish(
String topic, String message, [PubSubPublishOptions? options, Map< String, dynamic> payload = const {}]) → Future<void> -
publish()is used to publish messages on a specified topic in the room. -
subscribe(
String topic, PubSubMessageListener listener, [PubSubSubscribeOptions? options]) → Future< void> -
Subscribes
listenertotopic. -
unsubscribe(
String topic, PubSubMessageListener listener) → Future< void> -
Stops
listenerreceivingtopic.