diff --git a/lib/src/spinify_impl.dart b/lib/src/spinify_impl.dart index 6d98726..80aec84 100644 --- a/lib/src/spinify_impl.dart +++ b/lib/src/spinify_impl.dart @@ -401,21 +401,13 @@ base mixin SpinifySubscriptionMixin on SpinifyBase, SpinifyCommandMixin { final sub = _clientSubscriptionRegistry[reply.event.channel] ?? _serverSubscriptionRegistry[reply.event.channel]; sub?.onEvent(reply.event); - config.logger?.call( - const SpinifyLogLevel.debug(), - 'push_received', - 'Push received', - { - 'push': reply, - 'event': reply.event, - }, - ); } else if (reply is SpinifyConnectResult) { // Update subscriptions state. - final entries = reply.subs?.entries; + //final entries = reply.subs?.entries; // TODO(plugfox): implement subscription state update /* for (final entry in entries) { - final MapEntry(key: channel, value: sub) = entry; + final MapEntry(key: channel, value: sub) + = entry; final subState = reply.subs[channel]; if (subState != null) { sub.state = subState; diff --git a/lib/src/subscription_impl.dart b/lib/src/subscription_impl.dart index dc34a61..de8bba4 100644 --- a/lib/src/subscription_impl.dart +++ b/lib/src/subscription_impl.dart @@ -4,6 +4,7 @@ import 'package:meta/meta.dart'; import 'model/channel_event.dart'; import 'model/channel_events.dart'; +import 'model/config.dart'; import 'model/exception.dart'; import 'model/history.dart'; import 'model/presence_stats.dart'; @@ -37,6 +38,8 @@ abstract base class SpinifySubscriptionBase implements SpinifySubscription { return target; } + SpinifyLogger? get _logger => _client.config.logger; + SpinifySubscriptionState _state = SpinifySubscriptionState.unsubscribed(code: 0, reason: 'initial state'); final StreamController _stateController = @@ -49,7 +52,8 @@ abstract base class SpinifySubscriptionBase implements SpinifySubscription { SpinifySubscriptionState get state => _state; @override - SpinifySubscriptionStates get states => throw UnimplementedError(); + SpinifySubscriptionStates get states => + SpinifySubscriptionStates(_stateController.stream); @override SpinifyChannelEvents get stream => @@ -59,11 +63,32 @@ abstract base class SpinifySubscriptionBase implements SpinifySubscription { void onEvent(SpinifyChannelEvent event) { _eventController.add(event); // TODO(plugfox): update since position + + _logger?.call( + const SpinifyLogLevel.debug(), + 'channel_event_received', + 'Channel event received', + { + 'channel': channel, + 'subscription': this, + 'event': event, + }, + ); } @mustCallSuper void setState(SpinifySubscriptionState state) { _stateController.add(_state = state); + _logger?.call( + const SpinifyLogLevel.debug(), + 'subscription_state_changed', + 'Subscription state changed', + { + 'channel': channel, + 'subscription': this, + 'state': _state, + }, + ); } @mustCallSuper