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

feat: add createRecoveryKey method #507

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<Long> callback = new Callback<Long>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
10 changes: 10 additions & 0 deletions ios/Classes/AblyFlutter.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions ios/Classes/codec/AblyPlatformConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions ios/Classes/codec/AblyPlatformConstants.m
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
3 changes: 3 additions & 0 deletions lib/src/generated/platform_constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
9 changes: 9 additions & 0 deletions lib/src/platform/src/realtime/connection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String?> createRecoveryKey() =>
invoke<String?>(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.
Expand Down
Loading