Skip to content

Commit

Permalink
Refactor code to remove @internal annotations and update imports
Browse files Browse the repository at this point in the history
  • Loading branch information
PlugFox committed May 4, 2024
1 parent 97d5ac5 commit d9f89da
Show file tree
Hide file tree
Showing 15 changed files with 632 additions and 60 deletions.
6 changes: 4 additions & 2 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"recommendations": ["dart-code.dart-code"]
}
"recommendations": [
"dart-code.dart-code",
]
}
6 changes: 6 additions & 0 deletions lib/spinify_developer.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
library spinify.developer;

export 'spinify.dart';
export 'src/model/spinify_interface.dart';
export 'src/model/transport_interface.dart';
export 'src/transport_fake.dart';
4 changes: 2 additions & 2 deletions lib/src/event_bus.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ import 'dart:collection';
import 'package:meta/meta.dart';

import 'logger.dart' as log;
import 'spinify_interface.dart';
import 'model/spinify_interface.dart';

/// SpinifyBus Singleton class
/// That class is used to manage the event queue and work as a singleton
/// event bus to process, dispatch and manage all the events
/// in the Spinify clients.
@internal
@immutable
final class SpinifyEventBus {
SpinifyEventBus._internal();
Expand Down Expand Up @@ -84,6 +83,7 @@ abstract interface class ISpinifyEventBus$Bucket {
void unsubscribe(String event, Future<void> Function() callback);

/// Dispose the bucket
/// Do not use it directly
@internal
@visibleForTesting
void dispose();
Expand Down
191 changes: 191 additions & 0 deletions lib/src/model/command.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
import 'package:meta/meta.dart';

/// {@template command}
/// Command sent from a client to a server.
///
/// Server will
/// only take the first non-null request out of these and may return an error
/// if client passed more than one request.
/// {@category Command}
/// {@endtemplate}
@immutable
sealed class SpinifyCommand implements Comparable<SpinifyCommand> {
/// {@macro command}
const SpinifyCommand({
required this.id,
required this.timestamp,
});

/// ID of command to let client match replies to commands.
final int id;

/// Command type.
abstract final String type;

/// Timestamp of command.
final DateTime timestamp;

@override
int compareTo(SpinifyCommand other) =>
switch (timestamp.compareTo(other.timestamp)) {
0 => id.compareTo(other.id),
int result => result,
};
@override
int get hashCode => id ^ type.hashCode ^ timestamp.microsecondsSinceEpoch;

@override
bool operator ==(Object other) =>
identical(this, other) ||
other is SpinifyCommand &&
id == other.id &&
type == other.type &&
timestamp == other.timestamp;

@override
String toString() => '$type{id: $id}';
}

/// {@macro command}
final class SpinifyConnectRequest extends SpinifyCommand {
/// {@macro command}
const SpinifyConnectRequest({
required super.id,
required super.timestamp,
});

@override
String get type => 'ConnectRequest';
}

/// {@macro command}
final class SpinifySubscribeRequest extends SpinifyCommand {
/// {@macro command}
const SpinifySubscribeRequest({
required super.id,
required super.timestamp,
});

@override
String get type => 'SubscribeRequest';
}

/// {@macro command}
final class SpinifyUnsubscribeRequest extends SpinifyCommand {
/// {@macro command}
const SpinifyUnsubscribeRequest({
required super.id,
required super.timestamp,
});

@override
String get type => 'UnsubscribeRequest';
}

/// {@macro command}
final class SpinifyPublishRequest extends SpinifyCommand {
/// {@macro command}
const SpinifyPublishRequest({
required super.id,
required super.timestamp,
});

@override
String get type => 'PublishRequest';
}

/// {@macro command}
final class SpinifyPresenceRequest extends SpinifyCommand {
/// {@macro command}
const SpinifyPresenceRequest({
required super.id,
required super.timestamp,
});

@override
String get type => 'PresenceRequest';
}

/// {@macro command}
final class SpinifyPresenceStatsRequest extends SpinifyCommand {
/// {@macro command}
const SpinifyPresenceStatsRequest({
required super.id,
required super.timestamp,
});

@override
String get type => 'PresenceStatsRequest';
}

/// {@macro command}
final class SpinifyHistoryRequest extends SpinifyCommand {
/// {@macro command}
const SpinifyHistoryRequest({
required super.id,
required super.timestamp,
});

@override
String get type => 'HistoryRequest';
}

/// {@macro command}
final class SpinifyPingRequest extends SpinifyCommand {
/// {@macro command}
const SpinifyPingRequest({
required super.id,
required super.timestamp,
});

@override
String get type => 'PingRequest';
}

/// {@macro command}
final class SpinifySendRequest extends SpinifyCommand {
/// {@macro command}
const SpinifySendRequest({
required super.id,
required super.timestamp,
});

@override
String get type => 'SendRequest';
}

/// {@macro command}
final class SpinifyRPCRequest extends SpinifyCommand {
/// {@macro command}
const SpinifyRPCRequest({
required super.id,
required super.timestamp,
});

@override
String get type => 'RPCRequest';
}

/// {@macro command}
final class SpinifyRefreshRequest extends SpinifyCommand {
/// {@macro command}
const SpinifyRefreshRequest({
required super.id,
required super.timestamp,
});

@override
String get type => 'RefreshRequest';
}

/// {@macro command}
final class SpinifySubRefreshRequest extends SpinifyCommand {
/// {@macro command}
const SpinifySubRefreshRequest({
required super.id,
required super.timestamp,
});

@override
String get type => 'SubRefreshRequest';
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ abstract interface class ClientEvents {
static const String close = '${prefix}_close';
static const String connecting = '${prefix}_connecting';
static const String connected = '${prefix}_connected';
static const String disconnecting = '${prefix}_disconnecting';
static const String disconnected = '${prefix}_disconnected';
static const String stateChanged = '${prefix}_state_changed';
static const String command = '${prefix}_command';
static const String reply = '${prefix}_reply';
}
Loading

0 comments on commit d9f89da

Please sign in to comment.