diff --git a/.github/workflows/checkout.yml b/.github/workflows/checkout.yml index c65cd9f..883528b 100644 --- a/.github/workflows/checkout.yml +++ b/.github/workflows/checkout.yml @@ -46,11 +46,11 @@ jobs: - name: 🚃 Cache pub modules uses: actions/cache@v2 env: - cache-name: cache-centrifuge-package + cache-name: cache-spinify-package with: path: | $PWD/.pub_cache/ - key: ${{ runner.os }}-centrifuge-${{ env.cache-name }}-${{ hashFiles('**/pubspec.yaml') }} + key: ${{ runner.os }}-spinify-${{ env.cache-name }}-${{ hashFiles('**/pubspec.yaml') }} - name: 🗄️ Export pub cache directory run: export PUB_CACHE=$PWD/.pub_cache/ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..27c36da --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,40 @@ +# Spinify: contribution guide + +## How to regenerate protobuf files + +Windows: + +```ps1 +$ choco install protoc +$ dart pub global activate protoc_plugin +$ dart pub get +$ protoc --proto_path=lib/src/model/protobuf --dart_out=lib/src/model/protobuf lib/src/model/protobuf/client.proto +$ dart run build_runner build --delete-conflicting-outputs +$ dart format -l 80 lib/src/model/pubspec.yaml.g.dart lib/src/model/protobuf/ +``` + +Linux: + +```bash +$ sudo apt update +$ sudo apt install -y protobuf-compiler dart +$ export PATH="$PATH":"$HOME/.pub-cache/bin" +$ dart pub global activate protoc_plugin +$ dart pub get +$ protoc --proto_path=lib/src/model/protobuf --dart_out=lib/src/model/protobuf lib/src/model/protobuf/client.proto +$ dart run build_runner build --delete-conflicting-outputs +$ dart format -l 80 lib/src/model/pubspec.yaml.g.dart lib/src/model/protobuf/ +``` + +macOS: + +```zsh +$ brew update +$ brew install protobuf dart +$ export PATH="$PATH":"$HOME/.pub-cache/bin" +$ dart pub global activate protoc_plugin +$ dart pub get +$ protoc --proto_path=lib/src/model/protobuf --dart_out=lib/src/model/protobuf lib/src/model/protobuf/client.proto +$ dart run build_runner build --delete-conflicting-outputs +$ dart format -l 80 lib/src/model/pubspec.yaml.g.dart lib/src/model/protobuf/ +``` diff --git a/README.md b/README.md index 7885580..8e4bac5 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,11 @@ -# Centrifuge Dart +# Spinify + +[![Pub](https://img.shields.io/pub/v/spinify.svg)](https://pub.dev/packages/spinify) +[![Actions Status](https://github.com/PlugFox/spinify/actions/workflows/checkout.yml/badge.svg)](https://github.com/PlugFox/spinify/actions) +[![Coverage](https://codecov.io/gh/PlugFox/spinify/branch/master/graph/badge.svg)](https://codecov.io/gh/PlugFox/spinify) +[![License: MIT](https://img.shields.io/badge/license-MIT-purple.svg)](https://opensource.org/licenses/MIT) +[![Linter](https://img.shields.io/badge/style-linter-40c4ff.svg)](https://pub.dev/packages/linter) +[![GitHub stars](https://img.shields.io/github/stars/plugfox/spinify?style=social)](https://github.com/plugfox/spinify/) Websocket client for [Centrifugo server](https://github.com/centrifugal/centrifugo) and [Centrifuge library](https://github.com/centrifugal/centrifuge) based on [ws library](https://pub.dev/packages/ws). @@ -8,46 +15,7 @@ Add the following dependency to your `pubspec.yaml` file: ```yaml dependencies: - centrifuge_dart: -``` - -## How to regenerate protobuf files - -Windows: - -```ps1 -$ choco install protoc -$ dart pub global activate protoc_plugin -$ dart pub get -$ protoc --proto_path=lib/src/model/protobuf --dart_out=lib/src/model/protobuf lib/src/model/protobuf/client.proto -$ dart run build_runner build --delete-conflicting-outputs -$ dart format -l 80 lib/src/model/pubspec.yaml.g.dart lib/src/model/protobuf/ -``` - -Linux: - -```bash -$ sudo apt update -$ sudo apt install -y protobuf-compiler dart -$ export PATH="$PATH":"$HOME/.pub-cache/bin" -$ dart pub global activate protoc_plugin -$ dart pub get -$ protoc --proto_path=lib/src/model/protobuf --dart_out=lib/src/model/protobuf lib/src/model/protobuf/client.proto -$ dart run build_runner build --delete-conflicting-outputs -$ dart format -l 80 lib/src/model/pubspec.yaml.g.dart lib/src/model/protobuf/ -``` - -macOS: - -```zsh -$ brew update -$ brew install protobuf dart -$ export PATH="$PATH":"$HOME/.pub-cache/bin" -$ dart pub global activate protoc_plugin -$ dart pub get -$ protoc --proto_path=lib/src/model/protobuf --dart_out=lib/src/model/protobuf lib/src/model/protobuf/client.proto -$ dart run build_runner build --delete-conflicting-outputs -$ dart format -l 80 lib/src/model/pubspec.yaml.g.dart lib/src/model/protobuf/ + spinify: ``` ## Features and Roadmap @@ -58,32 +26,34 @@ Connection related features - ✅ Setting client options - ✅ Automatic reconnect with backoff algorithm - ✅ Client state changes -- ❌ Command-reply -- ❌ Command timeouts -- ❌ Async pushes -- ❌ Ping-pong -- ❌ Connection token refresh +- ✅ Command-reply +- ✅ Command timeouts +- ✅ Async pushes +- ✅ Ping-pong +- ✅ Connection token refresh +- ✅ Server-side subscriptions - ❌ Handle disconnect advice from the server -- ❌ Server-side subscriptions - ❌ Batching API - ❌ Bidirectional WebSocket emulation ### Client-side features -- ❌ Subscribe to a channel -- ❌ Setting subscription options -- ❌ Automatic resubscribe with backoff algorithm -- ❌ Subscription state changes -- ❌ Subscription command-reply -- ❌ Subscription async pushes -- ❌ Subscription token refresh -- ❌ Handle unsubscribe advice from the server -- ❌ Manage subscription registry +- ✅ Subscribe to a channel +- ✅ Setting subscription options +- ✅ Automatic resubscribe with backoff algorithm +- ✅ Subscription state changes +- ✅ Subscription command-reply +- ✅ Subscription async pushes +- ✅ Subscription token refresh +- ✅ Handle unsubscribe advice from the server +- ✅ Manage subscription registry - ❌ Optimistic subscriptions +## Example + ## More resources -- [Library documentation](https://pub.dev/documentation/centrifuge_dart/latest/) +- [Library documentation](https://pub.dev/documentation/spinify/latest/) - [RFC 6455: The WebSocket Protocol](https://tools.ietf.org/html/rfc6455) - [WebSocket API on MDN](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API) - [Dart HTML WebSocket library](https://api.dart.dev/stable/dart-html/WebSocket-class.html) @@ -96,11 +66,11 @@ Connection related features ## Coverage -[![](https://codecov.io/gh/PlugFox/centrifuge-dart/branch/master/graphs/sunburst.svg)](https://codecov.io/gh/PlugFox/centrifuge-dart/branch/master) +[![](https://codecov.io/gh/PlugFox/spinify/branch/master/graphs/sunburst.svg)](https://codecov.io/gh/PlugFox/spinify/branch/master) ## Changelog -Refer to the [Changelog](https://github.com/PlugFox/centrifuge-dart/blob/master/CHANGELOG.md) to get all release notes. +Refer to the [Changelog](https://github.com/PlugFox/spinify/blob/master/CHANGELOG.md) to get all release notes. ## Maintainers diff --git a/examples/console/bin/main.dart b/examples/console/bin/main.dart index 231120f..7b2b6df 100644 --- a/examples/console/bin/main.dart +++ b/examples/console/bin/main.dart @@ -4,7 +4,7 @@ import 'dart:async'; import 'dart:io' as io show exit, Platform; import 'package:args/args.dart' show ArgParser; -import 'package:centrifuge_dart/centrifuge.dart'; +import 'package:spinify/spinify.dart'; const url = 'ws://localhost:8000/connection/websocket?format=protobuf'; @@ -13,8 +13,8 @@ void main([List? args]) { runZonedGuarded( () async { // Create centrifuge client. - final client = Centrifuge( - CentrifugeConfig( + final client = Spinify( + SpinifyConfig( client: ( name: 'Centrifuge Console Example', version: '0.0.1', diff --git a/examples/console/pubspec.yaml b/examples/console/pubspec.yaml index e567d9d..154314f 100644 --- a/examples/console/pubspec.yaml +++ b/examples/console/pubspec.yaml @@ -1,4 +1,4 @@ -name: centrifuge_dart_example_console +name: spinify_example_console description: > Dart client to communicate with Centrifuge and Centrifugo from Flutter and VM @@ -10,9 +10,9 @@ publish_to: 'none' homepage: https://centrifugal.dev -repository: https://github.com/PlugFox/centrifuge-client +repository: https://github.com/PlugFox/spinify -issue_tracker: https://github.com/PlugFox/centrifuge-client/issues +issue_tracker: https://github.com/PlugFox/spinify/issues funding: - https://www.buymeacoffee.com/plugfox @@ -20,11 +20,11 @@ funding: - https://boosty.to/plugfox topics: + - spinify - centrifugo - centrifuge - websocket - cross-platform - - client platforms: android: @@ -42,7 +42,7 @@ environment: sdk: '>=3.0.0 <4.0.0' dependencies: - centrifuge_dart: + spinify: path: ../../ args: ^2.4.2 \ No newline at end of file diff --git a/lib/centrifuge.dart b/lib/centrifuge.dart deleted file mode 100644 index 757535c..0000000 --- a/lib/centrifuge.dart +++ /dev/null @@ -1,14 +0,0 @@ -library centrifuge; - -export 'package:centrifuge_dart/src/client/centrifuge.dart' show Centrifuge; -export 'package:centrifuge_dart/src/client/config.dart'; -export 'package:centrifuge_dart/src/client/state.dart'; -export 'package:centrifuge_dart/src/client/states_stream.dart'; -export 'package:centrifuge_dart/src/model/client_info.dart'; -export 'package:centrifuge_dart/src/model/exception.dart'; -export 'package:centrifuge_dart/src/model/jwt.dart'; -export 'package:centrifuge_dart/src/model/publication.dart'; -export 'package:centrifuge_dart/src/subscription/subscription.dart' - show CentrifugeClientSubscription, CentrifugeServerSubscription; -export 'package:centrifuge_dart/src/subscription/subscription_config.dart'; -export 'package:centrifuge_dart/src/subscription/subscription_state.dart'; diff --git a/lib/interface.dart b/lib/interface.dart index a78f8d7..90ccdbf 100644 --- a/lib/interface.dart +++ b/lib/interface.dart @@ -1,17 +1,17 @@ library interface; -export 'package:centrifuge_dart/src/client/centrifuge_interface.dart'; -export 'package:centrifuge_dart/src/client/config.dart'; -export 'package:centrifuge_dart/src/client/state.dart'; -export 'package:centrifuge_dart/src/client/states_stream.dart'; -export 'package:centrifuge_dart/src/model/client_info.dart'; -export 'package:centrifuge_dart/src/model/exception.dart'; -export 'package:centrifuge_dart/src/model/jwt.dart'; -export 'package:centrifuge_dart/src/model/publication.dart'; -export 'package:centrifuge_dart/src/subscription/subscription.dart' +export 'package:spinify/src/client/centrifuge_interface.dart'; +export 'package:spinify/src/client/config.dart'; +export 'package:spinify/src/client/state.dart'; +export 'package:spinify/src/client/states_stream.dart'; +export 'package:spinify/src/model/client_info.dart'; +export 'package:spinify/src/model/exception.dart'; +export 'package:spinify/src/model/jwt.dart'; +export 'package:spinify/src/model/publication.dart'; +export 'package:spinify/src/subscription/subscription.dart' show - ICentrifugeSubscription, + ISpinifySubscription, CentrifugeClientSubscription, CentrifugeServerSubscription; -export 'package:centrifuge_dart/src/subscription/subscription_config.dart'; -export 'package:centrifuge_dart/src/subscription/subscription_state.dart'; +export 'package:spinify/src/subscription/subscription_config.dart'; +export 'package:spinify/src/subscription/subscription_state.dart'; diff --git a/lib/spinify.dart b/lib/spinify.dart new file mode 100644 index 0000000..138566a --- /dev/null +++ b/lib/spinify.dart @@ -0,0 +1,14 @@ +library spinify; + +export 'package:spinify/src/client/centrifuge.dart' show Spinify; +export 'package:spinify/src/client/config.dart'; +export 'package:spinify/src/client/state.dart'; +export 'package:spinify/src/client/states_stream.dart'; +export 'package:spinify/src/model/client_info.dart'; +export 'package:spinify/src/model/exception.dart'; +export 'package:spinify/src/model/jwt.dart'; +export 'package:spinify/src/model/publication.dart'; +export 'package:spinify/src/subscription/subscription.dart' + show CentrifugeClientSubscription, CentrifugeServerSubscription; +export 'package:spinify/src/subscription/subscription_config.dart'; +export 'package:spinify/src/subscription/subscription_state.dart'; diff --git a/lib/src/client/centrifuge.dart b/lib/src/client/centrifuge.dart index e54d42e..f5c1b8a 100644 --- a/lib/src/client/centrifuge.dart +++ b/lib/src/client/centrifuge.dart @@ -1,90 +1,89 @@ import 'dart:async'; -import 'package:centrifuge_dart/src/client/centrifuge_interface.dart'; -import 'package:centrifuge_dart/src/client/config.dart'; -import 'package:centrifuge_dart/src/client/disconnect_code.dart'; -import 'package:centrifuge_dart/src/client/observer.dart'; -import 'package:centrifuge_dart/src/client/state.dart'; -import 'package:centrifuge_dart/src/client/states_stream.dart'; -import 'package:centrifuge_dart/src/model/channel_presence.dart'; -import 'package:centrifuge_dart/src/model/channel_push.dart'; -import 'package:centrifuge_dart/src/model/connect.dart'; -import 'package:centrifuge_dart/src/model/disconnect.dart'; -import 'package:centrifuge_dart/src/model/event.dart'; -import 'package:centrifuge_dart/src/model/exception.dart'; -import 'package:centrifuge_dart/src/model/history.dart'; -import 'package:centrifuge_dart/src/model/message.dart'; -import 'package:centrifuge_dart/src/model/presence.dart'; -import 'package:centrifuge_dart/src/model/presence_stats.dart'; -import 'package:centrifuge_dart/src/model/publication.dart'; -import 'package:centrifuge_dart/src/model/pushes_stream.dart'; -import 'package:centrifuge_dart/src/model/refresh.dart'; -import 'package:centrifuge_dart/src/model/stream_position.dart'; -import 'package:centrifuge_dart/src/model/subscribe.dart'; -import 'package:centrifuge_dart/src/model/unsubscribe.dart'; -import 'package:centrifuge_dart/src/subscription/client_subscription_manager.dart'; -import 'package:centrifuge_dart/src/subscription/server_subscription_manager.dart'; -import 'package:centrifuge_dart/src/subscription/subscription.dart'; -import 'package:centrifuge_dart/src/subscription/subscription_config.dart'; -import 'package:centrifuge_dart/src/transport/transport_interface.dart'; -import 'package:centrifuge_dart/src/transport/ws_protobuf_transport.dart'; -import 'package:centrifuge_dart/src/util/event_queue.dart'; -import 'package:centrifuge_dart/src/util/logger.dart' as logger; import 'package:meta/meta.dart'; - -/// {@template centrifuge} -/// Centrifuge client. +import 'package:spinify/src/client/centrifuge_interface.dart'; +import 'package:spinify/src/client/config.dart'; +import 'package:spinify/src/client/disconnect_code.dart'; +import 'package:spinify/src/client/observer.dart'; +import 'package:spinify/src/client/state.dart'; +import 'package:spinify/src/client/states_stream.dart'; +import 'package:spinify/src/model/channel_presence.dart'; +import 'package:spinify/src/model/channel_push.dart'; +import 'package:spinify/src/model/connect.dart'; +import 'package:spinify/src/model/disconnect.dart'; +import 'package:spinify/src/model/event.dart'; +import 'package:spinify/src/model/exception.dart'; +import 'package:spinify/src/model/history.dart'; +import 'package:spinify/src/model/message.dart'; +import 'package:spinify/src/model/presence.dart'; +import 'package:spinify/src/model/presence_stats.dart'; +import 'package:spinify/src/model/publication.dart'; +import 'package:spinify/src/model/pushes_stream.dart'; +import 'package:spinify/src/model/refresh.dart'; +import 'package:spinify/src/model/stream_position.dart'; +import 'package:spinify/src/model/subscribe.dart'; +import 'package:spinify/src/model/unsubscribe.dart'; +import 'package:spinify/src/subscription/client_subscription_manager.dart'; +import 'package:spinify/src/subscription/server_subscription_manager.dart'; +import 'package:spinify/src/subscription/subscription.dart'; +import 'package:spinify/src/subscription/subscription_config.dart'; +import 'package:spinify/src/transport/transport_interface.dart'; +import 'package:spinify/src/transport/ws_protobuf_transport.dart'; +import 'package:spinify/src/util/event_queue.dart'; +import 'package:spinify/src/util/logger.dart' as logger; + +/// {@template spinify} +/// Spinify client. /// {@endtemplate} /// {@category Client} -final class Centrifuge extends CentrifugeBase +final class Spinify extends SpinifyBase with - CentrifugeErrorsMixin, - CentrifugeStateMixin, - CentrifugeEventReceiverMixin, - CentrifugeConnectionMixin, - CentrifugeSendMixin, - CentrifugeClientSubscriptionMixin, - CentrifugeServerSubscriptionMixin, - CentrifugePublicationsMixin, - CentrifugePresenceMixin, - CentrifugeHistoryMixin, - CentrifugeRPCMixin, - CentrifugeQueueMixin { - /// {@macro centrifuge} - Centrifuge([CentrifugeConfig? config]) - : super(config ?? CentrifugeConfig.byDefault()); + SpinifyErrorsMixin, + SpinifyStateMixin, + SpinifyEventReceiverMixin, + SpinifyConnectionMixin, + SpinifySendMixin, + SpinifyClientSubscriptionMixin, + SpinifyServerSubscriptionMixin, + SpinifyPublicationsMixin, + SpinifyPresenceMixin, + SpinifyHistoryMixin, + SpinifyRPCMixin, + SpinifyQueueMixin { + /// {@macro spinify} + Spinify([SpinifyConfig? config]) : super(config ?? SpinifyConfig.byDefault()); /// Create client and connect. /// - /// {@macro centrifuge} - factory Centrifuge.connect(String url, [CentrifugeConfig? config]) => - Centrifuge(config)..connect(url); + /// {@macro spinify} + factory Spinify.connect(String url, [SpinifyConfig? config]) => + Spinify(config)..connect(url); - /// The current [CentrifugeObserver] instance. - static CentrifugeObserver? observer; + /// The current [SpinifyObserver] instance. + static SpinifyObserver? observer; } /// {@nodoc} @internal -abstract base class CentrifugeBase implements ICentrifuge { +abstract base class SpinifyBase implements ISpinify { /// {@nodoc} - CentrifugeBase(CentrifugeConfig config) : _config = config { - _transport = CentrifugeWSPBTransport( + SpinifyBase(SpinifyConfig config) : _config = config { + _transport = SpinifyWSPBTransport( config: config, ); - _initCentrifuge(); + _initSpinify(); } /// Internal transport responsible /// for sending, receiving, encoding and decoding data from the server. /// {@nodoc} @nonVirtual - late final ICentrifugeTransport _transport; + late final ISpinifyTransport _transport; /// Centrifuge config. /// {@nodoc} @nonVirtual - final CentrifugeConfig _config; + final SpinifyConfig _config; /// Manager responsible for client-side subscriptions. /// {@nodoc} @@ -101,9 +100,9 @@ abstract base class CentrifugeBase implements ICentrifuge { /// {@nodoc} @protected @mustCallSuper - void _initCentrifuge() { - logger.fine('Centrifuge client initialized'); - Centrifuge.observer?.onCreate(this); + void _initSpinify() { + logger.fine('Spinify client initialized'); + Spinify.observer?.onCreate(this); } /// Called when connection established. @@ -113,7 +112,7 @@ abstract base class CentrifugeBase implements ICentrifuge { @mustCallSuper void _onConnected(CentrifugeState$Connected state) { logger.fine('Connection established'); - Centrifuge.observer?.onConnected(this, state); + Spinify.observer?.onConnected(this, state); } /// Called when connection lost. @@ -123,7 +122,7 @@ abstract base class CentrifugeBase implements ICentrifuge { @mustCallSuper void _onDisconnected(CentrifugeState$Disconnected state) { logger.fine('Connection lost'); - Centrifuge.observer?.onDisconnected(this, state); + Spinify.observer?.onDisconnected(this, state); } @override @@ -131,15 +130,14 @@ abstract base class CentrifugeBase implements ICentrifuge { Future close() async { await _transport.close(); logger.fine('Centrifuge client closed'); - Centrifuge.observer?.onClose(this); + Spinify.observer?.onClose(this); } } /// Mixin responsible for event receiving and distribution by controllers /// and streams to subscribers. /// {@nodoc} -base mixin CentrifugeEventReceiverMixin - on CentrifugeBase, CentrifugeStateMixin { +base mixin SpinifyEventReceiverMixin on SpinifyBase, SpinifyStateMixin { @protected @nonVirtual final StreamController _pushController = @@ -182,9 +180,9 @@ base mixin CentrifugeEventReceiverMixin ); @override - void _initCentrifuge() { + void _initSpinify() { _transport.events.addListener(_onEvent); - super._initCentrifuge(); + super._initSpinify(); } /// Router for all events. @@ -194,7 +192,7 @@ base mixin CentrifugeEventReceiverMixin @pragma('vm:prefer-inline') @pragma('dart2js:tryInline') void _onEvent(CentrifugeEvent event) { - Centrifuge.observer?.onEvent(this, event); + Spinify.observer?.onEvent(this, event); if (event is! CentrifugeChannelPush) return; // This is a push to a channel. _clientSubscriptionManager.onPush(event); @@ -264,7 +262,7 @@ base mixin CentrifugeEventReceiverMixin /// Mixin responsible for centrifuge states /// {@nodoc} @internal -base mixin CentrifugeStateMixin on CentrifugeBase, CentrifugeErrorsMixin { +base mixin SpinifyStateMixin on SpinifyBase, SpinifyErrorsMixin { /// Refresh timer. /// {@nodoc} Timer? _refreshTimer; @@ -283,10 +281,10 @@ base mixin CentrifugeStateMixin on CentrifugeBase, CentrifugeErrorsMixin { CentrifugeStatesStream(_statesController.stream); @override - void _initCentrifuge() { + void _initSpinify() { _state = _transport.state; _transport.states.addListener(_onStateChange); - super._initCentrifuge(); + super._initSpinify(); } @protected @@ -310,7 +308,7 @@ base mixin CentrifugeStateMixin on CentrifugeBase, CentrifugeErrorsMixin { break; } _statesController.add(_state = newState); - Centrifuge.observer?.onStateChanged(this, oldState, newState); + Spinify.observer?.onStateChanged(this, oldState, newState); } @protected @@ -365,18 +363,18 @@ base mixin CentrifugeStateMixin on CentrifugeBase, CentrifugeErrorsMixin { /// Mixin responsible for errors stream. /// {@nodoc} @internal -base mixin CentrifugeErrorsMixin on CentrifugeBase { +base mixin SpinifyErrorsMixin on SpinifyBase { @protected @nonVirtual void _emitError(CentrifugeException exception, StackTrace stackTrace) => - Centrifuge.observer?.onError(exception, stackTrace); + Spinify.observer?.onError(exception, stackTrace); } /// Mixin responsible for connection. /// {@nodoc} @internal -base mixin CentrifugeConnectionMixin - on CentrifugeBase, CentrifugeErrorsMixin, CentrifugeStateMixin { +base mixin SpinifyConnectionMixin + on SpinifyBase, SpinifyErrorsMixin, SpinifyStateMixin { @override Future connect(String url) async { logger.fine('Interactively connecting to $url'); @@ -471,7 +469,7 @@ base mixin CentrifugeConnectionMixin /// Mixin responsible for sending asynchronous messages. /// {@nodoc} @internal -base mixin CentrifugeSendMixin on CentrifugeBase, CentrifugeErrorsMixin { +base mixin SpinifySendMixin on SpinifyBase, SpinifyErrorsMixin { @override Future send(List data) async { try { @@ -491,8 +489,7 @@ base mixin CentrifugeSendMixin on CentrifugeBase, CentrifugeErrorsMixin { /// Mixin responsible for client-side subscriptions. /// {@nodoc} @internal -base mixin CentrifugeClientSubscriptionMixin - on CentrifugeBase, CentrifugeErrorsMixin { +base mixin SpinifyClientSubscriptionMixin on SpinifyBase, SpinifyErrorsMixin { @override CentrifugeClientSubscription newSubscription( String channel, [ @@ -559,7 +556,7 @@ base mixin CentrifugeClientSubscriptionMixin /// Mixin responsible for server-side subscriptions. /// {@nodoc} @internal -base mixin CentrifugeServerSubscriptionMixin on CentrifugeBase { +base mixin SpinifyServerSubscriptionMixin on SpinifyBase { @override void _onConnected(CentrifugeState$Connected state) { super._onConnected(state); @@ -582,11 +579,8 @@ base mixin CentrifugeServerSubscriptionMixin on CentrifugeBase { /// Mixin responsible for publications. /// {@nodoc} @internal -base mixin CentrifugePublicationsMixin - on - CentrifugeBase, - CentrifugeErrorsMixin, - CentrifugeClientSubscriptionMixin { +base mixin SpinifyPublicationsMixin + on SpinifyBase, SpinifyErrorsMixin, SpinifyClientSubscriptionMixin { @override Future publish(String channel, List data) async { try { @@ -608,7 +602,7 @@ base mixin CentrifugePublicationsMixin /// Mixin responsible for presence. /// {@nodoc} -base mixin CentrifugePresenceMixin on CentrifugeBase, CentrifugeErrorsMixin { +base mixin SpinifyPresenceMixin on SpinifyBase, SpinifyErrorsMixin { @override Future presence(String channel) async { try { @@ -648,7 +642,7 @@ base mixin CentrifugePresenceMixin on CentrifugeBase, CentrifugeErrorsMixin { /// Mixin responsible for history. /// {@nodoc} -base mixin CentrifugeHistoryMixin on CentrifugeBase, CentrifugeErrorsMixin { +base mixin SpinifyHistoryMixin on SpinifyBase, SpinifyErrorsMixin { @override Future history( String channel, { @@ -680,7 +674,7 @@ base mixin CentrifugeHistoryMixin on CentrifugeBase, CentrifugeErrorsMixin { /// Mixin responsible for history. /// {@nodoc} -base mixin CentrifugeRPCMixin on CentrifugeBase, CentrifugeErrorsMixin { +base mixin SpinifyRPCMixin on SpinifyBase, SpinifyErrorsMixin { @override Future> rpc(String method, List data) async { try { @@ -704,7 +698,7 @@ base mixin CentrifugeRPCMixin on CentrifugeBase, CentrifugeErrorsMixin { /// SHOULD BE LAST MIXIN. /// {@nodoc} @internal -base mixin CentrifugeQueueMixin on CentrifugeBase { +base mixin SpinifyQueueMixin on SpinifyBase { /// {@nodoc} final CentrifugeEventQueue _eventQueue = CentrifugeEventQueue(); diff --git a/lib/src/client/centrifuge_interface.dart b/lib/src/client/centrifuge_interface.dart index 6e8f8e6..9451fa0 100644 --- a/lib/src/client/centrifuge_interface.dart +++ b/lib/src/client/centrifuge_interface.dart @@ -2,24 +2,27 @@ import 'dart:async'; -import 'package:centrifuge_dart/centrifuge.dart'; -import 'package:centrifuge_dart/src/model/history.dart'; -import 'package:centrifuge_dart/src/model/presence.dart'; -import 'package:centrifuge_dart/src/model/presence_stats.dart'; -import 'package:centrifuge_dart/src/model/pushes_stream.dart'; -import 'package:centrifuge_dart/src/model/stream_position.dart'; +import 'package:spinify/src/client/state.dart'; +import 'package:spinify/src/client/states_stream.dart'; +import 'package:spinify/src/model/history.dart'; +import 'package:spinify/src/model/presence.dart'; +import 'package:spinify/src/model/presence_stats.dart'; +import 'package:spinify/src/model/pushes_stream.dart'; +import 'package:spinify/src/model/stream_position.dart'; +import 'package:spinify/src/subscription/subscription.dart'; +import 'package:spinify/src/subscription/subscription_config.dart'; /// Centrifuge client interface. -abstract interface class ICentrifuge +abstract interface class ISpinify implements - ICentrifugeStateOwner, - ICentrifugeAsyncMessageSender, - ICentrifugePublicationSender, - ICentrifugeEventReceiver, - ICentrifugeClientSubscriptionsManager, - ICentrifugePresenceOwner, - ICentrifugeHistoryOwner, - ICentrifugeRemoteProcedureCall { + ISpinifyStateOwner, + ISpinifyAsyncMessageSender, + ISpinifyPublicationSender, + ISpinifyEventReceiver, + ISpinifyClientSubscriptionsManager, + ISpinifyPresenceOwner, + ISpinifyHistoryOwner, + ISpinifyRemoteProcedureCall { /// Connect to the server. /// [url] is a URL of endpoint. Future connect(String url); @@ -41,7 +44,7 @@ abstract interface class ICentrifuge } /// Centrifuge client state owner interface. -abstract interface class ICentrifugeStateOwner { +abstract interface class ISpinifyStateOwner { /// State of client. CentrifugeState get state; @@ -50,13 +53,13 @@ abstract interface class ICentrifugeStateOwner { } /// Centrifuge send publication interface. -abstract interface class ICentrifugePublicationSender { +abstract interface class ISpinifyPublicationSender { /// Publish data to specific subscription channel Future publish(String channel, List data); } /// Centrifuge send asynchronous message interface. -abstract interface class ICentrifugeAsyncMessageSender { +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 Centrifuge /// asynchronous message handler does not exist. @@ -64,13 +67,13 @@ abstract interface class ICentrifugeAsyncMessageSender { } /// Centrifuge event receiver interface. -abstract interface class ICentrifugeEventReceiver { +abstract interface class ISpinifyEventReceiver { /// Stream of received pushes from Centrifugo server for a channel. abstract final CentrifugePushesStream stream; } /// Centrifuge client subscriptions manager interface. -abstract interface class ICentrifugeClientSubscriptionsManager { +abstract interface class ISpinifyClientSubscriptionsManager { /// Create new client-side subscription. /// `newSubscription(channel, config)` allocates a new Subscription /// in the registry or throws an exception if the Subscription @@ -100,7 +103,7 @@ abstract interface class ICentrifugeClientSubscriptionsManager { } /// Centrifuge presence owner interface. -abstract interface class ICentrifugePresenceOwner { +abstract interface class ISpinifyPresenceOwner { /// Fetch presence information inside a channel. Future presence(String channel); @@ -109,7 +112,7 @@ abstract interface class ICentrifugePresenceOwner { } /// Centrifuge history owner interface. -abstract interface class ICentrifugeHistoryOwner { +abstract interface class ISpinifyHistoryOwner { /// Fetch publication history inside a channel. /// Only for channels where history is enabled. Future history( @@ -121,7 +124,7 @@ abstract interface class ICentrifugeHistoryOwner { } /// Centrifuge remote procedure call interface. -abstract interface class ICentrifugeRemoteProcedureCall { +abstract interface class ISpinifyRemoteProcedureCall { /// Send arbitrary RPC and wait for response. Future> rpc(String method, List data); } diff --git a/lib/src/client/config.dart b/lib/src/client/config.dart index 8d15e7c..43f987b 100644 --- a/lib/src/client/config.dart +++ b/lib/src/client/config.dart @@ -1,7 +1,7 @@ import 'dart:async'; -import 'package:centrifuge_dart/src/model/pubspec.yaml.g.dart'; import 'package:meta/meta.dart'; +import 'package:spinify/src/model/pubspec.yaml.g.dart'; /// Token used for authentication typedef CentrifugeToken = String; @@ -31,9 +31,9 @@ typedef CentrifugeConnectionPayloadCallback = FutureOr?> Function(); /// {@category Client} /// {@category Entity} @immutable -final class CentrifugeConfig { +final class SpinifyConfig { /// {@macro centrifuge_config} - CentrifugeConfig({ + SpinifyConfig({ this.getToken, this.getPayload, this.connectionRetryInterval = ( @@ -53,7 +53,7 @@ final class CentrifugeConfig { /// Create a default config /// /// {@macro centrifuge_config} - factory CentrifugeConfig.byDefault() = CentrifugeConfig; + factory SpinifyConfig.byDefault() = SpinifyConfig; /// Callback to get/refresh tokens /// This callback is used for initial connection diff --git a/lib/src/client/observer.dart b/lib/src/client/observer.dart index 1a35c2b..ab67201 100644 --- a/lib/src/client/observer.dart +++ b/lib/src/client/observer.dart @@ -1,40 +1,42 @@ -import 'package:centrifuge_dart/centrifuge.dart'; -import 'package:centrifuge_dart/src/client/centrifuge_interface.dart'; -import 'package:centrifuge_dart/src/model/event.dart'; -import 'package:centrifuge_dart/src/subscription/subscription.dart'; +import 'package:spinify/src/client/centrifuge_interface.dart'; +import 'package:spinify/src/client/state.dart'; +import 'package:spinify/src/model/event.dart'; +import 'package:spinify/src/model/exception.dart'; +import 'package:spinify/src/subscription/subscription.dart'; +import 'package:spinify/src/subscription/subscription_state.dart'; /// An interface for observing the behavior of Centrifuge instances. /// {@category Client} /// {@subCategory Observer} -abstract class CentrifugeObserver { - /// Called whenever a [ICentrifuge] is instantiated. - void onCreate(ICentrifuge client) {} +abstract class SpinifyObserver { + /// Called whenever a [ISpinify] is instantiated. + void onCreate(ISpinify client) {} - /// Called whenever a [ICentrifuge] client changes its state + /// Called whenever a [ISpinify] client changes its state /// to [CentrifugeState$Connecting]. - void onConnected(ICentrifuge client, CentrifugeState$Connected state) {} + void onConnected(ISpinify client, CentrifugeState$Connected state) {} - /// Called whenever a [ICentrifuge] client receives a [CentrifugeEvent]. - void onEvent(ICentrifuge client, CentrifugeEvent event) {} + /// Called whenever a [ISpinify] client receives a [CentrifugeEvent]. + void onEvent(ISpinify client, CentrifugeEvent event) {} - /// Called whenever a [ICentrifuge] client changes its state + /// Called whenever a [ISpinify] client changes its state /// from [prev] to [next]. void onStateChanged( - ICentrifuge client, CentrifugeState prev, CentrifugeState next) {} + ISpinify client, CentrifugeState prev, CentrifugeState next) {} - /// Called whenever a [ICentrifugeSubscription] changes its state + /// Called whenever a [ISpinifySubscription] changes its state /// from [prev] to [next]. /// Works both for client-side and server-side subscriptions. - void onSubscriptionChanged(ICentrifugeSubscription subscription, + void onSubscriptionChanged(ISpinifySubscription subscription, CentrifugeSubscriptionState prev, CentrifugeSubscriptionState next) {} - /// Called whenever a [ICentrifuge] client changes its state + /// Called whenever a [ISpinify] client changes its state /// to [CentrifugeState$Disconnected]. - void onDisconnected(ICentrifuge client, CentrifugeState$Disconnected state) {} + void onDisconnected(ISpinify client, CentrifugeState$Disconnected state) {} /// Called whenever an error is thrown in any Centrifuge client. void onError(CentrifugeException error, StackTrace stackTrace) {} - /// Called whenever a [ICentrifuge] is closed. - void onClose(ICentrifuge client) {} + /// Called whenever a [ISpinify] is closed. + void onClose(ISpinify client) {} } diff --git a/lib/src/client/states_stream.dart b/lib/src/client/states_stream.dart index 60c22bd..c918449 100644 --- a/lib/src/client/states_stream.dart +++ b/lib/src/client/states_stream.dart @@ -1,6 +1,6 @@ import 'dart:async'; -import 'package:centrifuge_dart/src/client/state.dart'; +import 'package:spinify/src/client/state.dart'; /// Stream of Centrifuge's [CentrifugeState] changes. /// {@category Client} diff --git a/lib/src/model/channel_presence.dart b/lib/src/model/channel_presence.dart index cdbf6ff..88e91c5 100644 --- a/lib/src/model/channel_presence.dart +++ b/lib/src/model/channel_presence.dart @@ -1,6 +1,6 @@ -import 'package:centrifuge_dart/src/model/channel_push.dart'; -import 'package:centrifuge_dart/src/model/client_info.dart'; import 'package:meta/meta.dart'; +import 'package:spinify/src/model/channel_push.dart'; +import 'package:spinify/src/model/client_info.dart'; /// {@template channel_presence} /// Channel presence. diff --git a/lib/src/model/channel_push.dart b/lib/src/model/channel_push.dart index d47803d..8292edf 100644 --- a/lib/src/model/channel_push.dart +++ b/lib/src/model/channel_push.dart @@ -1,5 +1,5 @@ -import 'package:centrifuge_dart/src/model/event.dart'; import 'package:meta/meta.dart'; +import 'package:spinify/src/model/event.dart'; /// {@template centrifuge_channel_push} /// Base class for all channel push events. diff --git a/lib/src/model/connect.dart b/lib/src/model/connect.dart index 1fd4318..a0fe970 100644 --- a/lib/src/model/connect.dart +++ b/lib/src/model/connect.dart @@ -1,4 +1,4 @@ -import 'package:centrifuge_dart/src/model/channel_push.dart'; +import 'package:spinify/src/model/channel_push.dart'; /// {@template connect} /// Connect push from Centrifugo server. diff --git a/lib/src/model/disconnect.dart b/lib/src/model/disconnect.dart index f26f18d..50cb490 100644 --- a/lib/src/model/disconnect.dart +++ b/lib/src/model/disconnect.dart @@ -1,4 +1,4 @@ -import 'package:centrifuge_dart/src/model/channel_push.dart'; +import 'package:spinify/src/model/channel_push.dart'; /// {@template disconnect} /// Disconnect push from Centrifugo server. diff --git a/lib/src/model/history.dart b/lib/src/model/history.dart index 4ef266b..cfe508e 100644 --- a/lib/src/model/history.dart +++ b/lib/src/model/history.dart @@ -1,6 +1,6 @@ -import 'package:centrifuge_dart/src/model/publication.dart'; -import 'package:centrifuge_dart/src/model/stream_position.dart'; import 'package:meta/meta.dart'; +import 'package:spinify/src/model/publication.dart'; +import 'package:spinify/src/model/stream_position.dart'; /// {@template history} /// History diff --git a/lib/src/model/message.dart b/lib/src/model/message.dart index a02cb25..82e181a 100644 --- a/lib/src/model/message.dart +++ b/lib/src/model/message.dart @@ -1,4 +1,4 @@ -import 'package:centrifuge_dart/src/model/channel_push.dart'; +import 'package:spinify/src/model/channel_push.dart'; /// {@template message} /// Message push from Centrifugo server. diff --git a/lib/src/model/presence.dart b/lib/src/model/presence.dart index e942764..e505d46 100644 --- a/lib/src/model/presence.dart +++ b/lib/src/model/presence.dart @@ -1,5 +1,5 @@ -import 'package:centrifuge_dart/src/model/client_info.dart'; import 'package:meta/meta.dart'; +import 'package:spinify/src/model/client_info.dart'; /// {@template presence} /// Presence diff --git a/lib/src/model/publication.dart b/lib/src/model/publication.dart index 93192d1..778e9b2 100644 --- a/lib/src/model/publication.dart +++ b/lib/src/model/publication.dart @@ -1,7 +1,7 @@ -import 'package:centrifuge_dart/src/model/channel_push.dart'; -import 'package:centrifuge_dart/src/model/client_info.dart'; import 'package:fixnum/fixnum.dart' as fixnum; import 'package:meta/meta.dart'; +import 'package:spinify/src/model/channel_push.dart'; +import 'package:spinify/src/model/client_info.dart'; /// {@template publication} /// Publication context diff --git a/lib/src/model/pushes_stream.dart b/lib/src/model/pushes_stream.dart index 1560202..a2cf479 100644 --- a/lib/src/model/pushes_stream.dart +++ b/lib/src/model/pushes_stream.dart @@ -1,10 +1,10 @@ import 'dart:async'; -import 'package:centrifuge_dart/src/model/channel_presence.dart'; -import 'package:centrifuge_dart/src/model/channel_push.dart'; -import 'package:centrifuge_dart/src/model/event.dart'; -import 'package:centrifuge_dart/src/model/message.dart'; -import 'package:centrifuge_dart/src/model/publication.dart'; +import 'package:spinify/src/model/channel_presence.dart'; +import 'package:spinify/src/model/channel_push.dart'; +import 'package:spinify/src/model/event.dart'; +import 'package:spinify/src/model/message.dart'; +import 'package:spinify/src/model/publication.dart'; /// Stream of received pushes from Centrifugo server for a channel. /// {@category Entity} diff --git a/lib/src/model/refresh.dart b/lib/src/model/refresh.dart index 8b42b54..117be07 100644 --- a/lib/src/model/refresh.dart +++ b/lib/src/model/refresh.dart @@ -1,5 +1,5 @@ -import 'package:centrifuge_dart/src/model/channel_push.dart'; import 'package:meta/meta.dart'; +import 'package:spinify/src/model/channel_push.dart'; /// {@template refresh} /// Refresh push from Centrifugo server. diff --git a/lib/src/model/subscribe.dart b/lib/src/model/subscribe.dart index c36d19e..437e913 100644 --- a/lib/src/model/subscribe.dart +++ b/lib/src/model/subscribe.dart @@ -1,5 +1,5 @@ -import 'package:centrifuge_dart/src/model/channel_push.dart'; -import 'package:centrifuge_dart/src/model/stream_position.dart'; +import 'package:spinify/src/model/channel_push.dart'; +import 'package:spinify/src/model/stream_position.dart'; /// {@template subscribe} /// Subscribe push from Centrifugo server. diff --git a/lib/src/model/unsubscribe.dart b/lib/src/model/unsubscribe.dart index d1bfe4b..1db54e8 100644 --- a/lib/src/model/unsubscribe.dart +++ b/lib/src/model/unsubscribe.dart @@ -1,4 +1,4 @@ -import 'package:centrifuge_dart/src/model/channel_push.dart'; +import 'package:spinify/src/model/channel_push.dart'; /// {@template unsubscribe} /// Unsubscribe push from Centrifugo server. diff --git a/lib/src/subscription/client_subscription_impl.dart b/lib/src/subscription/client_subscription_impl.dart index 35a0a75..fa528eb 100644 --- a/lib/src/subscription/client_subscription_impl.dart +++ b/lib/src/subscription/client_subscription_impl.dart @@ -1,27 +1,32 @@ import 'dart:async'; -import 'package:centrifuge_dart/centrifuge.dart'; -import 'package:centrifuge_dart/src/client/disconnect_code.dart'; -import 'package:centrifuge_dart/src/model/channel_presence.dart'; -import 'package:centrifuge_dart/src/model/channel_push.dart'; -import 'package:centrifuge_dart/src/model/connect.dart'; -import 'package:centrifuge_dart/src/model/disconnect.dart'; -import 'package:centrifuge_dart/src/model/event.dart'; -import 'package:centrifuge_dart/src/model/history.dart'; -import 'package:centrifuge_dart/src/model/message.dart'; -import 'package:centrifuge_dart/src/model/presence.dart'; -import 'package:centrifuge_dart/src/model/presence_stats.dart'; -import 'package:centrifuge_dart/src/model/pushes_stream.dart'; -import 'package:centrifuge_dart/src/model/refresh.dart'; -import 'package:centrifuge_dart/src/model/stream_position.dart'; -import 'package:centrifuge_dart/src/model/subscribe.dart'; -import 'package:centrifuge_dart/src/model/unsubscribe.dart'; -import 'package:centrifuge_dart/src/subscription/subscription_states_stream.dart'; -import 'package:centrifuge_dart/src/transport/transport_interface.dart'; -import 'package:centrifuge_dart/src/util/event_queue.dart'; -import 'package:centrifuge_dart/src/util/logger.dart' as logger; import 'package:fixnum/fixnum.dart' as fixnum; import 'package:meta/meta.dart'; +import 'package:spinify/src/client/centrifuge.dart'; +import 'package:spinify/src/client/disconnect_code.dart'; +import 'package:spinify/src/model/channel_presence.dart'; +import 'package:spinify/src/model/channel_push.dart'; +import 'package:spinify/src/model/connect.dart'; +import 'package:spinify/src/model/disconnect.dart'; +import 'package:spinify/src/model/event.dart'; +import 'package:spinify/src/model/exception.dart'; +import 'package:spinify/src/model/history.dart'; +import 'package:spinify/src/model/message.dart'; +import 'package:spinify/src/model/presence.dart'; +import 'package:spinify/src/model/presence_stats.dart'; +import 'package:spinify/src/model/publication.dart'; +import 'package:spinify/src/model/pushes_stream.dart'; +import 'package:spinify/src/model/refresh.dart'; +import 'package:spinify/src/model/stream_position.dart'; +import 'package:spinify/src/model/subscribe.dart'; +import 'package:spinify/src/model/unsubscribe.dart'; +import 'package:spinify/src/subscription/subscription.dart'; +import 'package:spinify/src/subscription/subscription_config.dart'; +import 'package:spinify/src/subscription/subscription_state.dart'; +import 'package:spinify/src/subscription/subscription_states_stream.dart'; +import 'package:spinify/src/transport/transport_interface.dart'; +import 'package:spinify/src/util/event_queue.dart'; +import 'package:spinify/src/util/logger.dart' as logger; /// Client-side subscription implementation. /// {@nodoc} @@ -51,7 +56,7 @@ abstract base class CentrifugeClientSubscriptionBase /// {@nodoc} CentrifugeClientSubscriptionBase({ required this.channel, - required WeakReference transportWeakRef, + required WeakReference transportWeakRef, required CentrifugeSubscriptionConfig config, }) : _config = config { _transportWeakRef = transportWeakRef; @@ -73,12 +78,12 @@ abstract base class CentrifugeClientSubscriptionBase /// Weak reference to transport. /// {@nodoc} @nonVirtual - late final WeakReference _transportWeakRef; + late final WeakReference _transportWeakRef; /// Internal transport responsible /// for sending, receiving, encoding and decoding data from the server. /// {@nodoc} - ICentrifugeTransport get _transport => _transportWeakRef.target!; + ISpinifyTransport get _transport => _transportWeakRef.target!; /// Subscription config. /// {@nodoc} @@ -120,7 +125,7 @@ abstract base class CentrifugeClientSubscriptionBase if (_state == state) return; final previousState = _state; _stateController.add(_state = state); - Centrifuge.observer?.onSubscriptionChanged(this, previousState, state); + Spinify.observer?.onSubscriptionChanged(this, previousState, state); } /// Notify about new publication. @@ -254,7 +259,7 @@ base mixin CentrifugeClientSubscriptionErrorsMixin @protected @nonVirtual void _emitError(CentrifugeException exception, StackTrace stackTrace) => - Centrifuge.observer?.onError(exception, stackTrace); + Spinify.observer?.onError(exception, stackTrace); } /// Mixin responsible for subscribing. diff --git a/lib/src/subscription/client_subscription_manager.dart b/lib/src/subscription/client_subscription_manager.dart index d8a8a84..9cb1d5b 100644 --- a/lib/src/subscription/client_subscription_manager.dart +++ b/lib/src/subscription/client_subscription_manager.dart @@ -1,24 +1,24 @@ import 'dart:collection'; -import 'package:centrifuge_dart/src/model/channel_push.dart'; -import 'package:centrifuge_dart/src/model/exception.dart'; -import 'package:centrifuge_dart/src/subscription/client_subscription_impl.dart'; -import 'package:centrifuge_dart/src/subscription/subscription.dart'; -import 'package:centrifuge_dart/src/subscription/subscription_config.dart'; -import 'package:centrifuge_dart/src/transport/transport_interface.dart'; import 'package:meta/meta.dart'; +import 'package:spinify/src/model/channel_push.dart'; +import 'package:spinify/src/model/exception.dart'; +import 'package:spinify/src/subscription/client_subscription_impl.dart'; +import 'package:spinify/src/subscription/subscription.dart'; +import 'package:spinify/src/subscription/subscription_config.dart'; +import 'package:spinify/src/transport/transport_interface.dart'; /// Responsible for managing client-side subscriptions. /// {@nodoc} @internal final class ClientSubscriptionManager { /// {@nodoc} - ClientSubscriptionManager(ICentrifugeTransport transport) - : _transportWeakRef = WeakReference(transport); + ClientSubscriptionManager(ISpinifyTransport transport) + : _transportWeakRef = WeakReference(transport); /// Centrifuge client weak reference. /// {@nodoc} - final WeakReference _transportWeakRef; + final WeakReference _transportWeakRef; /// Subscriptions registry (channel -> subscription). /// Channel : CentrifugeClientSubscription diff --git a/lib/src/subscription/server_subscription_impl.dart b/lib/src/subscription/server_subscription_impl.dart index d38bda9..a150ab8 100644 --- a/lib/src/subscription/server_subscription_impl.dart +++ b/lib/src/subscription/server_subscription_impl.dart @@ -1,30 +1,30 @@ import 'dart:async'; -import 'package:centrifuge_dart/src/client/centrifuge.dart'; -import 'package:centrifuge_dart/src/model/channel_presence.dart'; -import 'package:centrifuge_dart/src/model/channel_push.dart'; -import 'package:centrifuge_dart/src/model/connect.dart'; -import 'package:centrifuge_dart/src/model/disconnect.dart'; -import 'package:centrifuge_dart/src/model/event.dart'; -import 'package:centrifuge_dart/src/model/exception.dart'; -import 'package:centrifuge_dart/src/model/history.dart'; -import 'package:centrifuge_dart/src/model/message.dart'; -import 'package:centrifuge_dart/src/model/presence.dart'; -import 'package:centrifuge_dart/src/model/presence_stats.dart'; -import 'package:centrifuge_dart/src/model/publication.dart'; -import 'package:centrifuge_dart/src/model/pushes_stream.dart'; -import 'package:centrifuge_dart/src/model/refresh.dart'; -import 'package:centrifuge_dart/src/model/stream_position.dart'; -import 'package:centrifuge_dart/src/model/subscribe.dart'; -import 'package:centrifuge_dart/src/model/unsubscribe.dart'; -import 'package:centrifuge_dart/src/subscription/subscription.dart'; -import 'package:centrifuge_dart/src/subscription/subscription_state.dart'; -import 'package:centrifuge_dart/src/subscription/subscription_states_stream.dart'; -import 'package:centrifuge_dart/src/transport/transport_interface.dart'; -import 'package:centrifuge_dart/src/util/event_queue.dart'; -import 'package:centrifuge_dart/src/util/logger.dart' as logger; import 'package:fixnum/fixnum.dart' as fixnum; import 'package:meta/meta.dart'; +import 'package:spinify/src/client/centrifuge.dart'; +import 'package:spinify/src/model/channel_presence.dart'; +import 'package:spinify/src/model/channel_push.dart'; +import 'package:spinify/src/model/connect.dart'; +import 'package:spinify/src/model/disconnect.dart'; +import 'package:spinify/src/model/event.dart'; +import 'package:spinify/src/model/exception.dart'; +import 'package:spinify/src/model/history.dart'; +import 'package:spinify/src/model/message.dart'; +import 'package:spinify/src/model/presence.dart'; +import 'package:spinify/src/model/presence_stats.dart'; +import 'package:spinify/src/model/publication.dart'; +import 'package:spinify/src/model/pushes_stream.dart'; +import 'package:spinify/src/model/refresh.dart'; +import 'package:spinify/src/model/stream_position.dart'; +import 'package:spinify/src/model/subscribe.dart'; +import 'package:spinify/src/model/unsubscribe.dart'; +import 'package:spinify/src/subscription/subscription.dart'; +import 'package:spinify/src/subscription/subscription_state.dart'; +import 'package:spinify/src/subscription/subscription_states_stream.dart'; +import 'package:spinify/src/transport/transport_interface.dart'; +import 'package:spinify/src/util/event_queue.dart'; +import 'package:spinify/src/util/logger.dart' as logger; /// Server-side subscription implementation. /// {@nodoc} @@ -53,7 +53,7 @@ abstract base class CentrifugeServerSubscriptionBase /// {@nodoc} CentrifugeServerSubscriptionBase({ required this.channel, - required WeakReference transportWeakRef, + required WeakReference transportWeakRef, }) { _transportWeakRef = transportWeakRef; _initSubscription(); @@ -74,12 +74,12 @@ abstract base class CentrifugeServerSubscriptionBase /// Weak reference to transport. /// {@nodoc} @nonVirtual - late final WeakReference _transportWeakRef; + late final WeakReference _transportWeakRef; /// Internal transport responsible /// for sending, receiving, encoding and decoding data from the server. /// {@nodoc} - ICentrifugeTransport get _transport => _transportWeakRef.target!; + ISpinifyTransport get _transport => _transportWeakRef.target!; /// Init subscription. /// {@nodoc} @@ -116,7 +116,7 @@ abstract base class CentrifugeServerSubscriptionBase if (_state == state) return; final previousState = _state; _stateController.add(_state = state); - Centrifuge.observer?.onSubscriptionChanged(this, previousState, state); + Spinify.observer?.onSubscriptionChanged(this, previousState, state); } /// Notify about new publication. @@ -260,7 +260,7 @@ base mixin CentrifugeServerSubscriptionErrorsMixin @protected @nonVirtual void _emitError(CentrifugeException exception, StackTrace stackTrace) => - Centrifuge.observer?.onError(exception, stackTrace); + Spinify.observer?.onError(exception, stackTrace); } /// Mixin responsible for ready method. diff --git a/lib/src/subscription/server_subscription_manager.dart b/lib/src/subscription/server_subscription_manager.dart index e7ad9aa..94b69aa 100644 --- a/lib/src/subscription/server_subscription_manager.dart +++ b/lib/src/subscription/server_subscription_manager.dart @@ -1,24 +1,24 @@ import 'dart:collection'; -import 'package:centrifuge_dart/src/model/channel_push.dart'; -import 'package:centrifuge_dart/src/model/subscribe.dart'; -import 'package:centrifuge_dart/src/model/unsubscribe.dart'; -import 'package:centrifuge_dart/src/subscription/server_subscription_impl.dart'; -import 'package:centrifuge_dart/src/subscription/subscription.dart'; -import 'package:centrifuge_dart/src/transport/transport_interface.dart'; import 'package:meta/meta.dart'; +import 'package:spinify/src/model/channel_push.dart'; +import 'package:spinify/src/model/subscribe.dart'; +import 'package:spinify/src/model/unsubscribe.dart'; +import 'package:spinify/src/subscription/server_subscription_impl.dart'; +import 'package:spinify/src/subscription/subscription.dart'; +import 'package:spinify/src/transport/transport_interface.dart'; /// Responsible for managing client-side subscriptions. /// {@nodoc} @internal final class ServerSubscriptionManager { /// {@nodoc} - ServerSubscriptionManager(ICentrifugeTransport transport) - : _transportWeakRef = WeakReference(transport); + ServerSubscriptionManager(ISpinifyTransport transport) + : _transportWeakRef = WeakReference(transport); /// Centrifuge client weak reference. /// {@nodoc} - final WeakReference _transportWeakRef; + final WeakReference _transportWeakRef; /// Subscriptions registry (channel -> subscription). /// Channel : CentrifugeClientSubscription diff --git a/lib/src/subscription/subcibed_on_channel.dart b/lib/src/subscription/subcibed_on_channel.dart index afc0006..e2db5d9 100644 --- a/lib/src/subscription/subcibed_on_channel.dart +++ b/lib/src/subscription/subcibed_on_channel.dart @@ -1,6 +1,6 @@ -import 'package:centrifuge_dart/src/model/publication.dart'; -import 'package:centrifuge_dart/src/model/stream_position.dart'; import 'package:meta/meta.dart'; +import 'package:spinify/src/model/publication.dart'; +import 'package:spinify/src/model/stream_position.dart'; /// Subscribed on channel message. @immutable diff --git a/lib/src/subscription/subscription.dart b/lib/src/subscription/subscription.dart index dd751c8..29fee4c 100644 --- a/lib/src/subscription/subscription.dart +++ b/lib/src/subscription/subscription.dart @@ -1,19 +1,19 @@ import 'dart:async'; -import 'package:centrifuge_dart/src/model/history.dart'; -import 'package:centrifuge_dart/src/model/presence.dart'; -import 'package:centrifuge_dart/src/model/presence_stats.dart'; -import 'package:centrifuge_dart/src/model/pushes_stream.dart'; -import 'package:centrifuge_dart/src/model/stream_position.dart'; -import 'package:centrifuge_dart/src/subscription/subscription_state.dart'; -import 'package:centrifuge_dart/src/subscription/subscription_states_stream.dart'; +import 'package:spinify/src/model/history.dart'; +import 'package:spinify/src/model/presence.dart'; +import 'package:spinify/src/model/presence_stats.dart'; +import 'package:spinify/src/model/pushes_stream.dart'; +import 'package:spinify/src/model/stream_position.dart'; +import 'package:spinify/src/subscription/subscription_state.dart'; +import 'package:spinify/src/subscription/subscription_states_stream.dart'; /// {@template subscription} /// Centrifuge subscription interface. /// {@endtemplate} /// {@category Subscription} /// {@category Entity} -abstract interface class ICentrifugeSubscription { +abstract interface class ISpinifySubscription { /// Channel name. abstract final String channel; @@ -108,7 +108,7 @@ abstract interface class ICentrifugeSubscription { /// {@category Entity} /// {@subCategory Client-side} abstract interface class CentrifugeClientSubscription - implements ICentrifugeSubscription { + implements ISpinifySubscription { /// Start subscribing to a channel Future subscribe(); @@ -138,7 +138,7 @@ abstract interface class CentrifugeClientSubscription /// {@category Entity} /// {@subCategory Server-side} abstract interface class CentrifugeServerSubscription - implements ICentrifugeSubscription { + implements ISpinifySubscription { @override String toString() => 'CentrifugeServerSubscription{channel: $channel}'; } diff --git a/lib/src/subscription/subscription_states_stream.dart b/lib/src/subscription/subscription_states_stream.dart index 799a5fc..90a384d 100644 --- a/lib/src/subscription/subscription_states_stream.dart +++ b/lib/src/subscription/subscription_states_stream.dart @@ -1,6 +1,6 @@ import 'dart:async'; -import 'package:centrifuge_dart/src/subscription/subscription_state.dart'; +import 'package:spinify/src/subscription/subscription_state.dart'; /// Stream of Centrifuge's [CentrifugeSubscriptionState] changes. /// {@category Subscription} diff --git a/lib/src/transport/transport_interface.dart b/lib/src/transport/transport_interface.dart index 9aed8e6..790380e 100644 --- a/lib/src/transport/transport_interface.dart +++ b/lib/src/transport/transport_interface.dart @@ -1,21 +1,22 @@ import 'dart:async'; -import 'package:centrifuge_dart/centrifuge.dart'; -import 'package:centrifuge_dart/src/model/event.dart'; -import 'package:centrifuge_dart/src/model/history.dart'; -import 'package:centrifuge_dart/src/model/presence.dart'; -import 'package:centrifuge_dart/src/model/presence_stats.dart'; -import 'package:centrifuge_dart/src/model/refresh.dart'; -import 'package:centrifuge_dart/src/model/stream_position.dart'; -import 'package:centrifuge_dart/src/subscription/server_subscription_manager.dart'; -import 'package:centrifuge_dart/src/subscription/subcibed_on_channel.dart'; -import 'package:centrifuge_dart/src/util/notifier.dart'; import 'package:meta/meta.dart'; +import 'package:spinify/src/client/state.dart'; +import 'package:spinify/src/model/event.dart'; +import 'package:spinify/src/model/history.dart'; +import 'package:spinify/src/model/presence.dart'; +import 'package:spinify/src/model/presence_stats.dart'; +import 'package:spinify/src/model/refresh.dart'; +import 'package:spinify/src/model/stream_position.dart'; +import 'package:spinify/src/subscription/server_subscription_manager.dart'; +import 'package:spinify/src/subscription/subcibed_on_channel.dart'; +import 'package:spinify/src/subscription/subscription_config.dart'; +import 'package:spinify/src/util/notifier.dart'; /// Class responsible for sending and receiving data from the server. /// {@nodoc} @internal -abstract interface class ICentrifugeTransport { +abstract interface class ISpinifyTransport { /// Current state /// {@nodoc} CentrifugeState get state; diff --git a/lib/src/transport/transport_protobuf_codec.dart b/lib/src/transport/transport_protobuf_codec.dart index 9438b46..d72c3f9 100644 --- a/lib/src/transport/transport_protobuf_codec.dart +++ b/lib/src/transport/transport_protobuf_codec.dart @@ -1,9 +1,9 @@ import 'dart:convert'; -import 'package:centrifuge_dart/src/model/protobuf/client.pb.dart' as pb; -import 'package:centrifuge_dart/src/util/logger.dart' as logger; import 'package:meta/meta.dart'; import 'package:protobuf/protobuf.dart' as pb; +import 'package:spinify/src/model/protobuf/client.pb.dart' as pb; +import 'package:spinify/src/util/logger.dart' as logger; /// {@nodoc} @internal diff --git a/lib/src/transport/ws_protobuf_transport.dart b/lib/src/transport/ws_protobuf_transport.dart index 8681a54..ecd4233 100644 --- a/lib/src/transport/ws_protobuf_transport.dart +++ b/lib/src/transport/ws_protobuf_transport.dart @@ -2,38 +2,44 @@ import 'dart:async'; import 'dart:collection'; import 'dart:convert'; -import 'package:centrifuge_dart/centrifuge.dart'; -import 'package:centrifuge_dart/src/client/disconnect_code.dart'; -import 'package:centrifuge_dart/src/model/channel_presence.dart'; -import 'package:centrifuge_dart/src/model/connect.dart'; -import 'package:centrifuge_dart/src/model/disconnect.dart'; -import 'package:centrifuge_dart/src/model/event.dart'; -import 'package:centrifuge_dart/src/model/history.dart'; -import 'package:centrifuge_dart/src/model/message.dart'; -import 'package:centrifuge_dart/src/model/presence.dart'; -import 'package:centrifuge_dart/src/model/presence_stats.dart'; -import 'package:centrifuge_dart/src/model/protobuf/client.pb.dart' as pb; -import 'package:centrifuge_dart/src/model/refresh.dart'; -import 'package:centrifuge_dart/src/model/stream_position.dart'; -import 'package:centrifuge_dart/src/model/subscribe.dart'; -import 'package:centrifuge_dart/src/model/unsubscribe.dart'; -import 'package:centrifuge_dart/src/subscription/server_subscription_manager.dart'; -import 'package:centrifuge_dart/src/subscription/subcibed_on_channel.dart'; -import 'package:centrifuge_dart/src/transport/transport_interface.dart'; -import 'package:centrifuge_dart/src/transport/transport_protobuf_codec.dart'; -import 'package:centrifuge_dart/src/util/logger.dart' as logger; -import 'package:centrifuge_dart/src/util/notifier.dart'; import 'package:meta/meta.dart'; import 'package:protobuf/protobuf.dart' as pb; +import 'package:spinify/src/client/config.dart'; +import 'package:spinify/src/client/disconnect_code.dart'; +import 'package:spinify/src/client/state.dart'; +import 'package:spinify/src/model/channel_presence.dart'; +import 'package:spinify/src/model/client_info.dart'; +import 'package:spinify/src/model/connect.dart'; +import 'package:spinify/src/model/disconnect.dart'; +import 'package:spinify/src/model/event.dart'; +import 'package:spinify/src/model/exception.dart'; +import 'package:spinify/src/model/history.dart'; +import 'package:spinify/src/model/message.dart'; +import 'package:spinify/src/model/presence.dart'; +import 'package:spinify/src/model/presence_stats.dart'; +import 'package:spinify/src/model/protobuf/client.pb.dart' as pb; +import 'package:spinify/src/model/publication.dart'; +import 'package:spinify/src/model/refresh.dart'; +import 'package:spinify/src/model/stream_position.dart'; +import 'package:spinify/src/model/subscribe.dart'; +import 'package:spinify/src/model/unsubscribe.dart'; +import 'package:spinify/src/subscription/server_subscription_manager.dart'; +import 'package:spinify/src/subscription/subcibed_on_channel.dart'; +import 'package:spinify/src/subscription/subscription.dart'; +import 'package:spinify/src/subscription/subscription_config.dart'; +import 'package:spinify/src/subscription/subscription_state.dart'; +import 'package:spinify/src/transport/transport_interface.dart'; +import 'package:spinify/src/transport/transport_protobuf_codec.dart'; +import 'package:spinify/src/util/logger.dart' as logger; +import 'package:spinify/src/util/notifier.dart'; import 'package:ws/ws.dart'; /// {@nodoc} @internal -abstract base class CentrifugeWSPBTransportBase - implements ICentrifugeTransport { +abstract base class CentrifugeWSPBTransportBase implements ISpinifyTransport { /// {@nodoc} CentrifugeWSPBTransportBase({ - required CentrifugeConfig config, + required SpinifyConfig config, }) : _config = config, _webSocket = WebSocketClient( WebSocketOptions.selector( @@ -62,7 +68,7 @@ abstract base class CentrifugeWSPBTransportBase /// Centrifuge config. /// {@nodoc} - final CentrifugeConfig _config; + final SpinifyConfig _config; @override final CentrifugeChangeNotifier events = @@ -111,7 +117,7 @@ abstract base class CentrifugeWSPBTransportBase /// {@nodoc} @internal // ignore: lines_longer_than_80_chars -final class CentrifugeWSPBTransport = CentrifugeWSPBTransportBase +final class SpinifyWSPBTransport = CentrifugeWSPBTransportBase with CentrifugeWSPBReplyMixin, CentrifugeWSPBStateHandlerMixin, diff --git a/pubspec.yaml b/pubspec.yaml index 55be85d..26d6cdd 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,4 +1,4 @@ -name: centrifuge_dart +name: spinify description: > Dart client to communicate with Centrifuge and Centrifugo from Flutter and VM @@ -8,9 +8,9 @@ version: 0.0.1-pre.1 homepage: https://centrifugal.dev -repository: https://github.com/PlugFox/centrifuge-client +repository: https://github.com/PlugFox/spinify -issue_tracker: https://github.com/PlugFox/centrifuge-client/issues +issue_tracker: https://github.com/PlugFox/spinify/issues funding: - https://www.buymeacoffee.com/plugfox @@ -18,11 +18,11 @@ funding: - https://boosty.to/plugfox topics: + - spinify - centrifugo - centrifuge - websocket - cross-platform - - client platforms: android: diff --git a/test/unit/centrifuge_test.dart b/test/unit/centrifuge_test.dart index 7fed22b..3806ca8 100644 --- a/test/unit/centrifuge_test.dart +++ b/test/unit/centrifuge_test.dart @@ -1,10 +1,10 @@ -import 'package:centrifuge_dart/centrifuge.dart'; +import 'package:spinify/spinify.dart'; import 'package:test/test.dart'; void main() => group('Centrifuge', () { const url = 'ws://localhost:8000/connection/websocket'; test('Connection', () async { - final client = Centrifuge(); + final client = Spinify(); await client.connect(url); expect(client.state, isA()); await client.disconnect();