Skip to content

Commit

Permalink
Refactor SpinifyCommandMixin error handling and connection logic
Browse files Browse the repository at this point in the history
  • Loading branch information
PlugFox committed May 12, 2024
1 parent 70353cf commit 8d096ea
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/src/spinify_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ base mixin SpinifyCommandMixin on SpinifyBase {
/// Base mixin for Spinify client connection management (connect & disconnect).
base mixin SpinifyConnectionMixin
on SpinifyBase, SpinifyCommandMixin, SpinifyStateMixin {
/// Last connected URL.
/// Used for reconnecting after connection lost.
/// If null, then client is not connected or interractively disconnected.
String? _reconnectUrl;
Completer<void>? _readyCompleter;

@protected
Expand All @@ -175,6 +179,7 @@ base mixin SpinifyConnectionMixin
await disconnect();
try {
_setState(SpinifyState$Connecting(url: url));
_reconnectUrl = url;

// Create new transport.
_transport = await _createTransport(url, config.headers)
Expand Down Expand Up @@ -279,6 +284,7 @@ base mixin SpinifyConnectionMixin

@override
Future<void> disconnect() async {
_reconnectUrl = null;
if (state.isDisconnected) return Future.value();
await _transport?.disconnect(1000, 'Client disconnecting');
await _onDisconnect();
Expand Down

0 comments on commit 8d096ea

Please sign in to comment.