Skip to content

Instantly share code, notes, and snippets.

@ova2
Last active May 15, 2021 07:55
Show Gist options
  • Save ova2/bcedd7ef98386f99442147655bbc2f53 to your computer and use it in GitHub Desktop.
Save ova2/bcedd7ef98386f99442147655bbc2f53 to your computer and use it in GitHub Desktop.
import 'package:mqtt_client/mqtt_client.dart';
import 'package:rxdart/rxdart.dart';
class MessagingService {
/// Subscribes to the given topic and produces a stream of received updates from the message
/// broker matching this topic. You can also pass [MqttQos] which defaults to atLeastOnce.
///
/// This method returns a stream of [MqttMessage] instances.
Stream<MqttMessage> updatesFor(String topic, [MqttQos qos = MqttQos.atLeastOnce]) {
...
}
/// Publishes a message to the message broker. You should pass a topic and serialized
/// message data in JSON format. You can also pass [MqttQos] which defaults to atLeastOnce.
///
/// This method returns a [Future] of message identifer [int] assigned to the message.
Future<int> request(String topic, String jsonData, [MqttQos qos = MqttQos.atLeastOnce]) {
...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment