From 742cb04fa4def2bdce2121531ddc09fe8389540a Mon Sep 17 00:00:00 2001 From: Muhammad Talha Date: Sat, 29 Jun 2024 15:32:34 +0500 Subject: [PATCH] Fixed issue related to not accepting multiple values sent from Hub, changed from single params to List --- .idea/libraries/Dart_SDK.xml | 32 ++++--- .../example_lib_main_dart.xml | 2 +- .idea/workspace.xml | 84 ++++++++++++++++--- .../asdevs/signalr_flutter/SignalrApi.java | 6 +- .../signalr_flutter/SignalRFlutterPlugin.kt | 25 +++++- .../android/app/src/main/AndroidManifest.xml | 1 + example/pubspec.lock | 38 ++++----- lib/signalr_api.dart | 17 ++-- lib/signalr_flutter.dart | 6 +- lib/signalr_platform_interface.dart | 2 +- pigeons/signalr_api.dart | 2 +- pubspec.lock | 70 ++++++++-------- signalr_flutter.iml | 2 +- 13 files changed, 192 insertions(+), 95 deletions(-) diff --git a/.idea/libraries/Dart_SDK.xml b/.idea/libraries/Dart_SDK.xml index 4a1c018..7a86b34 100644 --- a/.idea/libraries/Dart_SDK.xml +++ b/.idea/libraries/Dart_SDK.xml @@ -1,17 +1,27 @@ - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + diff --git a/.idea/runConfigurations/example_lib_main_dart.xml b/.idea/runConfigurations/example_lib_main_dart.xml index 5fd9159..2697c6a 100644 --- a/.idea/runConfigurations/example_lib_main_dart.xml +++ b/.idea/runConfigurations/example_lib_main_dart.xml @@ -1,6 +1,6 @@ \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index e71bf39..e4de1eb 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,5 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + @@ -22,24 +50,56 @@ - - - - - + + + { + "associatedIndex": 7 +} + + - - + - - - - + + + + + + + + 1719645892801 + + + + + + + + - + \ No newline at end of file diff --git a/android/src/main/java/dev/asdevs/signalr_flutter/SignalrApi.java b/android/src/main/java/dev/asdevs/signalr_flutter/SignalrApi.java index 74b1c24..fb5f6cb 100644 --- a/android/src/main/java/dev/asdevs/signalr_flutter/SignalrApi.java +++ b/android/src/main/java/dev/asdevs/signalr_flutter/SignalrApi.java @@ -473,10 +473,10 @@ public void onStatusChange(@NonNull StatusChangeResult statusChangeResultArg, Re callback.reply(null); }); } - public void onNewMessage(@NonNull String hubNameArg, @NonNull String messageArg, Reply callback) { + public void onNewMessage(@NonNull String hubNameArg, @NonNull List messageArgs, Reply callback) { BasicMessageChannel channel = - new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.SignalRPlatformApi.onNewMessage", getCodec()); - channel.send(new ArrayList(Arrays.asList(hubNameArg, messageArg)), channelReply -> { + new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.SignalRPlatformApi.onNewMessage", getCodec()); + channel.send(new ArrayList(Arrays.asList(hubNameArg, messageArgs)), channelReply -> { callback.reply(null); }); } diff --git a/android/src/main/kotlin/dev/asdevs/signalr_flutter/SignalRFlutterPlugin.kt b/android/src/main/kotlin/dev/asdevs/signalr_flutter/SignalRFlutterPlugin.kt index 83aaf3f..f0bb3ad 100644 --- a/android/src/main/kotlin/dev/asdevs/signalr_flutter/SignalRFlutterPlugin.kt +++ b/android/src/main/kotlin/dev/asdevs/signalr_flutter/SignalRFlutterPlugin.kt @@ -13,6 +13,7 @@ import microsoft.aspnet.signalr.client.hubs.HubProxy import microsoft.aspnet.signalr.client.transport.LongPollingTransport import microsoft.aspnet.signalr.client.transport.ServerSentEventsTransport import java.lang.Exception +import org.json.JSONArray /** SignalrFlutterPlugin */ class SignalrFlutterPlugin : FlutterPlugin, SignalrApi.SignalRHostApi { @@ -56,12 +57,30 @@ class SignalrFlutterPlugin : FlutterPlugin, SignalrApi.SignalRHostApi { hub = connection.createHubProxy(connectionOptions.hubName) +// connectionOptions.hubMethods?.forEach { methodName -> +// hub.on(methodName, { res -> +// Handler(Looper.getMainLooper()).post { +// try { +// // Assuming res is a JSON array string containing multiple elements +// val jsonArray = JSONArray(res) +// val messageArgs = mutableListOf() +// for (i in 0 until jsonArray.length()) { +// messageArgs.add(jsonArray.getString(i)) +// } +// signalrApi.onNewMessage(methodName, messageArgs) { } +// } catch (e: Exception) { +// e.printStackTrace() +// } +// } +// }, String::class.java) +// } connectionOptions.hubMethods?.forEach { methodName -> - hub.on(methodName, { res -> + hub.on(methodName, { res1, res2 -> Handler(Looper.getMainLooper()).post { - signalrApi.onNewMessage(methodName, res) { } + val messageArgs = listOf(res1, res2) + signalrApi.onNewMessage(methodName, messageArgs) { } } - }, String::class.java) + }, String::class.java, String::class.java) } connection.connected { diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index bd31ea2..9f1b717 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -1,6 +1,7 @@ =3.2.0 <4.0.0" + dart: ">=3.3.0 <4.0.0" flutter: ">=3.19.0" diff --git a/lib/signalr_api.dart b/lib/signalr_api.dart index 3ce9d39..c1658ba 100644 --- a/lib/signalr_api.dart +++ b/lib/signalr_api.dart @@ -304,7 +304,7 @@ abstract class SignalRPlatformApi { static const MessageCodec codec = _SignalRPlatformApiCodec(); Future onStatusChange(StatusChangeResult statusChangeResult); - Future onNewMessage(String hubName, String message); + Future onNewMessage(String hubName, {List? params}); static void setup(SignalRPlatformApi? api, {BinaryMessenger? binaryMessenger}) { { @@ -341,10 +341,17 @@ abstract class SignalRPlatformApi { final String? arg_hubName = (args[0] as String?); assert(arg_hubName != null, 'Argument for dev.flutter.pigeon.SignalRPlatformApi.onNewMessage was null, expected non-null String.'); - final String? arg_message = (args[1] as String?); - assert(arg_message != null, - 'Argument for dev.flutter.pigeon.SignalRPlatformApi.onNewMessage was null, expected non-null String.'); - await api.onNewMessage(arg_hubName!, arg_message!); + List params = []; + for(var item in args) { + params.add("$item"); + } + //List params = args as List; + params.removeAt(0); + // assert(arg_message1 != null, + // 'Argument for dev.flutter.pigeon.SignalRPlatformApi.onNewMessage was null, expected non-null String.'); + // assert(arg_message2 != null, + // 'Argument for dev.flutter.pigeon.SignalRPlatformApi.onNewMessage was null, expected non-null String.'); + await api.onNewMessage(arg_hubName!, params: params); return; }); } diff --git a/lib/signalr_flutter.dart b/lib/signalr_flutter.dart index 5421f26..56d7fee 100644 --- a/lib/signalr_flutter.dart +++ b/lib/signalr_flutter.dart @@ -17,7 +17,7 @@ class SignalR extends SignalrPlatformInterface implements SignalRPlatformApi { List? hubMethods, Transport transport = Transport.auto, void Function(ConnectionStatus?)? statusChangeCallback, - void Function(String, String)? hubCallback, + void Function(String, {List? params})? hubCallback, this.connectionErrorCallback, }) : super( baseUrl, @@ -32,8 +32,8 @@ class SignalR extends SignalrPlatformInterface implements SignalRPlatformApi { //---- Callback Methods ----// // ------------------------// @override - Future onNewMessage(String hubName, String message) async { - hubCallback?.call(hubName, message); + Future onNewMessage(String hubName, {List? params}) async { + hubCallback?.call(hubName, params: params); } @override diff --git a/lib/signalr_platform_interface.dart b/lib/signalr_platform_interface.dart index b944fcd..00cc2e2 100644 --- a/lib/signalr_platform_interface.dart +++ b/lib/signalr_platform_interface.dart @@ -28,7 +28,7 @@ abstract class SignalrPlatformInterface { final void Function(ConnectionStatus?)? statusChangeCallback; /// This callback gets called whenever SignalR server sends some message to client. - final void Function(String, String)? hubCallback; + final void Function(String, {List? params})? hubCallback; /// Connect to the SignalR Server with given [baseUrl] & [hubName]. /// diff --git a/pigeons/signalr_api.dart b/pigeons/signalr_api.dart index 2a07b66..806db0f 100644 --- a/pigeons/signalr_api.dart +++ b/pigeons/signalr_api.dart @@ -52,7 +52,7 @@ abstract class SignalRPlatformApi { void onStatusChange(StatusChangeResult statusChangeResult); @async - void onNewMessage(String hubName, String message); + void onNewMessage(String hubName, String message1, String message2); } void configurePigeon(PigeonOptions opts) { diff --git a/pubspec.lock b/pubspec.lock index 9e8e4c0..674cbba 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -21,10 +21,10 @@ packages: dependency: transitive description: name: args - sha256: b003c3098049a51720352d219b0bb5f219b60fbfb68e7a4748139a06a5676515 + sha256: "7cf60b9f0cc88203c5a190b4cd62a99feea42759a7fa695010eb5de1c0b2252a" url: "https://pub.dev" source: hosted - version: "2.3.1" + version: "2.5.0" async: dependency: transitive description: @@ -77,10 +77,10 @@ packages: dependency: transitive description: name: crypto - sha256: aa274aa7774f8964e4f4f38cc994db7b6158dd36e9187aaceaddc994b35c6c67 + sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab url: "https://pub.dev" source: hosted - version: "3.0.2" + version: "3.0.3" fake_async: dependency: transitive description: @@ -93,10 +93,10 @@ packages: dependency: transitive description: name: file - sha256: "1b92bec4fc2a72f59a8e15af5f52cd441e4a7860b49499d69dfa817af20e925d" + sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c" url: "https://pub.dev" source: hosted - version: "6.1.4" + version: "7.0.0" flutter: dependency: "direct main" description: flutter @@ -106,10 +106,10 @@ packages: dependency: "direct dev" description: name: flutter_lints - sha256: aeb0b80a8b3709709c9cc496cdc027c5b3216796bc0af0ce1007eaf24464fd4c + sha256: a25a15ebbdfc33ab1cd26c63a6ee519df92338a9c10f122adda92938253bef04 url: "https://pub.dev" source: hosted - version: "2.0.1" + version: "2.0.3" flutter_test: dependency: "direct dev" description: flutter @@ -119,42 +119,42 @@ packages: dependency: transitive description: name: glob - sha256: c51b4fdfee4d281f49b8c957f1add91b815473597f76bcf07377987f66a55729 + sha256: "0e7014b3b7d4dac1ca4d6114f82bf1782ee86745b9b42a92c9289c23d8a0ab63" url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.2" leak_tracker: dependency: transitive description: name: leak_tracker - sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa" + sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a" url: "https://pub.dev" source: hosted - version: "10.0.0" + version: "10.0.4" leak_tracker_flutter_testing: dependency: transitive description: name: leak_tracker_flutter_testing - sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0 + sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8" url: "https://pub.dev" source: hosted - version: "2.0.1" + version: "3.0.3" leak_tracker_testing: dependency: transitive description: name: leak_tracker_testing - sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47 + sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3" url: "https://pub.dev" source: hosted - version: "2.0.1" + version: "3.0.1" lints: dependency: transitive description: name: lints - sha256: "5e4a9cd06d447758280a8ac2405101e0e2094d2a1dbdd3756aec3fe7775ba593" + sha256: "0a217c6c989d21039f1498c3ed9f3ed71b354e69873f13a8dfc3c9fe76f1b452" url: "https://pub.dev" source: hosted - version: "2.0.1" + version: "2.1.1" matcher: dependency: transitive description: @@ -175,10 +175,10 @@ packages: dependency: transitive description: name: meta - sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 + sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136" url: "https://pub.dev" source: hosted - version: "1.11.0" + version: "1.12.0" package_config: dependency: transitive description: @@ -199,18 +199,18 @@ packages: dependency: "direct dev" description: name: pigeon - sha256: "3d2abf23455db89416491c690ee969b7e4ba65f54e7ca303f1698c135eed5bdb" + sha256: "6136ad922578ef81f3c997d3e2814a9c09e90875a4cc99a26f165eed507efe79" url: "https://pub.dev" source: hosted - version: "4.2.5" + version: "4.2.14" pub_semver: dependency: transitive description: name: pub_semver - sha256: b959af0a045c3484c4a8f4997731f5bfe4cac60d732fd8ce35b351f2d6a459fe + sha256: "40d3ab1bbd474c4c2328c91e3a7df8c6dd629b79ece4c4bd04bee496a224fb0c" url: "https://pub.dev" source: hosted - version: "2.1.2" + version: "2.1.4" sky_engine: dependency: transitive description: flutter @@ -260,18 +260,18 @@ packages: dependency: transitive description: name: test_api - sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" + sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f" url: "https://pub.dev" source: hosted - version: "0.6.1" + version: "0.7.0" typed_data: dependency: transitive description: name: typed_data - sha256: "26f87ade979c47a150c9eaab93ccd2bebe70a27dc0b4b29517f2904f04eb11a5" + sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c url: "https://pub.dev" source: hosted - version: "1.3.1" + version: "1.3.2" vector_math: dependency: transitive description: @@ -284,26 +284,26 @@ packages: dependency: transitive description: name: vm_service - sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957 + sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec" url: "https://pub.dev" source: hosted - version: "13.0.0" + version: "14.2.1" watcher: dependency: transitive description: name: watcher - sha256: "6a7f46926b01ce81bfc339da6a7f20afbe7733eff9846f6d6a5466aa4c6667c0" + sha256: "3d2ad6751b3c16cf07c7fca317a1413b3f26530319181b37e3b9039b84fc01d8" url: "https://pub.dev" source: hosted - version: "1.0.2" + version: "1.1.0" yaml: dependency: transitive description: name: yaml - sha256: "23812a9b125b48d4007117254bca50abb6c712352927eece9e155207b1db2370" + sha256: "75769501ea3489fca56601ff33454fe45507ea3bfb014161abc3b43ae25989d5" url: "https://pub.dev" source: hosted - version: "3.1.1" + version: "3.1.2" sdks: - dart: ">=3.2.0 <4.0.0" + dart: ">=3.3.0 <4.0.0" flutter: ">=3.19.0" diff --git a/signalr_flutter.iml b/signalr_flutter.iml index 429df7d..bb93ab7 100644 --- a/signalr_flutter.iml +++ b/signalr_flutter.iml @@ -10,9 +10,9 @@ + -