w3c_event_source 1.3.2

w3c_event_source #

pub package build status

W3C EventSource client implementation for Dart / Flutter.

This package depends on dart:io, so it is not usable on the Web. If you'd like to contribute a wrapper around dart:html's EventSource, feel free!

Install #

Add to your pubspec.yaml:

dependencies:
  w3c_event_source: ^1.3.2

Usage #

import 'dart:async';
import 'package:w3c_event_source/event_source.dart';

final events = EventSource(Uri.parse('http://api.example.com/ssedemo.php'));

// Listening on the `events` stream will open a connection.
final subscription = events.events.listen((MessageEvent message) {
  print('${message.name}: ${message.data}');
});

Timer(Duration(seconds: 30), () {
  // Canceling the subscription closes the connection.
  subscription.cancel();
});

License #

MIT

w3c_event_source change log #

All notable changes to this project will be documented in this file.

This project adheres to Semantic Versioning.

1.3.2 #

  • Prepare for upcoming Uint8List change to HttpClientResponse. (@tvolkert)

1.3.1 #

  • Prepare for upcoming change to HttpRequest and HttpClientResponse. (@tvolkert)

1.3.0 #

  • Delay reconnecting with randomized exponential backoff. (@mpx)
  • Reconnect after event stream request ends. (@mpx)
  • Reconnect after protocol errors (invalid UTF-8, non-200 OK status codes). (@mpx)
  • Stop event stream after 204 No Content. (@mpx)
  • Ensure resources are released for old connections. (@mpx)

1.2.2 #

  • Revert data event commit, which was a misreading of the spec. (@mpx)

1.2.1 #

  • Ensure data event data ends in \n per the spec. (@mpx)
  • Fix event name bug in multiline data messages. (@mpx)

1.2.0 #

  • Allow passing in a custom HttpClient factory. (@mpx)

1.1.0 #

  • Implement auto-reconnect.

1.0.0 #

  • Initial release.

Use this package as a library

1. Depend on it

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


dependencies:
  w3c_event_source: ^1.3.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:w3c_event_source/w3c_event_source.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
76
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
86
Learn more about scoring.

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

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms: Flutter, other

Primary library: package:w3c_event_source/w3c_event_source.dart with components: io.

Maintenance suggestions

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and w3c_event_source.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
Dev dependencies
test any