diff --git a/lib/src/message/src/message.dart b/lib/src/message/src/message.dart index e440169c6..a87ba133f 100644 --- a/lib/src/message/src/message.dart +++ b/lib/src/message/src/message.dart @@ -90,7 +90,7 @@ class Message { /// RSL6 and RLS6b as mentioned in TM3 Message.fromEncoded( Map jsonObject, [ - ChannelOptions? channelOptions, + RestChannelOptions? channelOptions, ]) : id = jsonObject['id'] as String?, name = jsonObject['name'] as String?, clientId = jsonObject['clientId'] as String?, @@ -111,7 +111,7 @@ class Message { /// https://docs.ably.com/client-lib-development-guide/features/#TM3 static List fromEncodedArray( List> jsonArray, [ - ChannelOptions? channelOptions, + RestChannelOptions? channelOptions, ]) => jsonArray.map((e) => Message.fromEncoded(e, channelOptions)).toList(); diff --git a/lib/src/message/src/presence_message.dart b/lib/src/message/src/presence_message.dart index afea8cfc1..4914cbb8f 100644 --- a/lib/src/message/src/presence_message.dart +++ b/lib/src/message/src/presence_message.dart @@ -92,7 +92,7 @@ class PresenceMessage { /// RSL6 and RLS6b as mentioned in TP4 PresenceMessage.fromEncoded( Map jsonObject, [ - ChannelOptions? channelOptions, + RestChannelOptions? channelOptions, ]) : id = jsonObject['id'] as String?, action = PresenceAction.values.firstWhere((e) => e.toString().split('.')[1] == jsonObject['action'] as String?), @@ -114,7 +114,7 @@ class PresenceMessage { /// https://docs.ably.com/client-lib-development-guide/features/#TP4 static List fromEncodedArray( List> jsonArray, [ - ChannelOptions? channelOptions, + RestChannelOptions? channelOptions, ]) => jsonArray .map((jsonObject) => PresenceMessage.fromEncoded( diff --git a/lib/src/platform/src/codec.dart b/lib/src/platform/src/codec.dart index c0af998a3..84d136e9f 100644 --- a/lib/src/platform/src/codec.dart +++ b/lib/src/platform/src/codec.dart @@ -8,6 +8,7 @@ import '../../message/message.dart'; import '../../push_notifications/push_notifications.dart'; import '../../push_notifications/src/local_device.dart'; import '../../realtime/realtime.dart'; +import '../../realtime/src/realtime_channel_options.dart'; import '../../rest/rest.dart'; import '../platform.dart'; @@ -72,7 +73,7 @@ class Codec extends StandardMessageCodec { CodecTypes.tokenRequest: _CodecPair(_encodeTokenRequest, null), CodecTypes.restChannelOptions: - _CodecPair(_encodeRestChannelOptions, null), + _CodecPair(_encodeRestChannelOptions, null), CodecTypes.realtimeChannelOptions: _CodecPair( _encodeRealtimeChannelOptions, null, @@ -309,9 +310,9 @@ class Codec extends StandardMessageCodec { return jsonMap; } - /// Encodes [ChannelOptions] to a Map + /// Encodes [RestChannelOptions] to a Map /// returns null if [v] is null - Map _encodeRestChannelOptions(final ChannelOptions v) { + Map _encodeRestChannelOptions(final RestChannelOptions v) { final jsonMap = {}; _writeToJson(jsonMap, TxRestChannelOptions.cipher, v.cipher); return jsonMap; diff --git a/lib/src/platform/src/realtime/realtime_channel.dart b/lib/src/platform/src/realtime/realtime_channel.dart index 1b312680e..3d67b8485 100644 --- a/lib/src/platform/src/realtime/realtime_channel.dart +++ b/lib/src/platform/src/realtime/realtime_channel.dart @@ -10,6 +10,8 @@ import '../../../generated/platform_constants.dart'; import '../../../message/message.dart'; import '../../../push_notifications/push_notifications.dart'; import '../../../realtime/realtime.dart'; +import '../../../realtime/src/realtime_channel_options.dart'; +import '../../../realtime/src/realtime_channels_interface.dart'; import '../../platform.dart'; import '../../platform_internal.dart'; diff --git a/lib/src/platform/src/rest/publish_queue_item.dart b/lib/src/platform/src/rest/publish_queue_item.dart new file mode 100644 index 000000000..ff38c5d01 --- /dev/null +++ b/lib/src/platform/src/rest/publish_queue_item.dart @@ -0,0 +1,12 @@ +import 'dart:async'; + +import '../../../message/message.dart'; + +/// An item for used to enqueue a message to be published after an ongoing +/// authCallback is completed +class PublishQueueItem { + final List messages; + final Completer completer; + + PublishQueueItem(this.completer, this.messages); +} diff --git a/lib/src/platform/src/rest/rest_channel.dart b/lib/src/platform/src/rest/rest_channel.dart index 107d43806..ba2d8f193 100644 --- a/lib/src/platform/src/rest/rest_channel.dart +++ b/lib/src/platform/src/rest/rest_channel.dart @@ -9,6 +9,7 @@ import '../../../generated/platform_constants.dart'; import '../../../message/message.dart'; import '../../../rest/rest.dart'; import '../../platform.dart'; +import 'publish_queue_item.dart'; /// Plugin based implementation of Rest channel class RestChannel extends PlatformObject implements RestChannelInterface { @@ -23,7 +24,7 @@ class RestChannel extends PlatformObject implements RestChannelInterface { late RestPresence _presence; - /// instantiates with [Rest], [name] and [ChannelOptions] + /// instantiates with [Rest], [name] and [RestChannelOptions] RestChannel(this.rest, this.push, this.name) { _presence = RestPresence(this); } @@ -53,7 +54,7 @@ class RestChannel extends PlatformObject implements RestChannelInterface { ); } - final _publishQueue = Queue<_PublishQueueItem>(); + final _publishQueue = Queue(); Completer? _authCallbackCompleter; @override @@ -66,7 +67,7 @@ class RestChannel extends PlatformObject implements RestChannelInterface { messages ??= [ if (message == null) Message(name: name, data: data) else message ]; - final queueItem = _PublishQueueItem(Completer(), messages); + final queueItem = PublishQueueItem(Completer(), messages); _publishQueue.add(queueItem); unawaited(_publishInternal()); return queueItem.completer.future; @@ -155,18 +156,9 @@ class RestChannel extends PlatformObject implements RestChannelInterface { } @override - Future setOptions(ChannelOptions options) => - invoke(PlatformMethod.setRealtimeChannelOptions, { + Future setOptions(RestChannelOptions options) => + invoke(PlatformMethod.setRestChannelOptions, { TxTransportKeys.channelName: name, TxTransportKeys.options: options, }); } - -/// An item for used to enqueue a message to be published after an ongoing -/// authCallback is completed -class _PublishQueueItem { - final List messages; - final Completer completer; - - _PublishQueueItem(this.completer, this.messages); -} diff --git a/lib/src/realtime/src/channels.dart b/lib/src/realtime/src/channels.dart index 8b494baaf..1d54900c8 100644 --- a/lib/src/realtime/src/channels.dart +++ b/lib/src/realtime/src/channels.dart @@ -2,33 +2,17 @@ import 'dart:async'; import '../../authentication/authentication.dart'; import '../../common/common.dart'; -import '../../common/src/channels.dart'; import '../../common/src/event_emitter.dart'; import '../../error/src/error_info.dart'; import '../../message/src/message.dart'; import '../../push_notifications/src/push_channel.dart'; -import '../../rest/src/channel_options.dart'; import '../realtime.dart'; import 'channel_event.dart'; import 'channel_state.dart'; import 'channel_state_event.dart'; import 'presence.dart'; import 'realtime.dart'; - -/// options provided when instantiating a realtime channel -/// -/// https://docs.ably.com/client-lib-development-guide/features/#TB1 -class RealtimeChannelOptions extends ChannelOptions { - /// https://docs.ably.com/client-lib-development-guide/features/#TB2c - final Map? params; - - /// https://docs.ably.com/client-lib-development-guide/features/#TB2d - final List? modes; - - /// create channel options with a cipher, params and modes - RealtimeChannelOptions(Object cipher, {this.params, this.modes}) - : super(cipher); -} +import 'realtime_channel_options.dart'; /// A named channel through with realtime client can interact with ably service. /// @@ -120,15 +104,3 @@ abstract class RealtimeChannelInterface /// https://docs.ably.com/client-lib-development-guide/features/#RTL16 Future setOptions(RealtimeChannelOptions options); } - -/// A collection of realtime channel objects -/// -/// https://docs.ably.com/client-lib-development-guide/features/#RTS1 -abstract class RealtimeChannelsInterface - extends Channels { - /// instance of ably realtime client - RealtimeInterface realtime; - - /// instantiates with the ably [RealtimeInterface] instance - RealtimeChannelsInterface(this.realtime); -} diff --git a/lib/src/realtime/src/realtime.dart b/lib/src/realtime/src/realtime.dart index a2f450b74..a49dc203b 100644 --- a/lib/src/realtime/src/realtime.dart +++ b/lib/src/realtime/src/realtime.dart @@ -2,6 +2,7 @@ import '../../authentication/authentication.dart'; import '../../common/common.dart'; import '../../push_notifications/push_notifications.dart'; import '../realtime.dart'; +import 'realtime_channels_interface.dart'; /// an abstract class for Ably's Realtime client /// diff --git a/lib/src/realtime/src/realtime_channel_options.dart b/lib/src/realtime/src/realtime_channel_options.dart new file mode 100644 index 000000000..626e0d51e --- /dev/null +++ b/lib/src/realtime/src/realtime_channel_options.dart @@ -0,0 +1,17 @@ +import '../../rest/rest.dart'; +import '../realtime.dart'; + +/// options provided when instantiating a realtime channel +/// +/// https://docs.ably.com/client-lib-development-guide/features/#TB1 +class RealtimeChannelOptions extends RestChannelOptions { + /// https://docs.ably.com/client-lib-development-guide/features/#TB2c + final Map? params; + + /// https://docs.ably.com/client-lib-development-guide/features/#TB2d + final List? modes; + + /// create channel options with a cipher, params and modes + RealtimeChannelOptions(Object cipher, {this.params, this.modes}) + : super(cipher); +} diff --git a/lib/src/realtime/src/realtime_channels_interface.dart b/lib/src/realtime/src/realtime_channels_interface.dart new file mode 100644 index 000000000..5c8ae869d --- /dev/null +++ b/lib/src/realtime/src/realtime_channels_interface.dart @@ -0,0 +1,14 @@ +import 'package:ably_flutter/src/common/common.dart'; +import 'package:ably_flutter/src/realtime/realtime.dart'; + +/// A collection of realtime channel objects +/// +/// https://docs.ably.com/client-lib-development-guide/features/#RTS1 +abstract class RealtimeChannelsInterface + extends Channels { + /// instance of ably realtime client + RealtimeInterface realtime; + + /// instantiates with the ably [RealtimeInterface] instance + RealtimeChannelsInterface(this.realtime); +} diff --git a/lib/src/rest/rest.dart b/lib/src/rest/rest.dart index 9e46d5d52..319a658a9 100644 --- a/lib/src/rest/rest.dart +++ b/lib/src/rest/rest.dart @@ -1,6 +1,6 @@ -export 'src/channel_options.dart'; export 'src/channels.dart'; export 'src/presence.dart'; export 'src/rest.dart'; +export 'src/rest_channel_options.dart'; export 'src/rest_history_params.dart'; export 'src/rest_presence_params.dart'; diff --git a/lib/src/rest/src/channels.dart b/lib/src/rest/src/channels.dart index cc1fdf22b..7940ca990 100644 --- a/lib/src/rest/src/channels.dart +++ b/lib/src/rest/src/channels.dart @@ -3,8 +3,8 @@ import '../../common/src/channels.dart'; import '../../message/src/message.dart'; import '../../push_notifications/push_notifications.dart'; import '../rest.dart'; -import 'channel_options.dart'; import 'rest.dart'; +import 'rest_channel_options.dart'; /// A named channel through with rest client can interact with ably service. /// @@ -51,7 +51,7 @@ abstract class RestChannelInterface { /// stored channel options, then indicates success /// /// https://docs.ably.com/client-lib-development-guide/features/#RSL7 - Future setOptions(ChannelOptions options); + Future setOptions(RestChannelOptions options); } /// A collection of rest channel objects diff --git a/lib/src/rest/src/channel_options.dart b/lib/src/rest/src/rest_channel_options.dart similarity index 80% rename from lib/src/rest/src/channel_options.dart rename to lib/src/rest/src/rest_channel_options.dart index 3aa810e6c..7cdfb15df 100644 --- a/lib/src/rest/src/channel_options.dart +++ b/lib/src/rest/src/rest_channel_options.dart @@ -1,10 +1,10 @@ /// options provided when instantiating a channel /// /// https://docs.ably.com/client-lib-development-guide/features/#TB1 -class ChannelOptions { +class RestChannelOptions { /// https://docs.ably.com/client-lib-development-guide/features/#TB2b final Object cipher; /// create channel options with a cipher - ChannelOptions(this.cipher); + RestChannelOptions(this.cipher); }