diff --git a/lib/main.dart b/lib/main.dart index 810454f..0e98bd0 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -63,6 +63,10 @@ class _GoMixHomeState extends State { ValueNotifier connectionError = ValueNotifier(""); void initWs() { + if (wsConnected) { + ws?.sink.close(1000, "disconnect before initWs"); + } + setState(() { connectionError.value = ""; wsConnected = false; @@ -142,6 +146,7 @@ class _GoMixHomeState extends State { wsConnected = false; if (connectionError.value != "") return; Future.delayed(const Duration(seconds: 2), () { + if (wsConnected) return; initWs(); }); }, onError: (err) { @@ -221,7 +226,9 @@ class _GoMixHomeState extends State { icon: const Icon(Icons.remove_circle_outline_outlined), color: Colors.red, tooltip: 'Not connected', - onPressed: () {}, + onPressed: () { + initWs(); + }, ), actions: [ Padding(