From 200b2f9c05acf63f01f45062ed9396fbc5e6ecc9 Mon Sep 17 00:00:00 2001 From: Plague Fox Date: Fri, 3 May 2024 22:53:44 +0400 Subject: [PATCH] Refactor code to remove @internal annotations and update imports --- analysis_options.yaml | 6 +- lib/spinify.dart | 1 + lib/spinify.old.dart | 2 +- lib/src.old/client/config.dart | 2 +- lib/src.old/client/observer.dart | 12 +- lib/src.old/client/spinify.dart | 63 ++++---- lib/src.old/client/spinify_interface.dart | 20 +-- lib/src.old/client/states_stream.dart | 2 +- lib/src.old/model/channel_presence.dart | 4 +- lib/src.old/model/channel_push.dart | 2 +- lib/src.old/model/connect.dart | 2 +- lib/src.old/model/disconnect.dart | 2 +- lib/src.old/model/history.dart | 4 +- lib/src.old/model/message.dart | 2 +- lib/src.old/model/metrics.dart | 2 +- lib/src.old/model/presence.dart | 2 +- lib/src.old/model/publication.dart | 4 +- lib/src.old/model/pushes_stream.dart | 10 +- lib/src.old/model/refresh.dart | 2 +- lib/src.old/model/subscribe.dart | 4 +- lib/src.old/model/unsubscribe.dart | 2 +- .../client_subscription_impl.dart | 51 +++--- .../client_subscription_manager.dart | 14 +- .../server_subscription_impl.dart | 47 +++--- .../server_subscription_manager.dart | 14 +- .../subscription/subcibed_on_channel.dart | 4 +- lib/src.old/subscription/subscription.dart | 14 +- .../subscription_states_stream.dart | 2 +- .../transport/transport_interface.dart | 22 +-- .../transport/transport_protobuf_codec.dart | 5 +- .../transport/ws_protobuf_transport.dart | 61 ++++---- lib/src.old/util/event_queue.dart | 2 +- lib/src/client/spinify.dart | 0 lib/src/client/spinify_interface.dart | 146 ++++++++++++++++++ 34 files changed, 342 insertions(+), 190 deletions(-) create mode 100644 lib/spinify.dart create mode 100644 lib/src/client/spinify.dart create mode 100644 lib/src/client/spinify_interface.dart diff --git a/analysis_options.yaml b/analysis_options.yaml index c8fa7e8..06591ce 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -38,7 +38,7 @@ analyzer: empty_catches: warning # Error - always_use_package_imports: error + prefer_relative_imports: error avoid_relative_lib_imports: error avoid_slow_async_io: error avoid_types_as_parameter_names: error @@ -52,12 +52,12 @@ linter: lines_longer_than_80_chars: true # Enabling rules - always_use_package_imports: true + prefer_relative_imports: true avoid_relative_lib_imports: true # Disable rules sort_pub_dependencies: false - prefer_relative_imports: false + always_use_package_imports: false prefer_final_locals: false avoid_escaping_inner_quotes: false curly_braces_in_flow_control_structures: false diff --git a/lib/spinify.dart b/lib/spinify.dart new file mode 100644 index 0000000..5e15f82 --- /dev/null +++ b/lib/spinify.dart @@ -0,0 +1 @@ +library spinify; diff --git a/lib/spinify.old.dart b/lib/spinify.old.dart index 3caad0f..d3d228f 100644 --- a/lib/spinify.old.dart +++ b/lib/spinify.old.dart @@ -1,4 +1,4 @@ -library spinify; +library spinify.old; export 'src.old/client/config.dart'; export 'src.old/client/observer.dart'; diff --git a/lib/src.old/client/config.dart b/lib/src.old/client/config.dart index 2595e91..37b8f20 100644 --- a/lib/src.old/client/config.dart +++ b/lib/src.old/client/config.dart @@ -1,7 +1,7 @@ import 'dart:async'; import 'package:meta/meta.dart'; -import 'package:spinify/src.old/model/pubspec.yaml.g.dart'; +import '../model/pubspec.yaml.g.dart'; /// Token used for authentication /// diff --git a/lib/src.old/client/observer.dart b/lib/src.old/client/observer.dart index 37232fd..3968e32 100644 --- a/lib/src.old/client/observer.dart +++ b/lib/src.old/client/observer.dart @@ -1,9 +1,9 @@ -import 'package:spinify/src.old/client/spinify_interface.dart'; -import 'package:spinify/src.old/client/state.dart'; -import 'package:spinify/src.old/model/event.dart'; -import 'package:spinify/src.old/model/exception.dart'; -import 'package:spinify/src.old/subscription/subscription.dart'; -import 'package:spinify/src.old/subscription/subscription_state.dart'; +import '../model/event.dart'; +import '../model/exception.dart'; +import '../subscription/subscription.dart'; +import '../subscription/subscription_state.dart'; +import 'spinify_interface.dart'; +import 'state.dart'; /// An interface for observing the behavior of Spinify instances. /// {@category Client} diff --git a/lib/src.old/client/spinify.dart b/lib/src.old/client/spinify.dart index a178101..f443180 100644 --- a/lib/src.old/client/spinify.dart +++ b/lib/src.old/client/spinify.dart @@ -1,37 +1,38 @@ import 'dart:async'; import 'package:meta/meta.dart'; -import 'package:spinify/src.old/client/config.dart'; -import 'package:spinify/src.old/client/disconnect_code.dart'; -import 'package:spinify/src.old/client/observer.dart'; -import 'package:spinify/src.old/client/spinify_interface.dart'; -import 'package:spinify/src.old/client/state.dart'; -import 'package:spinify/src.old/client/states_stream.dart'; -import 'package:spinify/src.old/model/channel_presence.dart'; -import 'package:spinify/src.old/model/channel_push.dart'; -import 'package:spinify/src.old/model/connect.dart'; -import 'package:spinify/src.old/model/disconnect.dart'; -import 'package:spinify/src.old/model/event.dart'; -import 'package:spinify/src.old/model/exception.dart'; -import 'package:spinify/src.old/model/history.dart'; -import 'package:spinify/src.old/model/message.dart'; -import 'package:spinify/src.old/model/metrics.dart'; -import 'package:spinify/src.old/model/presence.dart'; -import 'package:spinify/src.old/model/presence_stats.dart'; -import 'package:spinify/src.old/model/publication.dart'; -import 'package:spinify/src.old/model/pushes_stream.dart'; -import 'package:spinify/src.old/model/refresh.dart'; -import 'package:spinify/src.old/model/stream_position.dart'; -import 'package:spinify/src.old/model/subscribe.dart'; -import 'package:spinify/src.old/model/unsubscribe.dart'; -import 'package:spinify/src.old/subscription/client_subscription_manager.dart'; -import 'package:spinify/src.old/subscription/server_subscription_manager.dart'; -import 'package:spinify/src.old/subscription/subscription.dart'; -import 'package:spinify/src.old/subscription/subscription_config.dart'; -import 'package:spinify/src.old/transport/transport_interface.dart'; -import 'package:spinify/src.old/transport/ws_protobuf_transport.dart'; -import 'package:spinify/src.old/util/event_queue.dart'; -import 'package:spinify/src.old/util/logger.dart' as logger; + +import '../model/channel_presence.dart'; +import '../model/channel_push.dart'; +import '../model/connect.dart'; +import '../model/disconnect.dart'; +import '../model/event.dart'; +import '../model/exception.dart'; +import '../model/history.dart'; +import '../model/message.dart'; +import '../model/metrics.dart'; +import '../model/presence.dart'; +import '../model/presence_stats.dart'; +import '../model/publication.dart'; +import '../model/pushes_stream.dart'; +import '../model/refresh.dart'; +import '../model/stream_position.dart'; +import '../model/subscribe.dart'; +import '../model/unsubscribe.dart'; +import '../subscription/client_subscription_manager.dart'; +import '../subscription/server_subscription_manager.dart'; +import '../subscription/subscription.dart'; +import '../subscription/subscription_config.dart'; +import '../transport/transport_interface.dart'; +import '../transport/ws_protobuf_transport.dart'; +import '../util/event_queue.dart'; +import '../util/logger.dart' as logger; +import 'config.dart'; +import 'disconnect_code.dart'; +import 'observer.dart'; +import 'spinify_interface.dart'; +import 'state.dart'; +import 'states_stream.dart'; /// {@template spinify} /// Spinify client for Centrifuge. diff --git a/lib/src.old/client/spinify_interface.dart b/lib/src.old/client/spinify_interface.dart index 3d93969..5158298 100644 --- a/lib/src.old/client/spinify_interface.dart +++ b/lib/src.old/client/spinify_interface.dart @@ -2,16 +2,16 @@ import 'dart:async'; -import 'package:spinify/src.old/client/state.dart'; -import 'package:spinify/src.old/client/states_stream.dart'; -import 'package:spinify/src.old/model/history.dart'; -import 'package:spinify/src.old/model/metrics.dart'; -import 'package:spinify/src.old/model/presence.dart'; -import 'package:spinify/src.old/model/presence_stats.dart'; -import 'package:spinify/src.old/model/pushes_stream.dart'; -import 'package:spinify/src.old/model/stream_position.dart'; -import 'package:spinify/src.old/subscription/subscription.dart'; -import 'package:spinify/src.old/subscription/subscription_config.dart'; +import '../model/history.dart'; +import '../model/metrics.dart'; +import '../model/presence.dart'; +import '../model/presence_stats.dart'; +import '../model/pushes_stream.dart'; +import '../model/stream_position.dart'; +import '../subscription/subscription.dart'; +import '../subscription/subscription_config.dart'; +import 'state.dart'; +import 'states_stream.dart'; /// Spinify client interface. abstract interface class ISpinify diff --git a/lib/src.old/client/states_stream.dart b/lib/src.old/client/states_stream.dart index 3f5acbf..5c2996c 100644 --- a/lib/src.old/client/states_stream.dart +++ b/lib/src.old/client/states_stream.dart @@ -1,6 +1,6 @@ import 'dart:async'; -import 'package:spinify/src.old/client/state.dart'; +import 'state.dart'; /// Stream of Spinify's [SpinifyState] changes. /// {@category Client} diff --git a/lib/src.old/model/channel_presence.dart b/lib/src.old/model/channel_presence.dart index d0a9f19..cc2d5cb 100644 --- a/lib/src.old/model/channel_presence.dart +++ b/lib/src.old/model/channel_presence.dart @@ -1,6 +1,6 @@ import 'package:meta/meta.dart'; -import 'package:spinify/src.old/model/channel_push.dart'; -import 'package:spinify/src.old/model/client_info.dart'; +import 'channel_push.dart'; +import 'client_info.dart'; /// {@template channel_presence} /// Channel presence. diff --git a/lib/src.old/model/channel_push.dart b/lib/src.old/model/channel_push.dart index 6297afe..f8716d2 100644 --- a/lib/src.old/model/channel_push.dart +++ b/lib/src.old/model/channel_push.dart @@ -1,5 +1,5 @@ import 'package:meta/meta.dart'; -import 'package:spinify/src.old/model/event.dart'; +import 'event.dart'; /// {@template spinify_channel_push} /// Base class for all channel push events. diff --git a/lib/src.old/model/connect.dart b/lib/src.old/model/connect.dart index 3352bb7..7af4476 100644 --- a/lib/src.old/model/connect.dart +++ b/lib/src.old/model/connect.dart @@ -1,4 +1,4 @@ -import 'package:spinify/src.old/model/channel_push.dart'; +import 'channel_push.dart'; /// {@template connect} /// Connect push from Centrifugo server. diff --git a/lib/src.old/model/disconnect.dart b/lib/src.old/model/disconnect.dart index 6c0e6b8..d29f24b 100644 --- a/lib/src.old/model/disconnect.dart +++ b/lib/src.old/model/disconnect.dart @@ -1,4 +1,4 @@ -import 'package:spinify/src.old/model/channel_push.dart'; +import 'channel_push.dart'; /// {@template disconnect} /// Disconnect push from Centrifugo server. diff --git a/lib/src.old/model/history.dart b/lib/src.old/model/history.dart index 737e917..256e531 100644 --- a/lib/src.old/model/history.dart +++ b/lib/src.old/model/history.dart @@ -1,6 +1,6 @@ import 'package:meta/meta.dart'; -import 'package:spinify/src.old/model/publication.dart'; -import 'package:spinify/src.old/model/stream_position.dart'; +import 'publication.dart'; +import 'stream_position.dart'; /// {@template history} /// History diff --git a/lib/src.old/model/message.dart b/lib/src.old/model/message.dart index 23f2f10..7066365 100644 --- a/lib/src.old/model/message.dart +++ b/lib/src.old/model/message.dart @@ -1,4 +1,4 @@ -import 'package:spinify/src.old/model/channel_push.dart'; +import 'channel_push.dart'; /// {@template message} /// Message push from Centrifugo server. diff --git a/lib/src.old/model/metrics.dart b/lib/src.old/model/metrics.dart index e508e32..5250e36 100644 --- a/lib/src.old/model/metrics.dart +++ b/lib/src.old/model/metrics.dart @@ -1,5 +1,5 @@ import 'package:meta/meta.dart'; -import 'package:spinify/src.old/client/state.dart'; +import '../client/state.dart'; /// Subscription count /// - total diff --git a/lib/src.old/model/presence.dart b/lib/src.old/model/presence.dart index 9b619b1..65fd7e2 100644 --- a/lib/src.old/model/presence.dart +++ b/lib/src.old/model/presence.dart @@ -1,5 +1,5 @@ import 'package:meta/meta.dart'; -import 'package:spinify/src.old/model/client_info.dart'; +import 'client_info.dart'; /// {@template presence} /// Presence diff --git a/lib/src.old/model/publication.dart b/lib/src.old/model/publication.dart index bae4ae8..2c9e27f 100644 --- a/lib/src.old/model/publication.dart +++ b/lib/src.old/model/publication.dart @@ -1,7 +1,7 @@ import 'package:fixnum/fixnum.dart' as fixnum; import 'package:meta/meta.dart'; -import 'package:spinify/src.old/model/channel_push.dart'; -import 'package:spinify/src.old/model/client_info.dart'; +import 'channel_push.dart'; +import 'client_info.dart'; /// {@template publication} /// Publication context diff --git a/lib/src.old/model/pushes_stream.dart b/lib/src.old/model/pushes_stream.dart index c2bc711..acdaf95 100644 --- a/lib/src.old/model/pushes_stream.dart +++ b/lib/src.old/model/pushes_stream.dart @@ -1,11 +1,11 @@ import 'dart:async'; import 'package:meta/meta.dart'; -import 'package:spinify/src.old/model/channel_presence.dart'; -import 'package:spinify/src.old/model/channel_push.dart'; -import 'package:spinify/src.old/model/event.dart'; -import 'package:spinify/src.old/model/message.dart'; -import 'package:spinify/src.old/model/publication.dart'; +import 'channel_presence.dart'; +import 'channel_push.dart'; +import 'event.dart'; +import 'message.dart'; +import 'publication.dart'; /// Stream of received pushes from Centrifugo server for a channel. /// {@category Event} diff --git a/lib/src.old/model/refresh.dart b/lib/src.old/model/refresh.dart index 73e7d2a..fb635d5 100644 --- a/lib/src.old/model/refresh.dart +++ b/lib/src.old/model/refresh.dart @@ -1,4 +1,4 @@ -import 'package:spinify/src.old/model/channel_push.dart'; +import 'channel_push.dart'; /// {@template refresh} /// Refresh push from Centrifugo server. diff --git a/lib/src.old/model/subscribe.dart b/lib/src.old/model/subscribe.dart index bd4d286..b855747 100644 --- a/lib/src.old/model/subscribe.dart +++ b/lib/src.old/model/subscribe.dart @@ -1,5 +1,5 @@ -import 'package:spinify/src.old/model/channel_push.dart'; -import 'package:spinify/src.old/model/stream_position.dart'; +import 'channel_push.dart'; +import 'stream_position.dart'; /// {@template subscribe} /// Subscribe push from Centrifugo server. diff --git a/lib/src.old/model/unsubscribe.dart b/lib/src.old/model/unsubscribe.dart index 70c5378..c312cb0 100644 --- a/lib/src.old/model/unsubscribe.dart +++ b/lib/src.old/model/unsubscribe.dart @@ -1,4 +1,4 @@ -import 'package:spinify/src.old/model/channel_push.dart'; +import 'channel_push.dart'; /// {@template unsubscribe} /// Unsubscribe push from Centrifugo server. diff --git a/lib/src.old/subscription/client_subscription_impl.dart b/lib/src.old/subscription/client_subscription_impl.dart index 5bc30a2..90d9abe 100644 --- a/lib/src.old/subscription/client_subscription_impl.dart +++ b/lib/src.old/subscription/client_subscription_impl.dart @@ -2,31 +2,32 @@ import 'dart:async'; import 'package:fixnum/fixnum.dart' as fixnum; import 'package:meta/meta.dart'; -import 'package:spinify/src.old/client/disconnect_code.dart'; -import 'package:spinify/src.old/client/spinify.dart'; -import 'package:spinify/src.old/model/channel_presence.dart'; -import 'package:spinify/src.old/model/channel_push.dart'; -import 'package:spinify/src.old/model/connect.dart'; -import 'package:spinify/src.old/model/disconnect.dart'; -import 'package:spinify/src.old/model/event.dart'; -import 'package:spinify/src.old/model/exception.dart'; -import 'package:spinify/src.old/model/history.dart'; -import 'package:spinify/src.old/model/message.dart'; -import 'package:spinify/src.old/model/presence.dart'; -import 'package:spinify/src.old/model/presence_stats.dart'; -import 'package:spinify/src.old/model/publication.dart'; -import 'package:spinify/src.old/model/pushes_stream.dart'; -import 'package:spinify/src.old/model/refresh.dart'; -import 'package:spinify/src.old/model/stream_position.dart'; -import 'package:spinify/src.old/model/subscribe.dart'; -import 'package:spinify/src.old/model/unsubscribe.dart'; -import 'package:spinify/src.old/subscription/subscription.dart'; -import 'package:spinify/src.old/subscription/subscription_config.dart'; -import 'package:spinify/src.old/subscription/subscription_state.dart'; -import 'package:spinify/src.old/subscription/subscription_states_stream.dart'; -import 'package:spinify/src.old/transport/transport_interface.dart'; -import 'package:spinify/src.old/util/event_queue.dart'; -import 'package:spinify/src.old/util/logger.dart' as logger; + +import '../client/disconnect_code.dart'; +import '../client/spinify.dart'; +import '../model/channel_presence.dart'; +import '../model/channel_push.dart'; +import '../model/connect.dart'; +import '../model/disconnect.dart'; +import '../model/event.dart'; +import '../model/exception.dart'; +import '../model/history.dart'; +import '../model/message.dart'; +import '../model/presence.dart'; +import '../model/presence_stats.dart'; +import '../model/publication.dart'; +import '../model/pushes_stream.dart'; +import '../model/refresh.dart'; +import '../model/stream_position.dart'; +import '../model/subscribe.dart'; +import '../model/unsubscribe.dart'; +import '../transport/transport_interface.dart'; +import '../util/event_queue.dart'; +import '../util/logger.dart' as logger; +import 'subscription.dart'; +import 'subscription_config.dart'; +import 'subscription_state.dart'; +import 'subscription_states_stream.dart'; /// Client-side subscription implementation. final class SpinifyClientSubscriptionImpl extends SpinifyClientSubscriptionBase diff --git a/lib/src.old/subscription/client_subscription_manager.dart b/lib/src.old/subscription/client_subscription_manager.dart index f10b85f..5c222ad 100644 --- a/lib/src.old/subscription/client_subscription_manager.dart +++ b/lib/src.old/subscription/client_subscription_manager.dart @@ -1,12 +1,12 @@ import 'dart:collection'; -import 'package:spinify/src.old/model/channel_push.dart'; -import 'package:spinify/src.old/model/exception.dart'; -import 'package:spinify/src.old/subscription/client_subscription_impl.dart'; -import 'package:spinify/src.old/subscription/subscription.dart'; -import 'package:spinify/src.old/subscription/subscription_config.dart'; -import 'package:spinify/src.old/subscription/subscription_state.dart'; -import 'package:spinify/src.old/transport/transport_interface.dart'; +import '../model/channel_push.dart'; +import '../model/exception.dart'; +import '../transport/transport_interface.dart'; +import 'client_subscription_impl.dart'; +import 'subscription.dart'; +import 'subscription_config.dart'; +import 'subscription_state.dart'; /// Responsible for managing client-side subscriptions. final class ClientSubscriptionManager { diff --git a/lib/src.old/subscription/server_subscription_impl.dart b/lib/src.old/subscription/server_subscription_impl.dart index b6b2f65..0297568 100644 --- a/lib/src.old/subscription/server_subscription_impl.dart +++ b/lib/src.old/subscription/server_subscription_impl.dart @@ -2,29 +2,30 @@ import 'dart:async'; import 'package:fixnum/fixnum.dart' as fixnum; import 'package:meta/meta.dart'; -import 'package:spinify/src.old/client/spinify.dart'; -import 'package:spinify/src.old/model/channel_presence.dart'; -import 'package:spinify/src.old/model/channel_push.dart'; -import 'package:spinify/src.old/model/connect.dart'; -import 'package:spinify/src.old/model/disconnect.dart'; -import 'package:spinify/src.old/model/event.dart'; -import 'package:spinify/src.old/model/exception.dart'; -import 'package:spinify/src.old/model/history.dart'; -import 'package:spinify/src.old/model/message.dart'; -import 'package:spinify/src.old/model/presence.dart'; -import 'package:spinify/src.old/model/presence_stats.dart'; -import 'package:spinify/src.old/model/publication.dart'; -import 'package:spinify/src.old/model/pushes_stream.dart'; -import 'package:spinify/src.old/model/refresh.dart'; -import 'package:spinify/src.old/model/stream_position.dart'; -import 'package:spinify/src.old/model/subscribe.dart'; -import 'package:spinify/src.old/model/unsubscribe.dart'; -import 'package:spinify/src.old/subscription/subscription.dart'; -import 'package:spinify/src.old/subscription/subscription_state.dart'; -import 'package:spinify/src.old/subscription/subscription_states_stream.dart'; -import 'package:spinify/src.old/transport/transport_interface.dart'; -import 'package:spinify/src.old/util/event_queue.dart'; -import 'package:spinify/src.old/util/logger.dart' as logger; + +import '../client/spinify.dart'; +import '../model/channel_presence.dart'; +import '../model/channel_push.dart'; +import '../model/connect.dart'; +import '../model/disconnect.dart'; +import '../model/event.dart'; +import '../model/exception.dart'; +import '../model/history.dart'; +import '../model/message.dart'; +import '../model/presence.dart'; +import '../model/presence_stats.dart'; +import '../model/publication.dart'; +import '../model/pushes_stream.dart'; +import '../model/refresh.dart'; +import '../model/stream_position.dart'; +import '../model/subscribe.dart'; +import '../model/unsubscribe.dart'; +import '../transport/transport_interface.dart'; +import '../util/event_queue.dart'; +import '../util/logger.dart' as logger; +import 'subscription.dart'; +import 'subscription_state.dart'; +import 'subscription_states_stream.dart'; /// Server-side subscription implementation. final class SpinifyServerSubscriptionImpl extends SpinifyServerSubscriptionBase diff --git a/lib/src.old/subscription/server_subscription_manager.dart b/lib/src.old/subscription/server_subscription_manager.dart index 27b5bbd..258b74d 100644 --- a/lib/src.old/subscription/server_subscription_manager.dart +++ b/lib/src.old/subscription/server_subscription_manager.dart @@ -1,12 +1,12 @@ import 'dart:collection'; -import 'package:spinify/src.old/model/channel_push.dart'; -import 'package:spinify/src.old/model/subscribe.dart'; -import 'package:spinify/src.old/model/unsubscribe.dart'; -import 'package:spinify/src.old/subscription/server_subscription_impl.dart'; -import 'package:spinify/src.old/subscription/subscription.dart'; -import 'package:spinify/src.old/subscription/subscription_state.dart'; -import 'package:spinify/src.old/transport/transport_interface.dart'; +import '../model/channel_push.dart'; +import '../model/subscribe.dart'; +import '../model/unsubscribe.dart'; +import '../transport/transport_interface.dart'; +import 'server_subscription_impl.dart'; +import 'subscription.dart'; +import 'subscription_state.dart'; /// Responsible for managing client-side subscriptions. final class ServerSubscriptionManager { diff --git a/lib/src.old/subscription/subcibed_on_channel.dart b/lib/src.old/subscription/subcibed_on_channel.dart index 6198e0a..a86b15b 100644 --- a/lib/src.old/subscription/subcibed_on_channel.dart +++ b/lib/src.old/subscription/subcibed_on_channel.dart @@ -1,6 +1,6 @@ import 'package:meta/meta.dart'; -import 'package:spinify/src.old/model/publication.dart'; -import 'package:spinify/src.old/model/stream_position.dart'; +import '../model/publication.dart'; +import '../model/stream_position.dart'; /// Subscribed on channel message. /// {@category Subscription} diff --git a/lib/src.old/subscription/subscription.dart b/lib/src.old/subscription/subscription.dart index 1041538..f268ae4 100644 --- a/lib/src.old/subscription/subscription.dart +++ b/lib/src.old/subscription/subscription.dart @@ -1,12 +1,12 @@ import 'dart:async'; -import 'package:spinify/src.old/model/history.dart'; -import 'package:spinify/src.old/model/presence.dart'; -import 'package:spinify/src.old/model/presence_stats.dart'; -import 'package:spinify/src.old/model/pushes_stream.dart'; -import 'package:spinify/src.old/model/stream_position.dart'; -import 'package:spinify/src.old/subscription/subscription_state.dart'; -import 'package:spinify/src.old/subscription/subscription_states_stream.dart'; +import '../model/history.dart'; +import '../model/presence.dart'; +import '../model/presence_stats.dart'; +import '../model/pushes_stream.dart'; +import '../model/stream_position.dart'; +import 'subscription_state.dart'; +import 'subscription_states_stream.dart'; /// {@template subscription} /// Spinify subscription interface. diff --git a/lib/src.old/subscription/subscription_states_stream.dart b/lib/src.old/subscription/subscription_states_stream.dart index c24ae7e..428c57e 100644 --- a/lib/src.old/subscription/subscription_states_stream.dart +++ b/lib/src.old/subscription/subscription_states_stream.dart @@ -1,7 +1,7 @@ import 'dart:async'; import 'package:meta/meta.dart'; -import 'package:spinify/src.old/subscription/subscription_state.dart'; +import 'subscription_state.dart'; /// Stream of Spinify's [SpinifySubscriptionState] changes. /// {@category Subscription} diff --git a/lib/src.old/transport/transport_interface.dart b/lib/src.old/transport/transport_interface.dart index 15a18ef..cf8ae41 100644 --- a/lib/src.old/transport/transport_interface.dart +++ b/lib/src.old/transport/transport_interface.dart @@ -1,16 +1,16 @@ import 'dart:async'; -import 'package:spinify/src.old/client/state.dart'; -import 'package:spinify/src.old/model/event.dart'; -import 'package:spinify/src.old/model/history.dart'; -import 'package:spinify/src.old/model/presence.dart'; -import 'package:spinify/src.old/model/presence_stats.dart'; -import 'package:spinify/src.old/model/refresh_result.dart'; -import 'package:spinify/src.old/model/stream_position.dart'; -import 'package:spinify/src.old/subscription/server_subscription_manager.dart'; -import 'package:spinify/src.old/subscription/subcibed_on_channel.dart'; -import 'package:spinify/src.old/subscription/subscription_config.dart'; -import 'package:spinify/src.old/util/notifier.dart'; +import '../client/state.dart'; +import '../model/event.dart'; +import '../model/history.dart'; +import '../model/presence.dart'; +import '../model/presence_stats.dart'; +import '../model/refresh_result.dart'; +import '../model/stream_position.dart'; +import '../subscription/server_subscription_manager.dart'; +import '../subscription/subcibed_on_channel.dart'; +import '../subscription/subscription_config.dart'; +import '../util/notifier.dart'; /// Class responsible for sending and receiving data from the server. abstract interface class ISpinifyTransport { diff --git a/lib/src.old/transport/transport_protobuf_codec.dart b/lib/src.old/transport/transport_protobuf_codec.dart index 9313add..303885d 100644 --- a/lib/src.old/transport/transport_protobuf_codec.dart +++ b/lib/src.old/transport/transport_protobuf_codec.dart @@ -1,8 +1,9 @@ import 'dart:convert'; import 'package:protobuf/protobuf.dart' as pb; -import 'package:spinify/src.old/transport/protobuf/client.pb.dart' as pb; -import 'package:spinify/src.old/util/logger.dart' as logger; + +import '../util/logger.dart' as logger; +import 'protobuf/client.pb.dart' as pb; /// Codec for encoding and decoding protobuf messages. final class TransportProtobufCodec extends Codec> { diff --git a/lib/src.old/transport/ws_protobuf_transport.dart b/lib/src.old/transport/ws_protobuf_transport.dart index 509ccff..1246d76 100644 --- a/lib/src.old/transport/ws_protobuf_transport.dart +++ b/lib/src.old/transport/ws_protobuf_transport.dart @@ -4,38 +4,39 @@ import 'dart:convert'; import 'package:meta/meta.dart'; import 'package:protobuf/protobuf.dart' as pb; -import 'package:spinify/src.old/client/config.dart'; -import 'package:spinify/src.old/client/disconnect_code.dart'; -import 'package:spinify/src.old/client/state.dart'; -import 'package:spinify/src.old/model/channel_presence.dart'; -import 'package:spinify/src.old/model/client_info.dart'; -import 'package:spinify/src.old/model/connect.dart'; -import 'package:spinify/src.old/model/disconnect.dart'; -import 'package:spinify/src.old/model/event.dart'; -import 'package:spinify/src.old/model/exception.dart'; -import 'package:spinify/src.old/model/history.dart'; -import 'package:spinify/src.old/model/message.dart'; -import 'package:spinify/src.old/model/presence.dart'; -import 'package:spinify/src.old/model/presence_stats.dart'; -import 'package:spinify/src.old/model/publication.dart'; -import 'package:spinify/src.old/model/refresh.dart'; -import 'package:spinify/src.old/model/refresh_result.dart'; -import 'package:spinify/src.old/model/stream_position.dart'; -import 'package:spinify/src.old/model/subscribe.dart'; -import 'package:spinify/src.old/model/unsubscribe.dart'; -import 'package:spinify/src.old/subscription/server_subscription_manager.dart'; -import 'package:spinify/src.old/subscription/subcibed_on_channel.dart'; -import 'package:spinify/src.old/subscription/subscription.dart'; -import 'package:spinify/src.old/subscription/subscription_config.dart'; -import 'package:spinify/src.old/subscription/subscription_state.dart'; -import 'package:spinify/src.old/transport/protobuf/client.pb.dart' as pb; -import 'package:spinify/src.old/transport/transport_interface.dart'; -import 'package:spinify/src.old/transport/transport_protobuf_codec.dart'; -import 'package:spinify/src.old/util/logger.dart' as logger; -import 'package:spinify/src.old/util/notifier.dart'; -import 'package:spinify/src.old/util/speed_meter.dart'; import 'package:ws/ws.dart'; +import '../client/config.dart'; +import '../client/disconnect_code.dart'; +import '../client/state.dart'; +import '../model/channel_presence.dart'; +import '../model/client_info.dart'; +import '../model/connect.dart'; +import '../model/disconnect.dart'; +import '../model/event.dart'; +import '../model/exception.dart'; +import '../model/history.dart'; +import '../model/message.dart'; +import '../model/presence.dart'; +import '../model/presence_stats.dart'; +import '../model/publication.dart'; +import '../model/refresh.dart'; +import '../model/refresh_result.dart'; +import '../model/stream_position.dart'; +import '../model/subscribe.dart'; +import '../model/unsubscribe.dart'; +import '../subscription/server_subscription_manager.dart'; +import '../subscription/subcibed_on_channel.dart'; +import '../subscription/subscription.dart'; +import '../subscription/subscription_config.dart'; +import '../subscription/subscription_state.dart'; +import '../util/logger.dart' as logger; +import '../util/notifier.dart'; +import '../util/speed_meter.dart'; +import 'protobuf/client.pb.dart' as pb; +import 'transport_interface.dart'; +import 'transport_protobuf_codec.dart'; + /// Base class for Spinify transport with Protobuf & WebSocket protocol. abstract base class SpinifyWSPBTransportBase implements ISpinifyTransport { /// Create a new instance of [SpinifyWSPBTransportBase]. diff --git a/lib/src.old/util/event_queue.dart b/lib/src.old/util/event_queue.dart index bc41a0c..85c4ef4 100644 --- a/lib/src.old/util/event_queue.dart +++ b/lib/src.old/util/event_queue.dart @@ -1,7 +1,7 @@ import 'dart:async'; import 'dart:collection'; -import 'package:spinify/src.old/util/logger.dart'; +import 'logger.dart'; /// Event Queue final class SpinifyEventQueue { diff --git a/lib/src/client/spinify.dart b/lib/src/client/spinify.dart new file mode 100644 index 0000000..e69de29 diff --git a/lib/src/client/spinify_interface.dart b/lib/src/client/spinify_interface.dart new file mode 100644 index 0000000..52db27e --- /dev/null +++ b/lib/src/client/spinify_interface.dart @@ -0,0 +1,146 @@ +// ignore_for_file: one_member_abstracts + +import 'dart:async'; + +import '../../src.old/client/state.dart'; +import '../../src.old/client/states_stream.dart'; +import '../../src.old/model/history.dart'; +import '../../src.old/model/metrics.dart'; +import '../../src.old/model/presence.dart'; +import '../../src.old/model/presence_stats.dart'; +import '../../src.old/model/pushes_stream.dart'; +import '../../src.old/model/stream_position.dart'; +import '../../src.old/subscription/subscription.dart'; +import '../../src.old/subscription/subscription_config.dart'; + +/// Spinify client interface. +abstract interface class ISpinify + implements + ISpinifyStateOwner, + ISpinifyAsyncMessageSender, + ISpinifyPublicationSender, + ISpinifyEventReceiver, + ISpinifySubscriptionsManager, + ISpinifyPresenceOwner, + ISpinifyHistoryOwner, + ISpinifyRemoteProcedureCall, + ISpinifyMetricsOwner { + /// Connect to the server. + /// [url] is a URL of endpoint. + Future connect(String url); + + /// Ready resolves when client successfully connected. + /// Throws exceptions if called not in connecting or connected state. + FutureOr ready(); + + /// Disconnect from the server. + Future disconnect([ + int code = 0, + String reason = 'Disconnect called', + ]); + + /// Client if not needed anymore. + /// Permanent close connection to the server and + /// free all allocated resources. + Future close(); +} + +/// Spinify client state owner interface. +abstract interface class ISpinifyStateOwner { + /// State of client. + SpinifyState get state; + + /// Stream of client states. + abstract final SpinifyStatesStream states; +} + +/// Spinify send publication interface. +abstract interface class ISpinifyPublicationSender { + /// Publish data to specific subscription channel + Future publish(String channel, List data); +} + +/// Spinify send asynchronous message interface. +abstract interface class ISpinifyAsyncMessageSender { + /// Send asynchronous message to a server. This method makes sense + /// only when using Centrifuge library for Go on a server side. In Centrifugo + /// asynchronous message handler does not exist. + Future send(List data); +} + +/// Spinify event receiver interface. +abstract interface class ISpinifyEventReceiver { + /// Stream of received pushes from Centrifugo server for a channel. + abstract final SpinifyPushesStream stream; +} + +/// Spinify client subscriptions manager interface. +abstract interface class ISpinifySubscriptionsManager { + /// Create new client-side subscription. + /// `newSubscription(channel, config)` allocates a new Subscription + /// in the registry or throws an exception if the Subscription + /// is already there. We will discuss common Subscription options below. + SpinifyClientSubscription newSubscription( + String channel, [ + SpinifySubscriptionConfig? config, + ]); + + /// Get subscription to the channel + /// from internal registry or null if not found. + /// + /// You need to call [SpinifyClientSubscription.subscribe] + /// to start receiving events + /// in the channel. + SpinifyClientSubscription? getSubscription(String channel); + + /// Remove the [SpinifySubscription] from internal registry + /// and unsubscribe from [SpinifyClientSubscription.channel]. + Future removeSubscription(SpinifyClientSubscription subscription); + + /// Get map wirth all registered client-side & server-side subscriptions. + /// Returns all registered subscriptions, + /// so you can iterate over all and do some action if required. + /// + /// For example: + /// ```dart + /// final subscription = spinify.subscriptions.client['chat']!; + /// await subscription.unsubscribe(); + /// ``` + ({ + Map client, + Map server, + }) get subscriptions; +} + +/// Spinify presence owner interface. +abstract interface class ISpinifyPresenceOwner { + /// Fetch presence information inside a channel. + Future presence(String channel); + + /// Fetch presence stats information inside a channel. + Future presenceStats(String channel); +} + +/// Spinify history owner interface. +abstract interface class ISpinifyHistoryOwner { + /// Fetch publication history inside a channel. + /// Only for channels where history is enabled. + Future history( + String channel, { + int? limit, + SpinifyStreamPosition? since, + bool? reverse, + }); +} + +/// Spinify remote procedure call interface. +abstract interface class ISpinifyRemoteProcedureCall { + /// Send arbitrary RPC and wait for response. + Future> rpc(String method, List data); +} + +/// Spinify metrics interface. +abstract interface class ISpinifyMetricsOwner { + /// Get metrics of Spinify client. + SpinifyMetrics get metrics; +}