Skip to content

Commit

Permalink
fix:
Browse files Browse the repository at this point in the history
- fix: Completer does not complete when the state is `Disconnected`
- fix: ErrorState does not emits when the exception is `WebsocketException`
  • Loading branch information
moshOntong-IT committed Jul 3, 2024
1 parent 6ce2a64 commit 1b798e9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# 0.1.0+1
# 0.1.2+1

- feat: initial commit 🎉
- fix: Completer does not complete when the state is `Disconnected`
- fix: ErrorState does not emits when the exception is `WebsocketException`

# 0.1.1+1

- feat: improve documentation

# 0.1.0+1

- feat: initial commit 🎉
28 changes: 20 additions & 8 deletions lib/src/services/src/realtime_mixin_ext.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ mixin RealtimeMixinExt {
connectionCompleter.complete();
}
} else if (newState is DisconnectedState || newState is ReconnectingState) {
if (!connectionCompleter.isCompleted) {
connectionCompleter.complete();
}

if (connectionCompleter.isCompleted) {
connectionCompleter = Completer<void>();
}
Expand Down Expand Up @@ -224,26 +228,34 @@ mixin RealtimeMixinExt {
);

_startPingTimer();
} on WebSocketException catch (e, _) {
} on WebSocketException catch (e, stackTrace) {
debugPrint('Websocket: $e');
_setState(
ErrorState(
error: e,
stackTrace: stackTrace,
),
);
if (e.message.contains('was not upgraded to websocket')) {
await toReconnect();
return;
}
} catch (e, stackTrace) {
debugPrint('Failed to connect to WebSocket: $e');
// stateController.add(
// ErrorState(
// error: e,
// stackTrace: stackTrace,
// ),
// );
isConnected = false;
_setState(
ErrorState(
error: e,
stackTrace: stackTrace,
),
);
debugPrint('Failed to connect to: $e');
// stateController.add(
// ErrorState(
// error: e,
// stackTrace: stackTrace,
// ),
// );

// if (e is AppwriteException) {
// rethrow;
// }
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: app_realtime_ext
description: A Realtime Clone from Appwrite Flutter sdk. The purpose of this is to extend the capability and separate from sdk-generator
version: 0.1.1+1
version: 0.1.2+1
license: MIT
homepage: https://github.com/moshOntong-IT/app_realtime_ext
repository: https://github.com/moshOntong-IT/app_realtime_ext
Expand Down

0 comments on commit 1b798e9

Please sign in to comment.