From 11d4a592fe1c552c6351f2130d812b20a16c72d9 Mon Sep 17 00:00:00 2001 From: evgeny Date: Mon, 26 Feb 2024 10:16:20 +0000 Subject: [PATCH 01/13] fix: add `createRecoveryKey` method --- .../ably/flutter/plugin/AblyMethodCallHandler.java | 14 ++++++++++---- .../plugin/generated/PlatformConstants.java | 3 +++ ios/Classes/AblyFlutter.m | 10 ++++++++++ ios/Classes/codec/AblyPlatformConstants.h | 3 +++ ios/Classes/codec/AblyPlatformConstants.m | 3 +++ lib/src/generated/platform_constants.dart | 3 +++ lib/src/platform/src/realtime/connection.dart | 9 +++++++++ 7 files changed, 41 insertions(+), 4 deletions(-) diff --git a/android/src/main/java/io/ably/flutter/plugin/AblyMethodCallHandler.java b/android/src/main/java/io/ably/flutter/plugin/AblyMethodCallHandler.java index 2d90d3571..7ce21c930 100644 --- a/android/src/main/java/io/ably/flutter/plugin/AblyMethodCallHandler.java +++ b/android/src/main/java/io/ably/flutter/plugin/AblyMethodCallHandler.java @@ -112,6 +112,9 @@ public AblyMethodCallHandler(final MethodChannel methodChannel, _map.put(PlatformConstants.PlatformMethod.restAuthGetClientId, (methodCall, result) -> authMethodHandler.clientId(methodCall, result, AuthMethodHandler.Type.Rest)); + // Connection specific handlers + _map.put(PlatformConstants.PlatformMethod.connectionRecoveryKey, this::connectionRecoveryKey); + // Push Notifications _map.put(PlatformConstants.PlatformMethod.pushActivate, this::pushActivate); _map.put(PlatformConstants.PlatformMethod.pushDeactivate, this::pushDeactivate); @@ -551,14 +554,17 @@ private void realtimeTime(@NonNull MethodCall methodCall, @NonNull MethodChannel time(result, instanceStore.getRealtime(ablyMessage.handle)); } - - - - private void restTime(@NonNull MethodCall methodCall, @NonNull MethodChannel.Result result) { + private void restTime(@NonNull MethodCall methodCall, @NonNull MethodChannel.Result result) { final AblyFlutterMessage ablyMessage = (AblyFlutterMessage) methodCall.arguments; time(result, instanceStore.getRest(ablyMessage.handle)); } + private void connectionRecoveryKey(@NonNull MethodCall methodCall, @NonNull MethodChannel.Result result) { + final AblyFlutterMessage ablyMessage = (AblyFlutterMessage) methodCall.arguments; + AblyRealtime realtime = instanceStore.getRealtime(ablyMessage.handle); + result.success(realtime.connection.recoveryKey); + } + private void time(@NonNull MethodChannel.Result result, AblyBase client) { Callback callback = new Callback() { @Override diff --git a/android/src/main/java/io/ably/flutter/plugin/generated/PlatformConstants.java b/android/src/main/java/io/ably/flutter/plugin/generated/PlatformConstants.java index 18be4726a..eabf5f49b 100644 --- a/android/src/main/java/io/ably/flutter/plugin/generated/PlatformConstants.java +++ b/android/src/main/java/io/ably/flutter/plugin/generated/PlatformConstants.java @@ -77,6 +77,9 @@ static final public class PlatformMethod { public static final String realtimeAuthCreateTokenRequest = "realtimeAuthCreateTokenRequest"; public static final String realtimeAuthRequestToken = "realtimeAuthRequestToken"; public static final String realtimeAuthGetClientId = "realtimeAuthGetClientId"; + + public static final String connectionRecoveryKey = "connectionRecoveryKey"; + public static final String pushActivate = "pushActivate"; public static final String pushDeactivate = "pushDeactivate"; public static final String pushReset = "pushReset"; diff --git a/ios/Classes/AblyFlutter.m b/ios/Classes/AblyFlutter.m index e465407d8..87502e265 100644 --- a/ios/Classes/AblyFlutter.m +++ b/ios/Classes/AblyFlutter.m @@ -599,6 +599,14 @@ -(void)reset; }]; }; +static const FlutterHandler _connectionRecoveryKey = ^void(AblyFlutter *const ably, FlutterMethodCall *const call, const FlutterResult result) { + AblyFlutterMessage *const ablyMessage = call.arguments; + AblyInstanceStore *const instanceStore = [ably instanceStore]; + ARTRealtime *const realtime = [instanceStore realtimeFrom:ablyMessage.handle]; + NSString *const connectionRecoveryKey = [realtime.connection recoveryKey]; + result(connectionRecoveryKey); +}; + static const FlutterHandler _getNextPage = ^void(AblyFlutter *const ably, FlutterMethodCall *const call, const FlutterResult result) { AblyFlutterMessage *const ablyMessage = call.arguments; @@ -741,6 +749,8 @@ -(instancetype)initWithChannel:(FlutterMethodChannel *const)channel AblyPlatformMethod_releaseRealtimeChannel: _releaseRealtimeChannel, AblyPlatformMethod_realtimeTime:_realtimeTime, AblyPlatformMethod_restTime:_restTime, + // Connection fields + AblyPlatformMethod_connectionRecoveryKey:_connectionRecoveryKey, // Push Notifications AblyPlatformMethod_pushActivate: PushHandlers.activate, AblyPlatformMethod_pushRequestPermission: PushHandlers.requestPermission, diff --git a/ios/Classes/codec/AblyPlatformConstants.h b/ios/Classes/codec/AblyPlatformConstants.h index ba6253f10..519724416 100644 --- a/ios/Classes/codec/AblyPlatformConstants.h +++ b/ios/Classes/codec/AblyPlatformConstants.h @@ -75,6 +75,9 @@ extern NSString *const AblyPlatformMethod_realtimeAuthAuthorize; extern NSString *const AblyPlatformMethod_realtimeAuthCreateTokenRequest; extern NSString *const AblyPlatformMethod_realtimeAuthRequestToken; extern NSString *const AblyPlatformMethod_realtimeAuthGetClientId; + +extern NSString *const AblyPlatformMethod_connectionRecoveryKey; + extern NSString *const AblyPlatformMethod_pushActivate; extern NSString *const AblyPlatformMethod_pushDeactivate; extern NSString *const AblyPlatformMethod_pushReset; diff --git a/ios/Classes/codec/AblyPlatformConstants.m b/ios/Classes/codec/AblyPlatformConstants.m index 9f4761111..8bc169129 100644 --- a/ios/Classes/codec/AblyPlatformConstants.m +++ b/ios/Classes/codec/AblyPlatformConstants.m @@ -44,6 +44,9 @@ NSString *const AblyPlatformMethod_realtimeAuthCreateTokenRequest= @"realtimeAuthCreateTokenRequest"; NSString *const AblyPlatformMethod_realtimeAuthRequestToken= @"realtimeAuthRequestToken"; NSString *const AblyPlatformMethod_realtimeAuthGetClientId= @"realtimeAuthGetClientId"; + +NSString *const AblyPlatformMethod_connectionRecoveryKey = @"connectionRecoveryKey"; + NSString *const AblyPlatformMethod_pushActivate= @"pushActivate"; NSString *const AblyPlatformMethod_pushDeactivate= @"pushDeactivate"; NSString *const AblyPlatformMethod_pushReset= @"pushReset"; diff --git a/lib/src/generated/platform_constants.dart b/lib/src/generated/platform_constants.dart index e8f113192..453b50c17 100644 --- a/lib/src/generated/platform_constants.dart +++ b/lib/src/generated/platform_constants.dart @@ -76,6 +76,9 @@ class PlatformMethod { 'realtimeAuthCreateTokenRequest'; static const String realtimeAuthRequestToken = 'realtimeAuthRequestToken'; static const String realtimeAuthGetClientId = 'realtimeAuthGetClientId'; + + static const String connectionRecoveryKey = 'connectionRecoveryKey'; + static const String pushActivate = 'pushActivate'; static const String pushDeactivate = 'pushDeactivate'; static const String pushReset = 'pushReset'; diff --git a/lib/src/platform/src/realtime/connection.dart b/lib/src/platform/src/realtime/connection.dart index 26881be46..bb653a7b2 100644 --- a/lib/src/platform/src/realtime/connection.dart +++ b/lib/src/platform/src/realtime/connection.dart @@ -55,8 +55,17 @@ class Connection extends PlatformObject { /// /// See [connection state recover options](https://ably.com/docs/realtime/connection#connection-state-recover-options) /// for more information. + @Deprecated('Use createRecoveryKey instead') String? recoveryKey; + /// The createRecoveryKey returns key string can be used by another client to + /// recover this connection's state in the recover client options property. + /// + /// See [connection state recover options](https://ably.com/docs/realtime/connection#connection-state-recover-options) + /// for more information. + Future createRecoveryKey() => + invoke(PlatformMethod.connectionRecoveryKey); + /// The serial number of the last message to be received on this connection, /// used automatically by the library when recovering or resuming a /// connection. From e0d44178b6cf2db567c31ff322e654a5595a6c66 Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Tue, 27 Feb 2024 16:18:34 +0530 Subject: [PATCH 02/13] Upgraded android depdendency to include support for java no connection serial --- android/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/build.gradle b/android/build.gradle index a60ef6170..878821fff 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -23,7 +23,7 @@ apply plugin: 'com.android.library' dependencies { // https://github.com/ably/ably-java/ - implementation 'io.ably:ably-android:1.2.33' + implementation 'io.ably:ably-android:1.2.34' // https://firebase.google.com/docs/cloud-messaging/android/client implementation 'com.google.firebase:firebase-messaging:23.0.4' From b46bc23b076ecc77465bb960b28f4266e6e8090b Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Tue, 27 Feb 2024 16:19:31 +0530 Subject: [PATCH 03/13] upgraded ios podspec files to add support for no-connection-serial --- example/ios/Podfile.lock | 4 ++-- ios/ably_flutter.podspec | 2 +- test_integration/ios/Podfile.lock | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index ddcf4a9ee..6a9f8b7e1 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -1,9 +1,9 @@ PODS: - - Ably (1.2.24): + - Ably (1.2.25): - AblyDeltaCodec (= 1.3.3) - msgpack (= 0.4.0) - ably_flutter (1.2.26): - - Ably (= 1.2.24) + - Ably (= 1.2.25) - Flutter - AblyDeltaCodec (1.3.3) - device_info_plus (0.0.1): diff --git a/ios/ably_flutter.podspec b/ios/ably_flutter.podspec index bfdbc0721..c331a8c59 100644 --- a/ios/ably_flutter.podspec +++ b/ios/ably_flutter.podspec @@ -18,7 +18,7 @@ Pod::Spec.new do |s| s.source_files = 'Classes/**/*' s.public_header_files = 'Classes/**/*.h' s.dependency 'Flutter' - s.dependency 'Ably', '1.2.24' + s.dependency 'Ably', '1.2.25' s.platform = :ios s.ios.deployment_target = '10.0' diff --git a/test_integration/ios/Podfile.lock b/test_integration/ios/Podfile.lock index cb58e2458..6d7658b71 100644 --- a/test_integration/ios/Podfile.lock +++ b/test_integration/ios/Podfile.lock @@ -1,9 +1,9 @@ PODS: - - Ably (1.2.24): + - Ably (1.2.25): - AblyDeltaCodec (= 1.3.3) - msgpack (= 0.4.0) - ably_flutter (1.2.26): - - Ably (= 1.2.24) + - Ably (= 1.2.25) - Flutter - AblyDeltaCodec (1.3.3) - Flutter (1.0.0) From 79384021a2dd61b660577494023485c21f754f14 Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Tue, 27 Feb 2024 16:24:59 +0530 Subject: [PATCH 04/13] Upgraded createRecoveryKey call for AblyMethodCallHandler --- .../main/java/io/ably/flutter/plugin/AblyMethodCallHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/src/main/java/io/ably/flutter/plugin/AblyMethodCallHandler.java b/android/src/main/java/io/ably/flutter/plugin/AblyMethodCallHandler.java index 7ce21c930..9be6c3aa0 100644 --- a/android/src/main/java/io/ably/flutter/plugin/AblyMethodCallHandler.java +++ b/android/src/main/java/io/ably/flutter/plugin/AblyMethodCallHandler.java @@ -562,7 +562,7 @@ private void restTime(@NonNull MethodCall methodCall, @NonNull MethodChannel.Res private void connectionRecoveryKey(@NonNull MethodCall methodCall, @NonNull MethodChannel.Result result) { final AblyFlutterMessage ablyMessage = (AblyFlutterMessage) methodCall.arguments; AblyRealtime realtime = instanceStore.getRealtime(ablyMessage.handle); - result.success(realtime.connection.recoveryKey); + result.success(realtime.connection.createRecovertKey()); } private void time(@NonNull MethodChannel.Result result, AblyBase client) { From a2bbd8a548d0744cf658b28d5ad4b932d81e9ee0 Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Tue, 27 Feb 2024 16:29:32 +0530 Subject: [PATCH 05/13] Added code for creating a recoveryKey in iOS as per protocol 2.0 --- ios/Classes/AblyFlutter.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/Classes/AblyFlutter.m b/ios/Classes/AblyFlutter.m index 87502e265..d02602b20 100644 --- a/ios/Classes/AblyFlutter.m +++ b/ios/Classes/AblyFlutter.m @@ -603,7 +603,7 @@ -(void)reset; AblyFlutterMessage *const ablyMessage = call.arguments; AblyInstanceStore *const instanceStore = [ably instanceStore]; ARTRealtime *const realtime = [instanceStore realtimeFrom:ablyMessage.handle]; - NSString *const connectionRecoveryKey = [realtime.connection recoveryKey]; + NSString *const connectionRecoveryKey = [realtime.connection createRecoveryKey]; result(connectionRecoveryKey); }; From e51f1461babce01a41324ff8728d3107ccc01f7a Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Wed, 28 Feb 2024 15:33:54 +0530 Subject: [PATCH 06/13] Fixed bug for creating a recovery key --- .../main/java/io/ably/flutter/plugin/AblyMethodCallHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/src/main/java/io/ably/flutter/plugin/AblyMethodCallHandler.java b/android/src/main/java/io/ably/flutter/plugin/AblyMethodCallHandler.java index 9be6c3aa0..368e8e1dc 100644 --- a/android/src/main/java/io/ably/flutter/plugin/AblyMethodCallHandler.java +++ b/android/src/main/java/io/ably/flutter/plugin/AblyMethodCallHandler.java @@ -562,7 +562,7 @@ private void restTime(@NonNull MethodCall methodCall, @NonNull MethodChannel.Res private void connectionRecoveryKey(@NonNull MethodCall methodCall, @NonNull MethodChannel.Result result) { final AblyFlutterMessage ablyMessage = (AblyFlutterMessage) methodCall.arguments; AblyRealtime realtime = instanceStore.getRealtime(ablyMessage.handle); - result.success(realtime.connection.createRecovertKey()); + result.success(realtime.connection.createRecoveryKey()); } private void time(@NonNull MethodChannel.Result result, AblyBase client) { From 70c5d4c52e8816e0d43352bbf30c87bf20ed7aad Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Tue, 5 Mar 2024 01:38:30 +0530 Subject: [PATCH 07/13] Updated ably-android version to latest 1.2.35 --- android/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/build.gradle b/android/build.gradle index 878821fff..e56d4b71f 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -23,7 +23,7 @@ apply plugin: 'com.android.library' dependencies { // https://github.com/ably/ably-java/ - implementation 'io.ably:ably-android:1.2.34' + implementation 'io.ably:ably-android:1.2.35' // https://firebase.google.com/docs/cloud-messaging/android/client implementation 'com.google.firebase:firebase-messaging:23.0.4' From 9ce64d131e2fc7d492f074f4a452751c2f290f70 Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Tue, 5 Mar 2024 10:23:56 +0530 Subject: [PATCH 08/13] changed log level from verbose to error --- .../lib/test/realtime/realtime_auth_client_id_test.dart | 2 +- .../lib/test/realtime/realtime_auth_url_test.dart | 4 ++-- .../lib/test/realtime/realtime_authorize_test.dart | 2 +- .../lib/test/realtime/realtime_encrypted_publish_test.dart | 2 +- test_integration/lib/test/realtime/realtime_history_test.dart | 2 +- .../realtime/realtime_history_with_auth_callback_test.dart | 2 +- .../test/realtime/realtime_presence_enter_update_leave.dart | 2 +- test_integration/lib/test/realtime/realtime_presence_get.dart | 2 +- .../lib/test/realtime/realtime_presence_history_test.dart | 2 +- .../lib/test/realtime/realtime_presence_subscribe.dart | 2 +- test_integration/lib/test/realtime/realtime_publish_test.dart | 4 ++-- .../realtime/realtime_publish_with_auth_callback_test.dart | 2 +- test_integration/lib/test/realtime/realtime_time_test.dart | 2 +- test_integration/lib/test/rest/rest_auth_client_id_test.dart | 2 +- test_integration/lib/test/rest/rest_authorize_test.dart | 2 +- test_integration/lib/test/rest/rest_capability_test.dart | 2 +- .../lib/test/rest/rest_create_token_request_test.dart | 2 +- .../lib/test/rest/rest_encrypted_publish_test.dart | 4 ++-- test_integration/lib/test/rest/rest_history_test.dart | 2 +- .../lib/test/rest/rest_history_with_auth_callback_test.dart | 2 +- test_integration/lib/test/rest/rest_presence_get_test.dart | 2 +- .../lib/test/rest/rest_presence_history_test.dart | 2 +- test_integration/lib/test/rest/rest_publish_test.dart | 4 ++-- .../lib/test/rest/rest_publish_with_auth_callback_test.dart | 2 +- test_integration/lib/test/rest/rest_request_token_test.dart | 4 ++-- test_integration/lib/test/rest/rest_time_test.dart | 2 +- 26 files changed, 31 insertions(+), 31 deletions(-) diff --git a/test_integration/lib/test/realtime/realtime_auth_client_id_test.dart b/test_integration/lib/test/realtime/realtime_auth_client_id_test.dart index e94781380..9575bc6d4 100644 --- a/test_integration/lib/test/realtime/realtime_auth_client_id_test.dart +++ b/test_integration/lib/test/realtime/realtime_auth_client_id_test.dart @@ -13,7 +13,7 @@ Future> testRealtimeAuthClientId({ final clientOptionsForToken = ClientOptions( key: appKey, environment: 'sandbox', - logLevel: LogLevel.verbose, + logLevel: LogLevel.error, ); final ablyForToken = Rest( diff --git a/test_integration/lib/test/realtime/realtime_auth_url_test.dart b/test_integration/lib/test/realtime/realtime_auth_url_test.dart index 8aacb9878..cea621364 100644 --- a/test_integration/lib/test/realtime/realtime_auth_url_test.dart +++ b/test_integration/lib/test/realtime/realtime_auth_url_test.dart @@ -16,7 +16,7 @@ Future> testCreateRealtimeWithAuthUrl({ final clientOptionsForToken = ClientOptions( key: appKey, environment: 'sandbox', - logLevel: LogLevel.verbose, + logLevel: LogLevel.error, fallbackHosts: ['a.ably-realtime.com', 'b.ably-realtime.com'], ); @@ -32,7 +32,7 @@ Future> testCreateRealtimeWithAuthUrl({ environment: 'sandbox', useTokenAuth: true, autoConnect: false, - logLevel: LogLevel.verbose); + logLevel: LogLevel.error); final realtime = Realtime(options: options); final completer = Completer(); realtime.connection.on().listen((stateChange) { diff --git a/test_integration/lib/test/realtime/realtime_authorize_test.dart b/test_integration/lib/test/realtime/realtime_authorize_test.dart index b85136b0a..c7497c16c 100644 --- a/test_integration/lib/test/realtime/realtime_authorize_test.dart +++ b/test_integration/lib/test/realtime/realtime_authorize_test.dart @@ -13,7 +13,7 @@ Future> testRealtimeAuthroize({ final clientOptionsForToken = ClientOptions( key: appKey, environment: 'sandbox', - logLevel: LogLevel.verbose, + logLevel: LogLevel.error, ); final ablyForToken = Rest( diff --git a/test_integration/lib/test/realtime/realtime_encrypted_publish_test.dart b/test_integration/lib/test/realtime/realtime_encrypted_publish_test.dart index 0354fab78..dee384131 100644 --- a/test_integration/lib/test/realtime/realtime_encrypted_publish_test.dart +++ b/test_integration/lib/test/realtime/realtime_encrypted_publish_test.dart @@ -52,7 +52,7 @@ Future> testRealtimeEncryptedPublishSpec({ key: appKey, environment: 'sandbox', clientId: clientId, - logLevel: LogLevel.verbose, + logLevel: LogLevel.error, ), ); diff --git a/test_integration/lib/test/realtime/realtime_history_test.dart b/test_integration/lib/test/realtime/realtime_history_test.dart index a99029fc6..f514a52b9 100644 --- a/test_integration/lib/test/realtime/realtime_history_test.dart +++ b/test_integration/lib/test/realtime/realtime_history_test.dart @@ -17,7 +17,7 @@ Future> testRealtimeHistory({ key: appKey, environment: 'sandbox', clientId: 'someClientId', - logLevel: LogLevel.verbose, + logLevel: LogLevel.error, ), ); final channel = realtime.channels.get('test'); diff --git a/test_integration/lib/test/realtime/realtime_history_with_auth_callback_test.dart b/test_integration/lib/test/realtime/realtime_history_with_auth_callback_test.dart index 85a69e0a1..4bfe35013 100644 --- a/test_integration/lib/test/realtime/realtime_history_with_auth_callback_test.dart +++ b/test_integration/lib/test/realtime/realtime_history_with_auth_callback_test.dart @@ -13,7 +13,7 @@ Future> testRealtimeHistoryWithAuthCallback({ final realtime = Realtime( options: ClientOptions( clientId: 'someClientId', - logLevel: LogLevel.verbose, + logLevel: LogLevel.error, authCallback: (params) async { authCallbackInvoked = true; return TokenRequest.fromMap( diff --git a/test_integration/lib/test/realtime/realtime_presence_enter_update_leave.dart b/test_integration/lib/test/realtime/realtime_presence_enter_update_leave.dart index ee7baf954..94b8699cf 100644 --- a/test_integration/lib/test/realtime/realtime_presence_enter_update_leave.dart +++ b/test_integration/lib/test/realtime/realtime_presence_enter_update_leave.dart @@ -14,7 +14,7 @@ ClientOptions getClientOptions( key: appKey, environment: 'sandbox', clientId: clientId, - logLevel: LogLevel.verbose, + logLevel: LogLevel.error, ); Future> testRealtimePresenceEnterUpdateLeave({ diff --git a/test_integration/lib/test/realtime/realtime_presence_get.dart b/test_integration/lib/test/realtime/realtime_presence_get.dart index 327938a09..95adb8cd7 100644 --- a/test_integration/lib/test/realtime/realtime_presence_get.dart +++ b/test_integration/lib/test/realtime/realtime_presence_get.dart @@ -15,7 +15,7 @@ ClientOptions getClientOptions( key: appKey, environment: 'sandbox', clientId: clientId, - logLevel: LogLevel.verbose, + logLevel: LogLevel.error, ); Future> testRealtimePresenceGet({ diff --git a/test_integration/lib/test/realtime/realtime_presence_history_test.dart b/test_integration/lib/test/realtime/realtime_presence_history_test.dart index 68a752e88..530a6d9f4 100644 --- a/test_integration/lib/test/realtime/realtime_presence_history_test.dart +++ b/test_integration/lib/test/realtime/realtime_presence_history_test.dart @@ -17,7 +17,7 @@ Future> testRealtimePresenceHistory({ key: appKey, environment: 'sandbox', clientId: 'someClientId', - logLevel: LogLevel.verbose, + logLevel: LogLevel.error, ); final realtime = Realtime(options: options); diff --git a/test_integration/lib/test/realtime/realtime_presence_subscribe.dart b/test_integration/lib/test/realtime/realtime_presence_subscribe.dart index b45dc1186..c8842bffa 100644 --- a/test_integration/lib/test/realtime/realtime_presence_subscribe.dart +++ b/test_integration/lib/test/realtime/realtime_presence_subscribe.dart @@ -23,7 +23,7 @@ Future> testRealtimePresenceSubscribe({ key: appKey, environment: 'sandbox', clientId: 'someClientId', - logLevel: LogLevel.verbose, + logLevel: LogLevel.error, ), ).channels.get('test').presence; diff --git a/test_integration/lib/test/realtime/realtime_publish_test.dart b/test_integration/lib/test/realtime/realtime_publish_test.dart index c23173635..14ed51ea7 100644 --- a/test_integration/lib/test/realtime/realtime_publish_test.dart +++ b/test_integration/lib/test/realtime/realtime_publish_test.dart @@ -18,7 +18,7 @@ Future> testRealtimePublish({ key: appKey, environment: 'sandbox', clientId: 'someClientId', - logLevel: LogLevel.verbose, + logLevel: LogLevel.error, ), ); await publishMessages(realtime.channels.get('test')); @@ -40,7 +40,7 @@ Future> testRealtimePublishSpec({ key: appKey, environment: 'sandbox', clientId: 'someClientId', - logLevel: LogLevel.verbose, + logLevel: LogLevel.error, ), ); final channel = realtime.channels.get('test'); diff --git a/test_integration/lib/test/realtime/realtime_publish_with_auth_callback_test.dart b/test_integration/lib/test/realtime/realtime_publish_with_auth_callback_test.dart index 7207d4a8d..669994bbe 100644 --- a/test_integration/lib/test/realtime/realtime_publish_with_auth_callback_test.dart +++ b/test_integration/lib/test/realtime/realtime_publish_with_auth_callback_test.dart @@ -10,7 +10,7 @@ Future> testRealtimePublishWithAuthCallback({ var authCallbackInvoked = false; final realtime = Realtime( options: ClientOptions( - logLevel: LogLevel.verbose, + logLevel: LogLevel.error, authCallback: (params) async { authCallbackInvoked = true; return TokenRequest.fromMap( diff --git a/test_integration/lib/test/realtime/realtime_time_test.dart b/test_integration/lib/test/realtime/realtime_time_test.dart index 7a8bf17d3..873e68f53 100644 --- a/test_integration/lib/test/realtime/realtime_time_test.dart +++ b/test_integration/lib/test/realtime/realtime_time_test.dart @@ -14,7 +14,7 @@ Future> testRealtimeTime({ key: appKey, environment: 'sandbox', clientId: 'someClientId', - logLevel: LogLevel.verbose, + logLevel: LogLevel.error, ), ); diff --git a/test_integration/lib/test/rest/rest_auth_client_id_test.dart b/test_integration/lib/test/rest/rest_auth_client_id_test.dart index 32eefa261..3cfcafea8 100644 --- a/test_integration/lib/test/rest/rest_auth_client_id_test.dart +++ b/test_integration/lib/test/rest/rest_auth_client_id_test.dart @@ -13,7 +13,7 @@ Future> testRestAuthClientId({ final clientOptionsForToken = ClientOptions( key: appKey, environment: 'sandbox', - logLevel: LogLevel.verbose, + logLevel: LogLevel.error, ); final ablyForToken = Rest( diff --git a/test_integration/lib/test/rest/rest_authorize_test.dart b/test_integration/lib/test/rest/rest_authorize_test.dart index c0f636326..44621ff21 100644 --- a/test_integration/lib/test/rest/rest_authorize_test.dart +++ b/test_integration/lib/test/rest/rest_authorize_test.dart @@ -13,7 +13,7 @@ Future> testRestAuthorize({ final clientOptionsForToken = ClientOptions( key: appKey, environment: 'sandbox', - logLevel: LogLevel.verbose, + logLevel: LogLevel.error, ); final ablyForToken = Rest( diff --git a/test_integration/lib/test/rest/rest_capability_test.dart b/test_integration/lib/test/rest/rest_capability_test.dart index d11f73cfd..cb4a49097 100644 --- a/test_integration/lib/test/rest/rest_capability_test.dart +++ b/test_integration/lib/test/rest/rest_capability_test.dart @@ -24,7 +24,7 @@ Future> testRestCapabilities({ key: appKey, environment: 'sandbox', clientId: 'someClientId', - logLevel: LogLevel.verbose, + logLevel: LogLevel.error, ), ); diff --git a/test_integration/lib/test/rest/rest_create_token_request_test.dart b/test_integration/lib/test/rest/rest_create_token_request_test.dart index a94f5bcd4..38d106b8d 100644 --- a/test_integration/lib/test/rest/rest_create_token_request_test.dart +++ b/test_integration/lib/test/rest/rest_create_token_request_test.dart @@ -12,7 +12,7 @@ Future> testRestCreateTokenRequest({ final clientOptionsForToken = ClientOptions( key: appKey, environment: 'sandbox', - logLevel: LogLevel.verbose, + logLevel: LogLevel.error, ); final rest = Rest( diff --git a/test_integration/lib/test/rest/rest_encrypted_publish_test.dart b/test_integration/lib/test/rest/rest_encrypted_publish_test.dart index 09fbad32f..44500d32e 100644 --- a/test_integration/lib/test/rest/rest_encrypted_publish_test.dart +++ b/test_integration/lib/test/rest/rest_encrypted_publish_test.dart @@ -22,7 +22,7 @@ Future> testRestEncryptedPublish({ key: appKey, environment: 'sandbox', clientId: 'someClientId', - logLevel: LogLevel.verbose, + logLevel: LogLevel.error, ), ); @@ -53,7 +53,7 @@ Future> testRestEncryptedPublishSpec({ key: appKey, environment: 'sandbox', clientId: clientId, - logLevel: LogLevel.verbose, + logLevel: LogLevel.error, ), ); diff --git a/test_integration/lib/test/rest/rest_history_test.dart b/test_integration/lib/test/rest/rest_history_test.dart index 9a390d923..b84c0511c 100644 --- a/test_integration/lib/test/rest/rest_history_test.dart +++ b/test_integration/lib/test/rest/rest_history_test.dart @@ -17,7 +17,7 @@ Future> testRestHistory({ key: appKey, environment: 'sandbox', clientId: 'someClientId', - logLevel: LogLevel.verbose, + logLevel: LogLevel.error, ), ); final channel = rest.channels.get('test'); diff --git a/test_integration/lib/test/rest/rest_history_with_auth_callback_test.dart b/test_integration/lib/test/rest/rest_history_with_auth_callback_test.dart index 2e8cbe63b..c5bed7103 100644 --- a/test_integration/lib/test/rest/rest_history_with_auth_callback_test.dart +++ b/test_integration/lib/test/rest/rest_history_with_auth_callback_test.dart @@ -13,7 +13,7 @@ Future> testRestHistoryWithAuthCallback({ final rest = Rest( options: ClientOptions( clientId: 'someClientId', - logLevel: LogLevel.verbose, + logLevel: LogLevel.error, authCallback: (params) async { authCallbackInvoked = true; return TokenRequest.fromMap( diff --git a/test_integration/lib/test/rest/rest_presence_get_test.dart b/test_integration/lib/test/rest/rest_presence_get_test.dart index fcbfad1ea..f9ce698fe 100644 --- a/test_integration/lib/test/rest/rest_presence_get_test.dart +++ b/test_integration/lib/test/rest/rest_presence_get_test.dart @@ -15,7 +15,7 @@ ClientOptions getClientOptions( key: appKey, environment: 'sandbox', clientId: clientId, - logLevel: LogLevel.verbose, + logLevel: LogLevel.error, ); Future> testRestPresenceGet({ diff --git a/test_integration/lib/test/rest/rest_presence_history_test.dart b/test_integration/lib/test/rest/rest_presence_history_test.dart index 6c2dda5bf..41b8895c3 100644 --- a/test_integration/lib/test/rest/rest_presence_history_test.dart +++ b/test_integration/lib/test/rest/rest_presence_history_test.dart @@ -17,7 +17,7 @@ Future> testRestPresenceHistory({ key: appKey, environment: 'sandbox', clientId: 'someClientId', - logLevel: LogLevel.verbose, + logLevel: LogLevel.error, ); final rest = Rest(options: options); diff --git a/test_integration/lib/test/rest/rest_publish_test.dart b/test_integration/lib/test/rest/rest_publish_test.dart index 296a085f4..ef2cb78c9 100644 --- a/test_integration/lib/test/rest/rest_publish_test.dart +++ b/test_integration/lib/test/rest/rest_publish_test.dart @@ -19,7 +19,7 @@ Future> testRestPublish({ key: appKey.toString(), environment: 'sandbox', clientId: 'someClientId', - logLevel: LogLevel.verbose, + logLevel: LogLevel.error, ), ); await publishMessages(rest.channels.get('test')); @@ -40,7 +40,7 @@ Future> testRestPublishSpec({ key: appKey, environment: 'sandbox', clientId: 'someClientId', - logLevel: LogLevel.verbose, + logLevel: LogLevel.error, ), ); final channel = rest.channels.get('test'); diff --git a/test_integration/lib/test/rest/rest_publish_with_auth_callback_test.dart b/test_integration/lib/test/rest/rest_publish_with_auth_callback_test.dart index 0b91dd767..5ad52f173 100644 --- a/test_integration/lib/test/rest/rest_publish_with_auth_callback_test.dart +++ b/test_integration/lib/test/rest/rest_publish_with_auth_callback_test.dart @@ -12,7 +12,7 @@ Future> testRestPublishWithAuthCallback({ final rest = Rest( options: ClientOptions( clientId: 'someClientId', - logLevel: LogLevel.verbose, + logLevel: LogLevel.error, authCallback: (params) async { authCallbackInvoked = true; return TokenRequest.fromMap( diff --git a/test_integration/lib/test/rest/rest_request_token_test.dart b/test_integration/lib/test/rest/rest_request_token_test.dart index b1b179fb1..b6c804efd 100644 --- a/test_integration/lib/test/rest/rest_request_token_test.dart +++ b/test_integration/lib/test/rest/rest_request_token_test.dart @@ -14,7 +14,7 @@ Future> testRestRequestToken({ final clientOptionsForToken = ClientOptions( key: appKey, environment: 'sandbox', - logLevel: LogLevel.verbose, + logLevel: LogLevel.error, ); final restForToken = Rest( @@ -24,7 +24,7 @@ Future> testRestRequestToken({ final token = await restForToken.auth.requestToken(); final clientOptions = ClientOptions( - tokenDetails: token, environment: 'sandbox', logLevel: LogLevel.verbose); + tokenDetails: token, environment: 'sandbox', logLevel: LogLevel.error); final tokenedRest = Rest(options: clientOptions); await publishMessages(tokenedRest.channels.get('test')); diff --git a/test_integration/lib/test/rest/rest_time_test.dart b/test_integration/lib/test/rest/rest_time_test.dart index 1c12fd928..4d840dddb 100644 --- a/test_integration/lib/test/rest/rest_time_test.dart +++ b/test_integration/lib/test/rest/rest_time_test.dart @@ -14,7 +14,7 @@ Future> testRestTime({ key: appKey, environment: 'sandbox', clientId: 'someClientId', - logLevel: LogLevel.verbose, + logLevel: LogLevel.error, ), ); From 51ce5f0d0a7535c9625cdff86a5a783bcaecaa01 Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Tue, 5 Mar 2024 14:24:17 +0530 Subject: [PATCH 09/13] Fixed ably flutter test for testing realtime events --- .../test_driver/test_implementation/realtime_tests.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test_integration/test_driver/test_implementation/realtime_tests.dart b/test_integration/test_driver/test_implementation/realtime_tests.dart index 5a03b10ca..2ba44c2bc 100644 --- a/test_integration/test_driver/test_implementation/realtime_tests.dart +++ b/test_integration/test_driver/test_implementation/realtime_tests.dart @@ -336,8 +336,10 @@ void testRealtimeEvents(FlutterDriver Function() getDriver) { ]; } else { _stateChangeEvents = const [ + 'attaching', 'attaching', 'attached', + 'update', 'detaching', 'detached', ]; From e82e6dbe1c19c41eb7b29eec89e1f9e56ef3e09d Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Tue, 5 Mar 2024 15:31:27 +0530 Subject: [PATCH 10/13] Updated realtime tests for state changes --- .../test_implementation/realtime_tests.dart | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/test_integration/test_driver/test_implementation/realtime_tests.dart b/test_integration/test_driver/test_implementation/realtime_tests.dart index 2ba44c2bc..e9898a6e3 100644 --- a/test_integration/test_driver/test_implementation/realtime_tests.dart +++ b/test_integration/test_driver/test_implementation/realtime_tests.dart @@ -318,6 +318,20 @@ void testRealtimeEvents(FlutterDriver Function() getDriver) { // https://github.com/ably/ably-flutter/issues/63 List _stateChangeEvents; List _stateChangePrevious; + if (channelStateChanges.length == 4) { + _stateChangeEvents = const [ + 'attaching', + 'attached', + 'detaching', + 'detached', + ]; + _stateChangePrevious = const [ + 'initialized', + 'attaching', + 'attached', + 'detaching', + ]; + } if (channelStateChanges.length == 5) { // ios _stateChangeEvents = const [ @@ -339,20 +353,22 @@ void testRealtimeEvents(FlutterDriver Function() getDriver) { 'attaching', 'attaching', 'attached', - 'update', + 'attached', 'detaching', 'detached', ]; _stateChangePrevious = const [ + 'initialized', 'initialized', 'attaching', + 'attaching', 'attached', 'detaching', ]; } - expect(channelStateChanges.map((e) => e['event']), - orderedEquals(_stateChangeEvents)); + // expect(channelStateChanges.map((e) => e['event']), + // orderedEquals(_stateChangeEvents)); expect(channelStateChanges.map((e) => e['current']), orderedEquals(_stateChangeEvents)); From fd7cc8cd823d9363b11e8d63272a534100aef5be Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Tue, 5 Mar 2024 15:56:36 +0530 Subject: [PATCH 11/13] Fixed failing test with right state changes for current and events --- .../test_implementation/realtime_tests.dart | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/test_integration/test_driver/test_implementation/realtime_tests.dart b/test_integration/test_driver/test_implementation/realtime_tests.dart index e9898a6e3..f2a933da8 100644 --- a/test_integration/test_driver/test_implementation/realtime_tests.dart +++ b/test_integration/test_driver/test_implementation/realtime_tests.dart @@ -316,10 +316,11 @@ void testRealtimeEvents(FlutterDriver Function() getDriver) { // TODO(tiholic): get rid of _stateChangeEvents and _stateChangePrevious // variables as they are a way to make tests pass due to // https://github.com/ably/ably-flutter/issues/63 - List _stateChangeEvents; + List _stateChangeCurrent; List _stateChangePrevious; + List _stateChangeEvents; if (channelStateChanges.length == 4) { - _stateChangeEvents = const [ + _stateChangeCurrent = const [ 'attaching', 'attached', 'detaching', @@ -331,10 +332,10 @@ void testRealtimeEvents(FlutterDriver Function() getDriver) { 'attached', 'detaching', ]; - } - if (channelStateChanges.length == 5) { + _stateChangeEvents = _stateChangeCurrent; + } else if (channelStateChanges.length == 5) { // ios - _stateChangeEvents = const [ + _stateChangeCurrent = const [ 'attaching', 'attached', 'detaching', @@ -348,8 +349,9 @@ void testRealtimeEvents(FlutterDriver Function() getDriver) { 'detaching', 'detached', ]; + _stateChangeEvents = _stateChangeCurrent; } else { - _stateChangeEvents = const [ + _stateChangeCurrent = const [ 'attaching', 'attaching', 'attached', @@ -358,20 +360,28 @@ void testRealtimeEvents(FlutterDriver Function() getDriver) { 'detached', ]; _stateChangePrevious = const [ - 'initialized', 'initialized', 'attaching', 'attaching', 'attached', + 'attached', 'detaching', ]; + _stateChangeEvents = const [ + 'attaching', + 'attaching', + 'attached', + 'update', + 'detaching', + 'detached', + ]; } - // expect(channelStateChanges.map((e) => e['event']), - // orderedEquals(_stateChangeEvents)); + expect(channelStateChanges.map((e) => e['event']), + orderedEquals(_stateChangeEvents)); expect(channelStateChanges.map((e) => e['current']), - orderedEquals(_stateChangeEvents)); + orderedEquals(_stateChangeCurrent)); expect(channelStateChanges.map((e) => e['previous']), orderedEquals(_stateChangePrevious)); From 767f984bc51bfaef2c112f2be1f9d2ec6392bdc9 Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Tue, 5 Mar 2024 16:32:56 +0530 Subject: [PATCH 12/13] Fixed failing tests for ably-flutter --- .../test_implementation/realtime_tests.dart | 48 +++++++++++-------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/test_integration/test_driver/test_implementation/realtime_tests.dart b/test_integration/test_driver/test_implementation/realtime_tests.dart index f2a933da8..e1604b506 100644 --- a/test_integration/test_driver/test_implementation/realtime_tests.dart +++ b/test_integration/test_driver/test_implementation/realtime_tests.dart @@ -320,6 +320,7 @@ void testRealtimeEvents(FlutterDriver Function() getDriver) { List _stateChangePrevious; List _stateChangeEvents; if (channelStateChanges.length == 4) { + // iOS _stateChangeCurrent = const [ 'attaching', 'attached', @@ -333,24 +334,8 @@ void testRealtimeEvents(FlutterDriver Function() getDriver) { 'detaching', ]; _stateChangeEvents = _stateChangeCurrent; - } else if (channelStateChanges.length == 5) { - // ios - _stateChangeCurrent = const [ - 'attaching', - 'attached', - 'detaching', - 'detached', - 'detached', - ]; - _stateChangePrevious = const [ - 'initialized', - 'attaching', - 'attached', - 'detaching', - 'detached', - ]; - _stateChangeEvents = _stateChangeCurrent; } else { + // android _stateChangeCurrent = const [ 'attaching', 'attaching', @@ -392,15 +377,38 @@ void testRealtimeEvents(FlutterDriver Function() getDriver) { '#on returns a stream which can be subscribed' ' for channel state changes with filter', () { + List _stateChangeCurrent; + List _stateChangePrevious; + List _stateChangeEvents; + if (channelStateChanges.length == 4) { + // iOS + _stateChangeCurrent = const [ + 'attaching', + ]; + _stateChangePrevious = const [ + 'initialized', + ]; + } else { + // Android + _stateChangeCurrent = const [ + 'attaching', + 'attaching', + ]; + _stateChangePrevious = const [ + 'initialized', + 'attaching', + ]; + } + _stateChangeEvents = _stateChangeCurrent; // filteredChannelStateChanges expect(filteredChannelStateChanges.map((e) => e['event']), - orderedEquals(const ['attaching'])); + orderedEquals(_stateChangeEvents)); expect(filteredChannelStateChanges.map((e) => e['current']), - orderedEquals(const ['attaching'])); + orderedEquals(_stateChangeCurrent)); expect(filteredChannelStateChanges.map((e) => e['previous']), - orderedEquals(const ['initialized'])); + orderedEquals(_stateChangePrevious)); }, ); }); From d3cd37b799ce6ff70872cc448b83599074edd049 Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Tue, 5 Mar 2024 19:24:38 +0530 Subject: [PATCH 13/13] Added recoveryKey as an example to realtime silver dart file --- example/lib/ui/realtime_sliver.dart | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/example/lib/ui/realtime_sliver.dart b/example/lib/ui/realtime_sliver.dart index 0481c9175..15e143e5c 100644 --- a/example/lib/ui/realtime_sliver.dart +++ b/example/lib/ui/realtime_sliver.dart @@ -136,13 +136,15 @@ class RealtimeSliver extends HookWidget { ValueNotifier connectionState, ValueNotifier channelState, ValueNotifier connectionId, + ValueNotifier recoveryKey, ) => TextButton( onPressed: () async { await channel.detach(); realtime.channels.release(Constants.channelName); channel = realtime.channels.get(Constants.channelName); - setupListeners(connectionState, channelState, connectionId); + setupListeners( + connectionState, channelState, connectionId, recoveryKey); }, child: const Text('Release'), ); @@ -179,6 +181,7 @@ class RealtimeSliver extends HookWidget { final connectionState = useState(realtime.connection.state); final connectionId = useState(realtime.connection.id); + final recoveryKey = useState(''); final channelState = useState(channel.state); final latestMessage = useState(null); final channelSubscription = @@ -188,7 +191,7 @@ class RealtimeSliver extends HookWidget { useEffect(() { realtime.time().then((value) => realtimeTime.value = value); - setupListeners(connectionState, channelState, connectionId); + setupListeners(connectionState, channelState, connectionId, recoveryKey); return dispose; }, []); @@ -202,6 +205,7 @@ class RealtimeSliver extends HookWidget { Text('Realtime time: ${realtimeTime.value}'), Text('Connection State: ${connectionState.value}'), Text('Connection Id: ${connectionId.value ?? '-'}'), + Text('Connection Recovery Key: ${recoveryKey.value ?? '-'}'), buildEncryptionSwitch(useEncryption), Row( children: [ @@ -226,7 +230,7 @@ class RealtimeSliver extends HookWidget { Expanded(child: buildChannelDetachButton(channelState.value)), Expanded( child: buildReleaseRealtimeChannelButton( - connectionState, channelState, connectionId)), + connectionState, channelState, connectionId, recoveryKey)), ], ), Row( @@ -293,7 +297,8 @@ class RealtimeSliver extends HookWidget { void setupListeners( ValueNotifier connectionState, ValueNotifier channelState, - ValueNotifier connectionId) { + ValueNotifier connectionId, + ValueNotifier recoveryKey) { dispose(); final connectionSubscription = realtime.connection.on().listen((connectionStateChange) { @@ -302,6 +307,9 @@ class RealtimeSliver extends HookWidget { } connectionState.value = connectionStateChange.current; connectionId.value = realtime.connection.id; + realtime.connection + .createRecoveryKey() + .then((value) => {recoveryKey.value = value}); print('${DateTime.now()}:' ' ConnectionStateChange event: ${connectionStateChange.event}' '\nReason: ${connectionStateChange.reason}');