Skip to content
Dart library for dunglas/mercure
Dart
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
example
lib
test
.gitignore
.gitlab-ci.yml
CHANGELOG.md
LICENSE
README.md
analysis_options.yaml
pubspec.yaml

README.md

Dart library for dunglas/mercure

pipeline status pub package

  • This library allow to communicate with dunglas/mercure.
  • You can publish and subscribe to topic on Mercure Hub.
  • It can be easily integrate with other package for create firebase like notification system.

license.

Usage

A basic usage example of publish/subscribe :

import 'package:dart_mercure/dart_mercure.dart';

main() {

  // Token generate with "mercure" JWT_KEY
  String token = "YOUR_JWT_TOKEN";
  String hub_url = "http://MERCURE_HUB_URL/hub";
  String topic = "http://YOUR_TOPIC/FOO";

  Mercure mercure = Mercure(token: token, hub_url: hub_url);

  // Subscribes to topics
  mercure.subscribeTopics(topics: <String> [topic, "ANOTHER_TOPIC"], onData: (Event event) {
    print(event.data);
  });

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

  // Publish on topic
  mercure.publish(topic: topic, data: "DATA").then((status) {
    if(status == 200) {
      print("Message Sent");
    }
    else {
      print('Message Failed with code : $status');
    }
  });
}

Features and bugs

Please file feature requests and bugs at the issue tracker

You can’t perform that action at this time.