pusher_dart 0.1.0+1 copy "pusher_dart: ^0.1.0+1" to clipboard
pusher_dart: ^0.1.0+1 copied to clipboard

Unofficial pusher client for dart

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';

final pusher = Pusher(
    DotEnv().env['PUSHER_APP_KEY'],
    PusherOptions(
        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();
2
likes
20
pub points
0%
popularity

Publisher

unverified uploader

Unofficial pusher client for dart

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

http, meta, web_socket_channel

More

Packages that depend on pusher_dart