🐛 Properly disconnect from previous websocket on server change
This commit is contained in:
@ -63,6 +63,10 @@ class _GoMixHomeState extends State<GoMixHome> {
|
||||
ValueNotifier<String> 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<GoMixHome> {
|
||||
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<GoMixHome> {
|
||||
icon: const Icon(Icons.remove_circle_outline_outlined),
|
||||
color: Colors.red,
|
||||
tooltip: 'Not connected',
|
||||
onPressed: () {},
|
||||
onPressed: () {
|
||||
initWs();
|
||||
},
|
||||
),
|
||||
actions: <Widget>[
|
||||
Padding(
|
||||
|
Reference in New Issue
Block a user