Skip to content

Commit

Permalink
Merge pull request #508 from ably/feature/integration-2.0
Browse files Browse the repository at this point in the history
[ECO-4611] Feature/integration 2.0
  • Loading branch information
sacOO7 authored Mar 5, 2024
2 parents 096daf4 + d3cd37b commit af60beb
Show file tree
Hide file tree
Showing 39 changed files with 137 additions and 56 deletions.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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.35'

// https://firebase.google.com/docs/cloud-messaging/android/client
implementation 'com.google.firebase:firebase-messaging:23.0.4'
Expand Down
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.createRecoveryKey());
}

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
4 changes: 2 additions & 2 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
16 changes: 12 additions & 4 deletions example/lib/ui/realtime_sliver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,15 @@ class RealtimeSliver extends HookWidget {
ValueNotifier<ably.ConnectionState> connectionState,
ValueNotifier<ably.ChannelState> channelState,
ValueNotifier<String?> connectionId,
ValueNotifier<String?> 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'),
);
Expand Down Expand Up @@ -179,6 +181,7 @@ class RealtimeSliver extends HookWidget {
final connectionState =
useState<ably.ConnectionState>(realtime.connection.state);
final connectionId = useState<String?>(realtime.connection.id);
final recoveryKey = useState<String?>('');
final channelState = useState<ably.ChannelState>(channel.state);
final latestMessage = useState<ably.Message?>(null);
final channelSubscription =
Expand All @@ -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;
}, []);

