From 0d3f7bb3ee46a35f5612b7c6c39381973ca9744e Mon Sep 17 00:00:00 2001 From: Plague Fox Date: Wed, 12 Jun 2024 01:55:04 +0400 Subject: [PATCH] Refactor SpinifySubscriptionMixin to use specific implementation classes for client and server subscriptions --- lib/src/subscription_impl.dart | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/src/subscription_impl.dart b/lib/src/subscription_impl.dart index a745704..6e68579 100644 --- a/lib/src/subscription_impl.dart +++ b/lib/src/subscription_impl.dart @@ -37,14 +37,16 @@ abstract base class SpinifySubscriptionBase implements SpinifySubscription { return target; } - final StreamController _stateController = - StreamController.broadcast(); + SpinifySubscriptionState _state = + SpinifySubscriptionState.unsubscribed(code: 0, reason: 'initial state'); + final StreamController _stateController = + StreamController.broadcast(); final StreamController _eventController = StreamController.broadcast(); @override - SpinifySubscriptionState get state => throw UnimplementedError(); + SpinifySubscriptionState get state => _state; @override SpinifySubscriptionStateStream get states => throw UnimplementedError(); @@ -59,6 +61,11 @@ abstract base class SpinifySubscriptionBase implements SpinifySubscription { // TODO(plugfox): update since position } + @mustCallSuper + void setState(SpinifySubscriptionState state) { + _stateController.add(_state = state); + } + @mustCallSuper void close() { _stateController.close().ignore();