diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..07488ba --- /dev/null +++ b/.gitignore @@ -0,0 +1,70 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# Visual Studio Code related +.vscode/ + +# Flutter/Dart/Pub related +**/doc/api/ +.dart_tool/ +.flutter-plugins +.packages +.pub-cache/ +.pub/ +/build/ + +# Android related +**/android/**/gradle-wrapper.jar +**/android/.gradle +**/android/captures/ +**/android/gradlew +**/android/gradlew.bat +**/android/local.properties +**/android/**/GeneratedPluginRegistrant.java + +# iOS/XCode related +**/ios/**/*.mode1v3 +**/ios/**/*.mode2v3 +**/ios/**/*.moved-aside +**/ios/**/*.pbxuser +**/ios/**/*.perspectivev3 +**/ios/**/*sync/ +**/ios/**/.sconsign.dblite +**/ios/**/.tags* +**/ios/**/.vagrant/ +**/ios/**/DerivedData/ +**/ios/**/Icon? +**/ios/**/Pods/ +**/ios/**/.symlinks/ +**/ios/**/profile +**/ios/**/xcuserdata +**/ios/.generated/ +**/ios/Flutter/App.framework +**/ios/Flutter/Flutter.framework +**/ios/Flutter/Generated.xcconfig +**/ios/Flutter/app.flx +**/ios/Flutter/app.zip +**/ios/Flutter/flutter_assets/ +**/ios/ServiceDefinitions.json +**/ios/Runner/GeneratedPluginRegistrant.* + +# Exceptions to above rules. +!**/ios/**/default.mode1v3 +!**/ios/**/default.mode2v3 +!**/ios/**/default.pbxuser +!**/ios/**/default.perspectivev3 +!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages diff --git a/android/build.gradle b/android/build.gradle index 043611a..c8b2759 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -48,5 +48,5 @@ android { dependencies { compile 'org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-4' - compile 'com.pusher:pusher-java-client:1.5.0' + compile 'com.pusher:pusher-java-client:1.8.2' } diff --git a/example/lib/main.dart b/example/lib/main.dart index 5445575..45fd48e 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -14,7 +14,9 @@ class _MyAppState extends State { Map _latestMessage; PusherError _lastError; PusherConnectionState _connectionState; - PusherFlutter pusher = new PusherFlutter(""); + + // Ao instanciar passar o + PusherFlutter pusher = new PusherFlutter("", cluster: ""); @override initState() { @@ -27,7 +29,7 @@ class _MyAppState extends State { } }); }); - pusher.onError.listen((err) => _lastError = err); + //pusher.onError.listen((err) => _lastError = err); _connectionState = PusherConnectionState.disconnected; } @@ -117,19 +119,17 @@ class _MyAppState extends State { void connect() { pusher.connect(); - pusher.subscribe("test_channel", "test_event"); - pusher.subscribe("test_channel", "test_event2"); + pusher.subscribe("my-channel", "my-event"); - pusher.subscribeAll("test_channel", ["test_event3", "test_event4"]); + //pusher.subscribeAll("test_channel", ["test_event3", "test_event4"]); pusher.onMessage.listen((pusher) { - setState(() => _latestMessage = pusher.body); + setState(() => _latestMessage = pusher.jsonBody); }); } void disconnect() { - pusher.unsubscribe("test_channel"); - pusher.unsubscribe("test_channel2"); + pusher.unsubscribe("my-channel"); pusher.disconnect(); } } diff --git a/lib/pusher_flutter.dart b/lib/pusher_flutter.dart index 92821bb..18bc159 100644 --- a/lib/pusher_flutter.dart +++ b/lib/pusher_flutter.dart @@ -21,18 +21,15 @@ class PusherFlutter { /// /// The [apiKey] may not be null. PusherFlutter(String apiKey, {String cluster}) { - _channel = new MethodChannel('plugins.apptreesoftware.com/pusher'); + _channel = MethodChannel('plugins.apptreesoftware.com/pusher'); var args = {"api_key": apiKey}; if (cluster != null) { args["cluster"] = cluster; } _channel.invokeMethod('create', args); - _connectivityEventChannel = - new EventChannel('plugins.apptreesoftware.com/pusher_connection'); - _messageChannel = - new EventChannel('plugins.apptreesoftware.com/pusher_message'); - _errorChannel = - new EventChannel('plugins.apptreesoftware.com/pusher_error'); + _connectivityEventChannel = EventChannel('plugins.apptreesoftware.com/pusher_connection'); + _messageChannel = EventChannel('plugins.apptreesoftware.com/pusher_message'); + _errorChannel = EventChannel('plugins.apptreesoftware.com/pusher_error'); } /// Connect to the pusher service. @@ -51,8 +48,7 @@ class PusherFlutter { /// provided to be delivered to the [onMessage] method. After calling this you /// must listen to the [Stream] returned from [onMessage]. void subscribe(String channelName, String event) { - _channel - .invokeMethod('subscribe', {"channel": channelName, "event": event}); + _channel.invokeMethod('subscribe', {"channel": channelName, "event": event}); } /// Subscribe to the channel [channelName] for each [eventName] in [events] @@ -74,21 +70,17 @@ class PusherFlutter { /// Get the [Stream] of [PusherMessage] for the channels and events you've /// signed up for. /// - Stream get onMessage => - _messageChannel.receiveBroadcastStream().map(_toPusherMessage); + Stream get onMessage => _messageChannel.receiveBroadcastStream().map(_toPusherMessage); - Stream get onError => - _errorChannel.receiveBroadcastStream().map(_toPusherError); + Stream get onError => _errorChannel.receiveBroadcastStream().map(_toPusherError); /// Get a [Stream] of [PusherConnectionState] events. /// Use this method to get notified about connection-related information. /// - Stream get onConnectivityChanged => - _connectivityEventChannel - .receiveBroadcastStream() - .map(_connectivityStringToState); + Stream get onConnectivityChanged => + _connectivityEventChannel.receiveBroadcastStream().map(_connectivityStringToState); - PusherConnectionState _connectivityStringToState(String string) { + PusherConnectionState _connectivityStringToState(dynamic string) { switch (string) { case 'connecting': return PusherConnectionState.connecting; @@ -108,23 +100,22 @@ class PusherFlutter { PusherMessage _toPusherMessage(dynamic map) { if (map is Map) { - var body = new Map.from(map['body']); - return new PusherMessage(map['channel'], map['event'], body); + return PusherMessage(map['channel'], map['event'], map['body']); } return null; } - PusherError _toPusherError(Map map) { - return new PusherError(map['code'], map['message']); + PusherError _toPusherError(dynamic map) { + return PusherError(map['code'], map['message']); } } class PusherMessage { final String channelName; final String eventName; - final Map body; + final dynamic jsonBody; // This body can be either JSON object or a list of JSON objects - PusherMessage(this.channelName, this.eventName, this.body); + PusherMessage(this.channelName, this.eventName, this.jsonBody); } class PusherError { diff --git a/pubspec.lock b/pubspec.lock new file mode 100644 index 0000000..47ac4f5 --- /dev/null +++ b/pubspec.lock @@ -0,0 +1,43 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + collection: + dependency: transitive + description: + name: collection + url: "https://pub.dartlang.org" + source: hosted + version: "1.14.11" + flutter: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" + meta: + dependency: transitive + description: + name: meta + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.6" + sky_engine: + dependency: transitive + description: flutter + source: sdk + version: "0.0.99" + typed_data: + dependency: transitive + description: + name: typed_data + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.6" + vector_math: + dependency: transitive + description: + name: vector_math + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.8" +sdks: + dart: ">=2.2.2 <3.0.0"