fix: continuing error managment and documentation

This commit is contained in:
alzalia1 2025-08-23 12:35:36 +02:00
parent 59e1c2558c
commit dad000a1b9
24 changed files with 389 additions and 182 deletions

View file

@ -8,13 +8,23 @@ import 'package:seshat/config/constants.dart';
import 'package:seshat/domain/models/owner.dart';
import 'package:web_socket_channel/web_socket_channel.dart';
/// API Client to manages connections to WebSockets
class WebsocketClient {
WebSocketChannel? _channel;
/// Storage to access JWT
FlutterSecureStorage? _secureStorage;
/// Raw channel of data from WebSocket
WebSocketChannel? _channel;
/// Global WebSocket Stream
final BehaviorSubject<dynamic> _baseController = BehaviorSubject();
/// WebSocket Stream dedicated to [Owner] entries
final BehaviorSubject<Owner> _ownersController = BehaviorSubject<Owner>(
sync: true,
);
/// Subscription to [_baseController]
late final StreamSubscription sub;
Logger log = Logger(
printer: PrettyPrinter(
@ -25,12 +35,15 @@ class WebsocketClient {
),
);
/// Gets a stream of [Owner]
Stream<Owner> get owners => _ownersController.stream;
/// Initializes connection to the [_secureStorage]
Future<void> _initStore() async {
_secureStorage ??= const FlutterSecureStorage();
}
/// Connects to the websocket
Future<void> connect() async {
final url = "wss://$apiBasePath/ws";
log.i("Webocket: $url");
@ -69,11 +82,13 @@ class WebsocketClient {
}
}
/// Disconnects from the websocket
void _handleDisconnect() {
sub.cancel();
_channel = null;
}
/// Closes all connections
void dispose() {
sub.cancel();
_channel?.sink.close();