pusher 1.0.0

Pusher HTTP Dart Library #

Build Status Coverage Status Pub Status

The Dart library for interacting with the Pusher HTTP API.

This package lets you trigger events to your client and query the state of your Pusher channels. When used with a server, you can authenticate private- or presence-channels.

In order to use this library, you need to have a free account on http://pusher.com. After registering, you will need the application credentials for your app.

Getting Started #

import 'package:pusher/pusher.dart';

main() async {
  Pusher pusher = new Pusher('PUSHER_APP_ID','PUSHER_APP_KEY','PUSHER_APP_SECRET');
  Map data = {'message':'Hello world'};
  Response response = await pusher.trigger(['test_channel'],'my_event',data);

Configuration #

There easiest way to configure the library is by creating a new Pusher instance:

Pusher pusher = new Pusher(

Additional options #

PusherOptions options = new PusherOptions(encrypted: true);
Pusher pusher = new Pusher(

Usage #

Triggering events #

It is possible to trigger an event on one or more channels. Channel names can contain only characters which are alphanumeric, _ or `-``. Event name can be at most 200 characters long too.

 Response response = await pusher.trigger(['test_channel'],'my_event',data);

Authenticating Channels #

Pusher provides a mechanism for authenticating a user's access to a channel at the point of subscription.

This can be used both to restrict access to private channels, and in the case of presence channels notify subscribers of who else is also subscribed via presence events.

This library provides a mechanism for generating an authentication signature to send back to the client and authorize them.

For more information see docs.

Private channels

 String socketId = '74124.3251944';
 String auth = pusher.authenticate('test_channel',socketId);

Authenticating presence channels

Using presence channels is similar to private channels, but in order to identify a user, clients are sent a user_id and, optionally, custom data.

 String socketId = '74124.3251944';
 User user = new User('1',{'name':'Adao'});
 String auth = pusher.authenticate('presence-test_channel',socketId,user);

It is possible to query the state of your Pusher application using the generic pusher.get( resource ) method and overloads.

For full details see: http://pusher.com/docs/rest_api

Application state #

This library allows you to query our API to retrieve information about your application's channels, their individual properties, and, for presence-channels, the users currently subscribed to them.

List channels

You can get a list of channels that are present within your application:

Response result = await pusher.get("/channels");

You can provide additional parameters to filter the list of channels that is returned.

Response result = await pusher.get("/channels", { "filter_by_prefix" : "presence-" } );

Fetch channel information

Retrive information about a single channel:

Response result = await pusher.get("/channels/my_channel");

Fetch a list of users on a presence channel

Retrive a list of users that are on a presence channel:

Response result = await pusher.get('/channels/presence-channel/users');

Documentation #


License #

This code is free to use under the terms of the MIT license.


import 'dart:async';
import 'package:pusher/pusher.dart';

Future<void> main() async {
  Pusher pusher = new Pusher('PUSHER_APP_ID', 'PUSHER_APP_KEY', 'PUSHER_APP_SECRET');
  Map data = {'message': 'Hello world'};
  await pusher.trigger(['test_channel'], 'my_event', data);

Use this package as a library

1. Depend on it

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

  pusher: ^1.0.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:pusher/pusher.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

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

  • Dart: 2.8.4
  • pana: 0.13.13

Health suggestions

Fix lib/src/pusher.dart. (-4.89 points)

Analysis of lib/src/pusher.dart reported 10 hints, including:

line 27 col 39: Unnecessary new keyword.

line 88 col 54: Unnecessary new keyword.

line 92 col 12: Unnecessary new keyword.

line 104 col 33: Unnecessary new keyword.

line 107 col 24: Unnecessary new keyword.

Fix lib/src/validation.dart. (-3.93 points)

Analysis of lib/src/validation.dart reported 8 hints, including:

line 1 col 30: Unnecessary new keyword.

line 4 col 33: Unnecessary new keyword.

line 11 col 5: DO use curly braces for all flow control structures.

line 11 col 11: Unnecessary new keyword.

line 18 col 5: DO use curly braces for all flow control structures.

Fix lib/src/options.dart. (-0.50 points)

Analysis of lib/src/options.dart reported 1 hint:

line 14 col 32: Use = to separate a named parameter from its default value.

Fix lib/src/user.dart. (-0.50 points)

Analysis of lib/src/user.dart reported 1 hint:

line 14 col 15: Unnecessary new keyword.

Fix lib/src/utils.dart. (-0.50 points)

Analysis of lib/src/utils.dart reported 1 hint:

line 7 col 16: Unnecessary new keyword.

Maintenance issues and suggestions

Provide a file named CHANGELOG.md. (-20 points)

Changelog entries help developers follow the progress of your package. See the example generated by stagehand.

Package is getting outdated. (-37.26 points)

The package was last published 71 weeks ago.

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
crypto ^2.0.6 2.1.5
http ^0.12.0+1 0.12.1
Transitive dependencies
charcode 1.1.3
collection 1.14.13
convert 2.1.1
http_parser 3.1.4
meta 1.2.1
path 1.7.0
pedantic 1.9.1
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.2.0
Dev dependencies
test ^1.5.3