Skip to content

dreamsoftin/pusher_dart

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pusher

Unofficial pusher client for dart.

Usage

Using this package is similar to how one would use PusherJS.

Initialize and connect

import 'package:pusher_dart/pusher_dart.dart';

final pusher = Pusher(
    DotEnv().env['PUSHER_APP_KEY'],
    PusherOptions(
        //host:'10.0.2.2',   //optional
        //port:6001,        //optional
        authEndpoint: DotEnv().env['PUSHER_AUTH_URL'],
        auth: PusherAuth(headers: {
          'Authorization': 'Bearer $apiToken',
          'Content-Type': 'application/json',
          'Accept': 'application/json'
        })
    )
);

Subscribe to a channel

final channel = pusher.subscribe('my-channel');

Bind to events

eventHandler(Object data) async {
    final jsonData = Map<String, Object>.from(jsonDecode(data));
}

channel.bind('my-event', eventHandler);

Trigger event on a channel

You can pass any data that can be converted to JSON using jsonEncode(data);.

Map<String, String> jsonData = {};
channel.trigger('my-event', jsonData);

Close the connection

pusher.disconnect();

About

Unofficial pusher client for dart

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 45.4%
  • Dart 30.0%
  • CMake 17.8%
  • HTML 3.4%
  • C 1.6%
  • Swift 0.9%
  • Other 0.9%