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.