From 3e7f000c3d197084908a3cf18be57ffb44ebeee7 Mon Sep 17 00:00:00 2001 From: Matheus de Sousa Barros Date: Thu, 28 Mar 2019 17:18:58 -0300 Subject: [PATCH 1/7] Package funcional para ser usado no projeto pusher --- .gitignore | 70 +++++++++++++++++++++++++++++++++++++++++ android/build.gradle | 2 +- example/lib/main.dart | 14 ++++----- lib/pusher_flutter.dart | 5 ++- pubspec.lock | 43 +++++++++++++++++++++++++ 5 files changed, 123 insertions(+), 11 deletions(-) create mode 100644 .gitignore create mode 100644 pubspec.lock 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..5ae3efc 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.0' } diff --git a/example/lib/main.dart b/example/lib/main.dart index 5445575..5cd4b44 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,10 +119,9 @@ 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); @@ -128,8 +129,7 @@ class _MyAppState extends State { } 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..0a9c2e0 100644 --- a/lib/pusher_flutter.dart +++ b/lib/pusher_flutter.dart @@ -77,8 +77,7 @@ class PusherFlutter { 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. @@ -88,7 +87,7 @@ class PusherFlutter { .receiveBroadcastStream() .map(_connectivityStringToState); - PusherConnectionState _connectivityStringToState(String string) { + PusherConnectionState _connectivityStringToState(dynamic string) { switch (string) { case 'connecting': return PusherConnectionState.connecting; diff --git a/pubspec.lock b/pubspec.lock new file mode 100644 index 0000000..f29cf26 --- /dev/null +++ b/pubspec.lock @@ -0,0 +1,43 @@ +# Generated by pub +# See https://www.dartlang.org/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.0.0 <3.0.0" From 6bbfdcfa003c586f877312e0c2fe07e3d259b514 Mon Sep 17 00:00:00 2001 From: Aleksandar Lugonja Date: Thu, 15 Aug 2019 11:53:27 +0200 Subject: [PATCH 2/7] Removed new statements, changed method parameters to dynamic. --- lib/pusher_flutter.dart | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/pusher_flutter.dart b/lib/pusher_flutter.dart index 0a9c2e0..cefc119 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. @@ -107,14 +104,14 @@ 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); + var body = Map.from(map['body']); + return PusherMessage(map['channel'], map['event'], body); } return null; } - PusherError _toPusherError(Map map) { - return new PusherError(map['code'], map['message']); + PusherError _toPusherError(dynamic map) { + return PusherError(map['code'], map['message']); } } From 05cdc4c2aaf13255bb83deb110ef9cf022d3b3f7 Mon Sep 17 00:00:00 2001 From: Aleksandar Lugonja Date: Thu, 15 Aug 2019 13:22:47 +0200 Subject: [PATCH 3/7] Call made dynamic without parsing to objects. --- lib/pusher_flutter.dart | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/lib/pusher_flutter.dart b/lib/pusher_flutter.dart index cefc119..1bece7e 100644 --- a/lib/pusher_flutter.dart +++ b/lib/pusher_flutter.dart @@ -48,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] @@ -71,18 +70,15 @@ 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); /// 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(dynamic string) { switch (string) { @@ -102,12 +98,12 @@ class PusherFlutter { return PusherConnectionState.disconnected; } - PusherMessage _toPusherMessage(dynamic map) { - if (map is Map) { - var body = Map.from(map['body']); - return PusherMessage(map['channel'], map['event'], body); - } - return null; + dynamic _toPusherMessage(dynamic map) { + // if (map is Map) { + // var body = Map.from(map['body']); + // return PusherMessage(map['channel'], map['event'], null); + // } + return map; } PusherError _toPusherError(dynamic map) { From 3a39da365ecc426a961e45986bccd378e69c9aa3 Mon Sep 17 00:00:00 2001 From: Aleksandar Lugonja Date: Thu, 15 Aug 2019 13:40:03 +0200 Subject: [PATCH 4/7] Fixed issue for channel content received as a list of JSON objects, where this plugin was crashing because of type mismatch. --- lib/pusher_flutter.dart | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/pusher_flutter.dart b/lib/pusher_flutter.dart index 1bece7e..5fa42ab 100644 --- a/lib/pusher_flutter.dart +++ b/lib/pusher_flutter.dart @@ -70,7 +70,7 @@ 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); @@ -98,12 +98,11 @@ class PusherFlutter { return PusherConnectionState.disconnected; } - dynamic _toPusherMessage(dynamic map) { - // if (map is Map) { - // var body = Map.from(map['body']); - // return PusherMessage(map['channel'], map['event'], null); - // } - return map; + PusherMessage _toPusherMessage(dynamic map) { + if (map is Map) { + return PusherMessage(map['channel'], map['event'], map['body']); + } + return null; } PusherError _toPusherError(dynamic map) { @@ -114,7 +113,7 @@ class PusherFlutter { 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); } From 765850bec679d965c449194cb15e845a2b4fd903 Mon Sep 17 00:00:00 2001 From: Aleksandar Lugonja Date: Thu, 15 Aug 2019 13:55:46 +0200 Subject: [PATCH 5/7] Issue with wrong object initialized fixed. --- lib/pusher_flutter.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pusher_flutter.dart b/lib/pusher_flutter.dart index 5fa42ab..18bc159 100644 --- a/lib/pusher_flutter.dart +++ b/lib/pusher_flutter.dart @@ -115,7 +115,7 @@ class PusherMessage { final String eventName; 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 { From ef374de3df9e9e6248d53d2316f7c57918d5c0ac Mon Sep 17 00:00:00 2001 From: Aleksandar Lugonja Date: Wed, 28 Aug 2019 10:15:44 +0200 Subject: [PATCH 6/7] Updated pusher java library to latest version. --- android/build.gradle | 2 +- example/lib/main.dart | 2 +- pubspec.lock | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 5ae3efc..503d545 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.8.0' + compile 'com.pusher:pusher-java-client:2.0.0' } diff --git a/example/lib/main.dart b/example/lib/main.dart index 5cd4b44..45fd48e 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -124,7 +124,7 @@ class _MyAppState extends State { //pusher.subscribeAll("test_channel", ["test_event3", "test_event4"]); pusher.onMessage.listen((pusher) { - setState(() => _latestMessage = pusher.body); + setState(() => _latestMessage = pusher.jsonBody); }); } diff --git a/pubspec.lock b/pubspec.lock index f29cf26..47ac4f5 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,5 +1,5 @@ # Generated by pub -# See https://www.dartlang.org/tools/pub/glossary#lockfile +# See https://dart.dev/tools/pub/glossary#lockfile packages: collection: dependency: transitive @@ -40,4 +40,4 @@ packages: source: hosted version: "2.0.8" sdks: - dart: ">=2.0.0 <3.0.0" + dart: ">=2.2.2 <3.0.0" From 4fd95f2a7deb85acbba68c8b699877ca099fd4af Mon Sep 17 00:00:00 2001 From: Aleksandar Lugonja Date: Wed, 28 Aug 2019 10:32:09 +0200 Subject: [PATCH 7/7] Lowered down version to 1.8.2 because 2.0.0 doesn't work with Kothlin. --- android/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/build.gradle b/android/build.gradle index 503d545..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:2.0.0' + compile 'com.pusher:pusher-java-client:1.8.2' }