Unofficial pusher client for dart.
Using this package is similar to how one would use PusherJS.
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'
})
)
);
final channel = pusher.subscribe('my-channel');
eventHandler(Object data) async {
final jsonData = Map<String, Object>.from(jsonDecode(data));
}
channel.bind('my-event', eventHandler);
You can pass any data that can be converted to JSON using jsonEncode(data);
.
Map<String, String> jsonData = {};
channel.trigger('my-event', jsonData);
pusher.disconnect();