Expand All @@ -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: <Widget>[
Expand All @@ -226,7 +230,7 @@ class RealtimeSliver extends HookWidget {
Expanded(child: buildChannelDetachButton(channelState.value)),
Expanded(
child: buildReleaseRealtimeChannelButton(
connectionState, channelState, connectionId)),
connectionState, channelState, connectionId, recoveryKey)),
],
),
Row(
Expand Down Expand Up @@ -293,7 +297,8 @@ class RealtimeSliver extends HookWidget {
void setupListeners(
ValueNotifier<ably.ConnectionState> connectionState,
ValueNotifier<ably.ChannelState> channelState,
ValueNotifier<String?> connectionId) {
ValueNotifier<String?> connectionId,
ValueNotifier<String?> recoveryKey) {
dispose();
final connectionSubscription =
realtime.connection.on().listen((connectionStateChange) {
Expand All @@ -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}');
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 createRecoveryKey];
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
2 changes: 1 addition & 1 deletion ios/ably_flutter.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'

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
4 changes: 2 additions & 2 deletions test_integration/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Future<Map<String, dynamic>> testRealtimeAuthClientId({
final clientOptionsForToken = ClientOptions(
key: appKey,
environment: 'sandbox',
logLevel: LogLevel.verbose,
logLevel: LogLevel.error,
);

final ablyForToken = Rest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Future<Map<String, dynamic>> testCreateRealtimeWithAuthUrl({
final clientOptionsForToken = ClientOptions(
key: appKey,
environment: 'sandbox',
logLevel: LogLevel.verbose,
logLevel: LogLevel.error,
fallbackHosts: <String>['a.ably-realtime.com', 'b.ably-realtime.com'],
);

Expand All @@ -32,7 +32,7 @@ Future<Map<String, dynamic>> testCreateRealtimeWithAuthUrl({
environment: 'sandbox',
useTokenAuth: true,
autoConnect: false,
logLevel: LogLevel.verbose);
logLevel: LogLevel.error);
final realtime = Realtime(options: options);
final completer = Completer<void>();
realtime.connection.on().listen((stateChange) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Future<Map<String, dynamic>> testRealtimeAuthroize({
final clientOptionsForToken = ClientOptions(
key: appKey,
environment: 'sandbox',
logLevel: LogLevel.verbose,
logLevel: LogLevel.error,
);

final ablyForToken = Rest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Future<Map<String, dynamic>> testRealtimeEncryptedPublishSpec({
key: appKey,
environment: 'sandbox',
clientId: clientId,
logLevel: LogLevel.verbose,
logLevel: LogLevel.error,
),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Future<Map<String, dynamic>> testRealtimeHistory({
key: appKey,
environment: 'sandbox',
clientId: 'someClientId',
logLevel: LogLevel.verbose,
logLevel: LogLevel.error,
),
);
final channel = realtime.channels.get('test');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Future<Map<String, dynamic>> testRealtimeHistoryWithAuthCallback({
final realtime = Realtime(
options: ClientOptions(
clientId: 'someClientId',
logLevel: LogLevel.verbose,
logLevel: LogLevel.error,
authCallback: (params) async {
authCallbackInvoked = true;
return TokenRequest.fromMap(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ClientOptions getClientOptions(
key: appKey,
environment: 'sandbox',
clientId: clientId,
logLevel: LogLevel.verbose,
logLevel: LogLevel.error,
);

Future<Map<String, dynamic>> testRealtimePresenceEnterUpdateLeave({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ClientOptions getClientOptions(
key: appKey,
environment: 'sandbox',
clientId: clientId,
logLevel: LogLevel.verbose,
logLevel: LogLevel.error,
);

Future<Map<String, dynamic>> testRealtimePresenceGet({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Future<Map<String, dynamic>> testRealtimePresenceHistory({
key: appKey,
environment: 'sandbox',
clientId: 'someClientId',
logLevel: LogLevel.verbose,
logLevel: LogLevel.error,
);

final realtime = Realtime(options: options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Future<Map<String, dynamic>> testRealtimePresenceSubscribe({
key: appKey,
environment: 'sandbox',
clientId: 'someClientId',
logLevel: LogLevel.verbose,
logLevel: LogLevel.error,
),
).channels.get('test').presence;

Expand Down
4 changes: 2 additions & 2 deletions test_integration/lib/test/realtime/realtime_publish_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Future<Map<String, dynamic>> testRealtimePublish({
key: appKey,
environment: 'sandbox',
clientId: 'someClientId',
logLevel: LogLevel.verbose,
logLevel: LogLevel.error,
),
);
await publishMessages(realtime.channels.get('test'));
Expand All @@ -40,7 +40,7 @@ Future<Map<String, dynamic>> testRealtimePublishSpec({
key: appKey,
environment: 'sandbox',
clientId: 'someClientId',
logLevel: LogLevel.verbose,
logLevel: LogLevel.error,
),
);
final channel = realtime.channels.get('test');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Future<Map<String, dynamic>> testRealtimePublishWithAuthCallback({
var authCallbackInvoked = false;
final realtime = Realtime(
options: ClientOptions(
logLevel: LogLevel.verbose,
logLevel: LogLevel.error,
authCallback: (params) async {
authCallbackInvoked = true;
return TokenRequest.fromMap(
Expand Down
2 changes: 1 addition & 1 deletion test_integration/lib/test/realtime/realtime_time_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Future<Map<String, dynamic>> testRealtimeTime({
key: appKey,
environment: 'sandbox',
clientId: 'someClientId',
logLevel: LogLevel.verbose,
logLevel: LogLevel.error,
),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Future<Map<String, dynamic>> testRestAuthClientId({
final clientOptionsForToken = ClientOptions(
key: appKey,
environment: 'sandbox',
logLevel: LogLevel.verbose,
logLevel: LogLevel.error,
);

final ablyForToken = Rest(
Expand Down
2 changes: 1 addition & 1 deletion test_integration/lib/test/rest/rest_authorize_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Future<Map<String, dynamic>> testRestAuthorize({
final clientOptionsForToken = ClientOptions(
key: appKey,
environment: 'sandbox',
logLevel: LogLevel.verbose,
logLevel: LogLevel.error,
);

final ablyForToken = Rest(
Expand Down
2 changes: 1 addition & 1 deletion test_integration/lib/test/rest/rest_capability_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Future<Map<String, dynamic>> testRestCapabilities({
key: appKey,
environment: 'sandbox',
clientId: 'someClientId',
logLevel: LogLevel.verbose,
logLevel: LogLevel.error,
),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Future<Map<String, dynamic>> testRestCreateTokenRequest({
final clientOptionsForToken = ClientOptions(
key: appKey,
environment: 'sandbox',
logLevel: LogLevel.verbose,
logLevel: LogLevel.error,
);

final rest = Rest(
Expand Down
Loading

0 comments on commit af60beb

Please sign in to comment.