feat: lots of fixes
This commit is contained in:
@ -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'],
|
||||
|
Reference in New Issue
Block a user