dart_mercure 0.1.3-dev.1 copy "dart_mercure: ^0.1.3-dev.1" to clipboard
dart_mercure: ^0.1.3-dev.1 copied to clipboard

outdated

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 'dart:async';
import 'package:dart_mercure/dart_mercure.dart';
import 'package:w3c_event_source/event_source.dart';

main() {
  // Token generate with "mercure" JWT_KEY
  String token =
      "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJtZXJjdXJlIjp7InN1YnNjcmliZSI6WyIqIl0sInB1Ymxpc2giOlsiKiJdfX0.Gfj3BFrSOFhyFN0hPOYg-Pe4dfYWOKq7QJiMWYC2Z_k";
  String hub_url = "http://mercure/hub";
  String topic = "http://mercure/test";
  hub_url = "https://mercure.wallforfry.fr/hub";
  topic = "https://mercure.wallforfry.fr/test";

  // Use this in dart or flutter project :
  Mercure mercure = Mercure(token: token, hub_url: hub_url);

  // Use this if you are in flutter web :
  // don't forget to import 'package:http/browser_client.dart';
  // Mercure mercure = Mercure(token: token, hub_url: hub_url, client: BrowserClient());

  mercure.subscribeTopics(
      topics: <String>[topic, "2"],
      onData: (MessageEvent event) {
        print(event.data);
      });

  mercure.subscribeTopic(
      topic: topic,
      onData: (MessageEvent 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
0
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

unknown (LICENSE)

Dependencies

http, meta, w3c_event_source

More

Packages that depend on dart_mercure