dart_mercure 0.1.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 62

Dart library for dunglas/mercure

  • 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

0.1.2 #

  • Update Readme
  • Move to Github

0.1.1 #

  • Update package description
  • Clean code with dartfmt

0.1.0 #

  • Initial version

example/dart_mercure_example.dart

import 'package:dart_mercure/dart_mercure.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";

  Mercure 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');
    }
  });
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  dart_mercure: ^0.1.2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:dart_mercure/dart_mercure.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
25
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
62
Learn more about scoring.

We analyzed this package on Dec 7, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:dart_mercure/dart_mercure.dart.

Health suggestions

Fix lib/src/dart_mercure_base.dart. (-1 points)

Analysis of lib/src/dart_mercure_base.dart reported 2 hints:

line 15 col 3: This function has a return type of 'StreamSubscription

line 30 col 3: This function has a return type of 'StreamSubscription

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.4.0 <3.0.0
eventsource ^0.2.2 0.2.2
http ^0.12.0+2 0.12.0+2
meta ^1.1.7 1.1.8
Transitive dependencies
async 2.4.0
charcode 1.1.2
collection 1.14.12
http_parser 3.1.3
logging 0.11.3+2
path 1.6.4
source_span 1.5.5
string_scanner 1.0.5
sync 0.2.0
term_glyph 1.1.0
typed_data 1.1.6
Dev dependencies
pedantic ^1.7.0 1.9.0
test ^1.6.0