publish method

Future<void> publish(
  1. String topic,
  2. String message, [
  3. PubSubPublishOptions? options,
  4. Map<String, dynamic> payload = const {},
])

publish() is used to publish messages on a specified topic in the room.

Throws if the room has not been joined yet or the request fails.

Parameters

  • topic - This is the name of the topic, for which message will be published.
  • message - This is the actual message.
  • options - Whether to persist the message, and who to send it to — see PubSubPublishOptions.
  • payload - If you need to include additional information along with a message, you can pass here as Map<String, dynamic>. This is optional parameter.

Example

// Publishing message
room.pubSub
    .publish(
      "CHAT",
      "Hii",
      const PubSubPublishOptions(persist: true),
    );

Implementation

Future<void> publish(String topic, String message,
        [PubSubPublishOptions? options,
        Map<String, dynamic> payload = const {}]) =>
    _publish(topic, message, options, payload);