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

Fix realtime connection fields #503

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
7829b1f
Added connection fields to android/ios platform constants
sacOO7 Feb 21, 2024
fb220ca
Added android specific method handlers for connection fields
sacOO7 Feb 21, 2024
553509e
Added missing ios specific constants to header file
sacOO7 Feb 21, 2024
2359a94
Added connection fields method handler implementation for ios
sacOO7 Feb 21, 2024
4484ef6
Added connection specific fields to platform constants dart
sacOO7 Feb 21, 2024
5362bff
Added dart methods to retrieve connection specific field values
sacOO7 Feb 21, 2024
5fd1f1f
Fixed indentation error in ablyflutter
sacOO7 Feb 21, 2024
3a109df
Fixed connection fields accessor issues for ios
sacOO7 Feb 21, 2024
5f40d84
Refactored connection dart file to include createRecoveryKey method
sacOO7 Feb 22, 2024
7609df0
Made connection field id and recoveryKey as sync instead of async
sacOO7 Feb 22, 2024
77a97e6
Refactored code as per review comments
sacOO7 Feb 22, 2024
62f4c80
removed connection error reason references from the code
sacOO7 Feb 22, 2024
59c820d
Added dart impl to handle notification from android when connection id
sacOO7 Feb 23, 2024
e697aa4
Updated android code to send connection id when connection state changes
sacOO7 Feb 23, 2024
5dddbe2
Added connectionIdUpdated constants to AblyPlatformConstants
sacOO7 Feb 23, 2024
09c3275
Added realtime callback whenever connection state changes, send conne…
sacOO7 Feb 23, 2024
25ddbd1
removed unnecessary fetchId and fetchKey method from the connection d…
sacOO7 Feb 23, 2024
e14238b
Removed unnecessary id setting from connection platformobject dart
sacOO7 Feb 23, 2024
e525c0e
Updated connectionId updated method to retun null in dart
sacOO7 Feb 23, 2024
032948f
refactored code, removed unnecessary additions
sacOO7 Feb 23, 2024
2e1839d
Fixed missing imports and build errors for android
sacOO7 Feb 23, 2024
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,12 @@ 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.connectionId, this::connectionId);
_map.put(PlatformConstants.PlatformMethod.connectionKey, this::connectionKey);
_map.put(PlatformConstants.PlatformMethod.connectionRecoveryKey, this::connectionRecoveryKey);
_map.put(PlatformConstants.PlatformMethod.connectionErrorReason, this::connectionErrorReason);

// Push Notifications
_map.put(PlatformConstants.PlatformMethod.pushActivate, this::pushActivate);
_map.put(PlatformConstants.PlatformMethod.pushDeactivate, this::pushDeactivate);
Expand Down Expand Up @@ -559,6 +565,30 @@ private void restTime(@NonNull MethodCall methodCall, @NonNull MethodChannel.Res
time(result, instanceStore.getRest(ablyMessage.handle));
}

private void connectionId(@NonNull MethodCall methodCall, @NonNull MethodChannel.Result result) {
final AblyFlutterMessage ablyMessage = (AblyFlutterMessage) methodCall.arguments;
AblyRealtime realtime = instanceStore.getRealtime(ablyMessage.handle);
result.success(realtime.connection.id);
}

private void connectionKey(@NonNull MethodCall methodCall, @NonNull MethodChannel.Result result) {
final AblyFlutterMessage ablyMessage = (AblyFlutterMessage) methodCall.arguments;
AblyRealtime realtime = instanceStore.getRealtime(ablyMessage.handle);
result.success(realtime.connection.key);
}

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 connectionErrorReason(@NonNull MethodCall methodCall, @NonNull MethodChannel.Result result) {
final AblyFlutterMessage ablyMessage = (AblyFlutterMessage) methodCall.arguments;
AblyRealtime realtime = instanceStore.getRealtime(ablyMessage.handle);
result.success(realtime.connection.reason);
}

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,12 @@ 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 connectionId = "connectionId";
public static final String connectionKey = "connectionKey";
public static final String connectionRecoveryKey = "connectionRecoveryKey";
public static final String connectionErrorReason = "connectionErrorReason";

public static final String pushActivate = "pushActivate";
public static final String pushDeactivate = "pushDeactivate";
public static final String pushReset = "pushReset";
Expand Down
38 changes: 37 additions & 1 deletion ios/Classes/AblyFlutter.m
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,6 @@ -(void)reset;

static const FlutterHandler _restTime = ^void(AblyFlutter *const ably, FlutterMethodCall *const call, const FlutterResult result) {
AblyFlutterMessage *const ablyMessage = call.arguments;

AblyInstanceStore *const instanceStore = [ably instanceStore];
ARTRest *const rest = [instanceStore restFrom:ablyMessage.handle];

Expand All @@ -599,6 +598,38 @@ -(void)reset;
}];
};

