feat: lots of fixes

This commit is contained in:
2024-03-14 20:50:30 +01:00
parent 5d617131ee
commit 48476f6fe4
11 changed files with 377 additions and 136 deletions

View File

@ -118,7 +118,7 @@ class OwntracksApi {
}
// Method to create and return a WebSocket connection
Future<WebSocketClient> createWebSocketConnection({
Future<Result<WebSocketClient>> createWebSocketConnection({
required String wsPath,
required void Function(Object message) onMessage,
required void Function(WebSocketClientState stateChange) onStateChange,
@ -149,10 +149,15 @@ class OwntracksApi {
client.stateChanges.listen(onStateChange);
// Connect to the WebSocket server
await client.connect("${baseUrl.replaceFirst('http', 'ws')}/ws/$wsPath");
try {
await client.connect("${baseUrl.replaceFirst('http', 'ws')}/ws/$wsPath");
} catch (e) {
await client.disconnect();
return bail("WebSocket connection to path $wsPath was unsuccessful: $e");
}
// Return the connected client
return client;
return Ok(client);
}
}
@ -163,6 +168,11 @@ class Point {
Point({required this.lat, required this.lon, required this.timestamp});
@override
String toString() {
return 'Point{lat: $lat, lon: $lon, timestamp: $timestamp}';
}
factory Point.fromJson(Map<String, dynamic> json) {
return Point(
lat: json['lat'],