🐛 Fix listen stream that already listened

This commit is contained in:
LittleSheep 2024-06-02 23:20:34 +08:00
parent 9287e3fc90
commit 19e243e277
2 changed files with 6 additions and 0 deletions

View File

@ -36,6 +36,8 @@ class AccountProvider extends GetxController {
} }
void connect({noRetry = false}) async { void connect({noRetry = false}) async {
if (isConnected.value) return;
final AuthProvider auth = Get.find(); final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized'); if (!await auth.isAuthorized) throw Exception('unauthorized');
@ -66,6 +68,7 @@ class AccountProvider extends GetxController {
void disconnect() { void disconnect() {
websocket?.sink.close(WebSocketStatus.normalClosure); websocket?.sink.close(WebSocketStatus.normalClosure);
websocket = null;
isConnected.value = false; isConnected.value = false;
} }

View File

@ -17,6 +17,8 @@ class ChatProvider extends GetxController {
StreamController<NetworkPackage> stream = StreamController.broadcast(); StreamController<NetworkPackage> stream = StreamController.broadcast();
void connect({noRetry = false}) async { void connect({noRetry = false}) async {
if (isConnected.value) return;
final AuthProvider auth = Get.find(); final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized'); if (!await auth.isAuthorized) throw Exception('unauthorized');
@ -47,6 +49,7 @@ class ChatProvider extends GetxController {
void disconnect() { void disconnect() {
websocket?.sink.close(WebSocketStatus.normalClosure); websocket?.sink.close(WebSocketStatus.normalClosure);
websocket = null;
isConnected.value = false; isConnected.value = false;
} }