Skip to content

Commit

Permalink
fix: add createRecoveryKey method
Browse files Browse the repository at this point in the history
  • Loading branch information
ttypic committed Feb 26, 2024
1 parent dad509f commit 4ead8d1
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 4 deletions.
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 @@ -61,8 +61,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

0 comments on commit 4ead8d1

Please sign in to comment.