static const FlutterHandler _connectionId = ^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 connectionId = [realtime.connection id];
result(connectionId);
};

static const FlutterHandler _connectionKey = ^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 connectionKey = [realtime.connection key];
result(connectionKey);
};

static const FlutterHandler _connectionErrorReason = ^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];
ARTErrorInfo* connectionError = [realtime.connection errorReason];
result(connectionError);
};

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 +772,11 @@ -(instancetype)initWithChannel:(FlutterMethodChannel *const)channel
AblyPlatformMethod_releaseRealtimeChannel: _releaseRealtimeChannel,
AblyPlatformMethod_realtimeTime:_realtimeTime,
AblyPlatformMethod_restTime:_restTime,
// Connection fields
AblyPlatformMethod_connectionId:_connectionId,
AblyPlatformMethod_connectionKey:_connectionKey,
AblyPlatformMethod_connectionRecoveryKey:_connectionRecoveryKey,
AblyPlatformMethod_connectionErrorReason:_connectionErrorReason,
// Push Notifications
AblyPlatformMethod_pushActivate: PushHandlers.activate,
AblyPlatformMethod_pushRequestPermission: PushHandlers.requestPermission,
Expand Down
6 changes: 6 additions & 0 deletions ios/Classes/codec/AblyPlatformConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ extern NSString *const AblyPlatformMethod_realtimeAuthAuthorize;
extern NSString *const AblyPlatformMethod_realtimeAuthCreateTokenRequest;
extern NSString *const AblyPlatformMethod_realtimeAuthRequestToken;
extern NSString *const AblyPlatformMethod_realtimeAuthGetClientId;

extern NSString *const AblyPlatformMethod_connectionId;
extern NSString *const AblyPlatformMethod_connectionKey;
extern NSString *const AblyPlatformMethod_connectionRecoveryKey;
extern NSString *const AblyPlatformMethod_connectionErrorReason;

extern NSString *const AblyPlatformMethod_pushActivate;
extern NSString *const AblyPlatformMethod_pushDeactivate;
extern NSString *const AblyPlatformMethod_pushReset;
Expand Down
6 changes: 6 additions & 0 deletions ios/Classes/codec/AblyPlatformConstants.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@
NSString *const AblyPlatformMethod_realtimeAuthCreateTokenRequest= @"realtimeAuthCreateTokenRequest";
NSString *const AblyPlatformMethod_realtimeAuthRequestToken= @"realtimeAuthRequestToken";
NSString *const AblyPlatformMethod_realtimeAuthGetClientId= @"realtimeAuthGetClientId";

NSString *const AblyPlatformMethod_connectionId = @"connectionId";
NSString *const AblyPlatformMethod_connectionKey = @"connectionKey";
NSString *const AblyPlatformMethod_connectionRecoveryKey = @"connectionRecoveryKey";
NSString *const AblyPlatformMethod_connectionErrorReason = @"connectionErrorReason";

NSString *const AblyPlatformMethod_pushActivate= @"pushActivate";
NSString *const AblyPlatformMethod_pushDeactivate= @"pushDeactivate";
NSString *const AblyPlatformMethod_pushReset= @"pushReset";
Expand Down
6 changes: 6 additions & 0 deletions lib/src/generated/platform_constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ class PlatformMethod {
'realtimeAuthCreateTokenRequest';
static const String realtimeAuthRequestToken = 'realtimeAuthRequestToken';
static const String realtimeAuthGetClientId = 'realtimeAuthGetClientId';

static const String connectionId = 'connectionId';
static const String connectionKey = 'connectionKey';
static const String connectionRecoveryKey = 'connectionRecoveryKey';
static const String connectionErrorReason = 'connectionErrorReason';

static const String pushActivate = 'pushActivate';
static const String pushDeactivate = 'pushDeactivate';
static const String pushReset = 'pushReset';
Expand Down
9 changes: 6 additions & 3 deletions lib/src/platform/src/realtime/connection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class Connection extends PlatformObject {

/// A unique public identifier for this connection, used to identify this
/// member.
String? id;
Future<String?> get id async =>
invoke<String?>(PlatformMethod.connectionId);

/// A unique private connection key used to recover or resume a connection,
/// assigned by Ably.
Expand All @@ -48,14 +49,16 @@ class Connection extends PlatformObject {
/// to publish on behalf of this client. See the
/// [publishing over REST on behalf of a realtime client docs](https://ably.com/docs/rest/channels#publish-on-behalf)
/// for more info.
String? key;
Future<String?> get key async =>
invoke<String?>(PlatformMethod.connectionKey);

/// The recovery 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.
String? recoveryKey;
Future<String?> get recoveryKey async =>
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
Expand Down
Loading