centrifuge 0.4.0

Build Status Coverage Status

Example #

Examples:

  • example\flutter_app simple chat application
  • example\console simple console application

Usage #

Create client:

import 'package:centrifuge/centrifuge.dart' as centrifuge;

final client = centrifuge.createClient("ws://localhost:8000/connection/websocket?format=protobuf");

Note that ?format=protobuf is required because this library only works with Protobuf protocol.

Connect to server:

client.connect();

Subscribe to channel:

final subscription = client.getSubscription(channel);

subscription.publishStream.listen(onEvent);
subscription.joinStream.listen(onEvent);  
subscription.leaveStream.listen(onEvent);
subscription.subscribeSuccessStream.listen(onEvent);
subscription.subscribeErrorStream.listen(onEvent);
subscription.unsubscribeStream.listen(onEvent);

subscription.subscribe();

Publish:

final output = jsonEncode({'input': message});
final data = utf8.encode(output);
await subscription.publish(data);

Feature matrix #

  • [ ] connect to server using JSON protocol format
  • [x] connect to server using Protobuf protocol format
  • [x] connect with JWT
  • [x] connect with custom header
  • [x] automatic reconnect in case of errors, network problems etc
  • [x] exponential backoff for reconnect
  • [x] connect and disconnect events
  • [x] handle disconnect reason
  • [x] subscribe on channel and handle asynchronous Publications
  • [x] handle Join and Leave messages
  • [x] handle Unsubscribe notifications
  • [ ] reconnect on subscribe timeout
  • [x] publish method of Subscription
  • [x] unsubscribe method of Subscription
  • [ ] presence method of Subscription
  • [ ] presence stats method of Subscription
  • [x] history method of Subscription
  • [ ] send asynchronous messages to server
  • [x] handle asynchronous messages from server
  • [x] send RPC commands
  • [x] publish to channel without being subscribed
  • [x] subscribe to private channels with JWT
  • [ ] connection JWT refresh
  • [ ] private channel subscription JWT refresh
  • [ ] handle connection expired error
  • [ ] handle subscription expired error
  • [x] ping/pong to find broken connection
  • [ ] message recovery mechanism

Author #

German Saprykin, saprykin.h@gmail.com

[0.4.0]

  • Breaking changes connected property removed

[0.3.0]

  • Breaking changes Changed API to avoid returning futures where they do not make sense – in connect and subscribe methods.
  • Client now uses Websocket Ping/Pong frames to find broken connection
  • Support for private channel subscription using onPrivateSub configuration callback function
  • Fix several null pointer dereferences in edge cases, throw ClientDisconnectedError when there is an attempt to send protocol request over non-connected client.
  • Fix examples where subscribe could happen before stream handlers set

[0.2.0]

  • Breaking changes Replaced subscribe method with getSubscription in Client.
  • Added reconnection.
  • Added history method to Subscription. Thanks vanelizarov.
  • Added rpc method.

[0.1.0]

  • Added authorization with JWT
  • Added subscription to private channel with JWT

[0.0.1]

  • Initial release

Use this package as a library

1. Depend on it

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


dependencies:
  centrifuge: ^0.4.0

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:centrifuge/centrifuge.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
62
Health:
Code health derived from static analysis. [more]
96
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
95
Overall:
Weighted score of the above. [more]
79
Learn more about scoring.

We analyzed this package on Jul 17, 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:centrifuge/centrifuge.dart with components: io.

Health suggestions

Fix lib/src/proto/client.pb.dart. (-3.45 points)

Analysis of lib/src/proto/client.pb.dart reported 7 hints, including:

line 806 col 7: 'pp' is deprecated and shouldn't be used.

line 919 col 7: DO use curly braces for all flow control structures.

line 1012 col 7: DO use curly braces for all flow control structures.

line 1049 col 7: DO use curly braces for all flow control structures.

line 1228 col 7: DO use curly braces for all flow control structures.

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

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

line 108 col 12: Getter doesn't override an inherited getter.

line 193 col 7: Future results in async function bodies must be awaited or marked unawaited using package:pedantic.

Maintenance suggestions

Homepage URL is insecure. (-5 points)

Update the homepage field and use a secure (https) URL.

Maintain an example.

None of the files in the package's example/ directory matches known example patterns.

Common filename patterns include main.dart, example.dart, and centrifuge.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
meta ^1.1.5 1.1.7
protobuf ^0.13.2 0.13.15
Transitive dependencies
fixnum 0.10.9
Dev dependencies
mockito ^3.0.0
test ^1.3.0

Admin