Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue related to not accepting multiple values sent from Hub, c… #66

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions .idea/libraries/Dart_SDK.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/runConfigurations/example_lib_main_dart.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

84 changes: 72 additions & 12 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -473,10 +473,10 @@ public void onStatusChange(@NonNull StatusChangeResult statusChangeResultArg, Re
callback.reply(null);
});
}
public void onNewMessage(@NonNull String hubNameArg, @NonNull String messageArg, Reply<Void> callback) {
public void onNewMessage(@NonNull String hubNameArg, @NonNull List<String> messageArgs, Reply<Void> callback) {
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.SignalRPlatformApi.onNewMessage", getCodec());
channel.send(new ArrayList<Object>(Arrays.asList(hubNameArg, messageArg)), channelReply -> {
new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.SignalRPlatformApi.onNewMessage", getCodec());
channel.send(new ArrayList<Object>(Arrays.asList(hubNameArg, messageArgs)), channelReply -> {
callback.reply(null);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<String>()
// 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 {
Expand Down
1 change: 1 addition & 0 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:label="signalr_flutter_example"
android:usesCleartextTraffic="true"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
Expand Down
38 changes: 19 additions & 19 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ packages:
dependency: "direct main"
description:
name: cupertino_icons
sha256: e35129dc44c9118cee2a5603506d823bab99c68393879edb440e0090d07586be
sha256: ba631d1c7f7bef6b729a622b7b752645a2d076dba9976925b8f25725a30e1ee6
url: "https://pub.dev"
source: hosted
version: "1.0.5"
version: "1.0.8"
fake_async:
dependency: transitive
description:
Expand All @@ -66,10 +66,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
Expand All @@ -79,34 +79,34 @@ packages:
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:
Expand All @@ -127,10 +127,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"
path:
dependency: transitive
description:
Expand Down Expand Up @@ -195,10 +195,10 @@ 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"
vector_math:
dependency: transitive
description:
Expand All @@ -211,10 +211,10 @@ 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"
sdks:
dart: ">=3.2.0 <4.0.0"
dart: ">=3.3.0 <4.0.0"
flutter: ">=3.19.0"
17 changes: 12 additions & 5 deletions lib/signalr_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ abstract class SignalRPlatformApi {
static const MessageCodec<Object?> codec = _SignalRPlatformApiCodec();

Future<void> onStatusChange(StatusChangeResult statusChangeResult);
Future<void> onNewMessage(String hubName, String message);
Future<void> onNewMessage(String hubName, {List<String>? params});
static void setup(SignalRPlatformApi? api,
{BinaryMessenger? binaryMessenger}) {
{
Expand Down Expand Up @@ -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<String> params = [];
for(var item in args) {
params.add("$item");
}
//List<String> params = args as List<String>;
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;
});
}
Expand Down
6 changes: 3 additions & 3 deletions lib/signalr_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class SignalR extends SignalrPlatformInterface implements SignalRPlatformApi {
List<String>? hubMethods,
Transport transport = Transport.auto,
void Function(ConnectionStatus?)? statusChangeCallback,
void Function(String, String)? hubCallback,
void Function(String, {List<String>? params})? hubCallback,
this.connectionErrorCallback,
}) : super(
baseUrl,
Expand All @@ -32,8 +32,8 @@ class SignalR extends SignalrPlatformInterface implements SignalRPlatformApi {
//---- Callback Methods ----//
// ------------------------//
@override
Future<void> onNewMessage(String hubName, String message) async {
hubCallback?.call(hubName, message);
Future<void> onNewMessage(String hubName, {List<String>? params}) async {
hubCallback?.call(hubName, params: params);
}

@override
Expand Down
2 changes: 1 addition & 1 deletion lib/signalr_platform_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>? params})? hubCallback;

/// Connect to the SignalR Server with given [baseUrl] & [hubName].
///
Expand Down
2 changes: 1 addition & 1 deletion pigeons/signalr_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading