dart_mercure 0.2.1 copy "dart_mercure: ^0.2.1" to clipboard
dart_mercure: ^0.2.1 copied to clipboard

A library to communicate with dunglas/mercure. This library allow publish/subscribe on Mercure Hub. Can be use to create firebase like notification system.

example/dart_mercure_example.dart

import 'package:dart_mercure/dart_mercure.dart';

void main() {
  // Token generate with "mercure" JWT_KEY
  var token =
      'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJtZXJjdXJlIjp7InN1YnNjcmliZSI6WyIqIl0sInB1Ymxpc2giOlsiKiJdfX0.Gfj3BFrSOFhyFN0hPOYg-Pe4dfYWOKq7QJiMWYC2Z_k';
  var hub_url = 'http://mercure/.well-known/mercure';
  var topic = 'http://mercure/test';

  var mercure = Mercure(token: token, hub_url: hub_url);
  mercure.subscribeTopics(
      topics: <String>[topic, '2'],
      onData: (Event event) {
        print(event.data);
      });

  mercure.subscribeTopic(
      topic: topic,
      onData: (Event event) {
        print(event.data);
      });

  mercure.publish(topic: topic, data: 'DATA').then((status) {
    if (status == 200) {
      print('Message Sent');
    } else {
      print('Message Failed with code : $status');
    }
  });
}
7
likes
40
pub points
0%
popularity

Publisher

verified publisherwallforfry.fr

A library to communicate with dunglas/mercure. This library allow publish/subscribe on Mercure Hub. Can be use to create firebase like notification system.

Repository (GitHub)
View/report issues

License

BSD-2-Clause (LICENSE)

Dependencies

eventsource, http, meta

More

Packages that depend on dart_mercure