PubSubMessage Class - Flutter
Properties
id
-
type:
String -
Unique id of the pubsub message.
message
-
type:
String -
Message that has been published on the specific topic.
topic
-
type:
String -
Name of the topic.
senderId
-
type:
String -
This is the id of the participant, who has sent this pubsub message.
senderName
-
type:
String -
This is the name of the participant, who has sent this pubsub message.
timestamp
-
type:
String -
When the message was published, as the server sends it.
payload
-
type:
Map<String,dynamic>? -
This is the data that was sent with the message as the
payloadofpublish(). It isnullor empty when the sender passed none.
PubSubMessageListener
Pass a PubSubMessageListener to subscribe(), and the same object to unsubscribe(). Every callback is optional.
onMessageReceived
-
type:
void Function(PubSubMessage message)? -
Called for each live message.
onOldMessagesReceived
-
type:
void Function(List<PubSubMessage> messages, PubSubHistoryInfo info)? -
Called with the topic's stored messages after you subscribe.
info.isLastistrueon the last delivery.
onBatchReceived
-
type:
void Function(List<PubSubMessage> messages)? -
Called with live messages that are delivered together.
onMessageDrop
-
type:
void Function(PubSubMessageDropInfo info)? -
Called when live messages are dropped under
RealtimeOverflow.DROP.info.droppedCountsays how many.
PubSubSubscribeOptions
Options for subscribe(). A field you leave out takes the server's default.
oldMessageLimit
-
type:
int? -
How many stored messages to deliver on subscribe.
0skips them.
realtimeOverflow
-
type:
RealtimeOverflow? -
What to do with live messages that arrive faster than the app takes them:
RealtimeOverflow.QUEUEkeeps them, up tomaxQueue, andRealtimeOverflow.DROPdrops them and reports the count toonMessageDrop.
maxQueue
-
type:
int? -
The queue size for
RealtimeOverflow.QUEUE. It is not allowed withRealtimeOverflow.DROP.
newMessageLimit
-
type:
int? -
The most live messages delivered in one batch.
Example
final listener = PubSubMessageListener(
onBatchReceived: (List<PubSubMessage> messages) {
// live messages, delivered together
},
onMessageDrop: (PubSubMessageDropInfo info) {
print("Dropped ${info.droppedCount} messages");
},
);
await room.pubSub.subscribe(
"REACTIONS",
listener,
const PubSubSubscribeOptions(
oldMessageLimit: 0,
realtimeOverflow: RealtimeOverflow.DROP,
newMessageLimit: 20,
),
);
Got a Question? Ask us on discord

