Viewing version 0.4.1. Open the latest package page.

centrifuge

0.4.1

Dart client to communicate with Centrifuge and Centrifugo from Flutter and VM over dart:io WebSocket

Download archive

Readme

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();

Note that .connect() method is asynchronous. This means that client will be properly connected and authenticated on server at some point in future. To handle connect and disconnect events you can listen to connectStream and disconnectStream:

client.connectStream.listen(onEvent);
client.disconnectStream.listen(onEvent);
client.connect();

Connect and disconnect events can happen many times throughout client lifetime.

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

Author

German Saprykin, saprykin.h@gmail.com

Changelog

[0.4.1]

  • Implement removeSubscription method, thanks @tiamo

[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

Installing

export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add 'centrifuge:0.4.1'
pubspec.yaml
name: centrifuge
version: 0.4.1

description: >
  Dart client to communicate with Centrifuge and Centrifugo from Flutter and VM over dart:io WebSocket

author: German Saprykin <saprykin.h@gmail.com>
homepage: http://github.com/centrifugal/centrifuge-dart

environment:
 sdk: '>=2.0.0  <3.0.0'

dependencies:
 meta: ^1.1.5
 protobuf: ^0.13.2

dev_dependencies:
  test: ^1.3.0
  mockito: ^3.0.0

Version history

VersionPublishedArchiveSHA-256
0.0.1Cached · Upstream SHA-256 matchedDownloaddb3faacd…bd6395
0.1.0Cached · Upstream SHA-256 matchedDownload09f7e4de…6b0b62
0.2.0Cached · Upstream SHA-256 matchedDownload23bb4439…ea7ae6
0.3.0Cached · Upstream SHA-256 matchedDownload3b377680…8aab61
0.4.0Cached · Upstream SHA-256 matchedDownload08e6f397…213fbc
0.4.1Cached · Upstream SHA-256 matchedDownload6bb61dec…98094b
0.5.0Cached · Upstream SHA-256 matchedDownloadfd063805…d18ae1
0.5.1Cached · Upstream SHA-256 matchedDownload60d5f869…941458
0.6.0Cached · Upstream SHA-256 matchedDownloadd219ec9a…037c10
0.7.0Cached · Upstream SHA-256 matchedDownload6548eff6…235e80
0.7.1Cached · Upstream SHA-256 matchedDownload56407e60…13ad2c
0.8.0Cached · Upstream SHA-256 matchedDownload5ac2b57e…b7620a
0.9.0Cached · Upstream SHA-256 matchedDownload1f281a39…016252
0.9.1Cached · Upstream SHA-256 matchedDownload0b9abe02…7ab142
0.9.2Cached · Upstream SHA-256 matchedDownloadc261d991…360df3
0.9.3Cached · Upstream SHA-256 matchedDownload4cd31b8b…bd7d34
0.9.4Cached · Upstream SHA-256 matchedDownloadfda87da9…272ec3
0.10.0Cached · Upstream SHA-256 matchedDownloada278ecc0…d447b3
0.11.0Cached · Upstream SHA-256 matchedDownload26bc8e36…65c5ec
0.12.0Cached · Upstream SHA-256 matchedDownload8a836da8…ea9aef
0.13.0Cached · Upstream SHA-256 matchedDownload8cea9670…6c71c8
0.14.0Cached · Upstream SHA-256 matchedDownloadc35b75c7…4e4d47
0.14.1Cached · Upstream SHA-256 matchedDownload15b9aabc…7e2516
0.15.0Cached · Upstream SHA-256 matchedDownloadbc4e20bc…a8eb01
0.15.1Cached · Upstream SHA-256 matchedDownloadbcd1e205…ccdf09
0.16.0Cached · Upstream SHA-256 matchedDownloadb8b3d3c6…522a6d
0.17.0Cached · Upstream SHA-256 matchedDownload96050368…f97c73
0.18.0Cached · Upstream SHA-256 matchedDownloadfa943928…f530ba
0.19.0Cached · Upstream SHA-256 matchedDownload672d21fa…77253d
0.19.1Cached · Upstream SHA-256 matchedDownload27808466…6446ea
0.20.0Cached · Upstream SHA-256 matchedDownloadfae4f687…b2bc6a
0.20.1Cached · Upstream SHA-256 matchedDownload5f172511…1e177d
0.21.0Cached · Upstream SHA-256 matchedDownload7449dc56…2b7969

Dependencies

meta "^1.1.5"

protobuf "^0.13.2"