Skip to content

Commit

Permalink
Fix multiple websocket connection was established after change api en…
Browse files Browse the repository at this point in the history
…trypoint
  • Loading branch information
lifegpc authored May 29, 2024
1 parent 4e013e3 commit 69929d6
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/task.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ class TaskManager {
Future<void> connect() async {
if (auth.canManageTasks != true) return;
try {
_channel = await connectWebSocket(api.getTaskUrl());
final url = api.getTaskUrl();
_channel = await connectWebSocket(url);
_channel!.stream.listen((event) {
try {
final data = jsonDecode(event) as Map<String, dynamic>;
Expand Down Expand Up @@ -196,7 +197,8 @@ class TaskManager {
}
}, onError: (e) {
_log.warning("Task websocket error: $e");
if (_allowReconnect && !_needClosed) {
final url2 = api.getTaskUrl();
if (_allowReconnect && !_needClosed && url == url2) {
_log.info("Reconnecting to task server in 5 seconds");
_reconnectTimer = Timer(const Duration(seconds: 5), () {
_reconnectTimer = null;
Expand All @@ -209,7 +211,8 @@ class TaskManager {
}, onDone: () {
_log.warning(
"WenSocket closed: ${_channel?.closeCode} ${_channel?.closeReason}");
if (_allowReconnect && !_needClosed) {
final url2 = api.getTaskUrl();
if (_allowReconnect && !_needClosed && url == url2) {
_log.info("Reconnecting to task server in 5 seconds");
_reconnectTimer = Timer(const Duration(seconds: 5), () {
_reconnectTimer = null;
Expand Down

0 comments on commit 69929d6

Please sign in to comment.