🐛 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("");
|
ValueNotifier<String> connectionError = ValueNotifier("");
|
||||||
|
|
||||||
void initWs() {
|
void initWs() {
|
||||||
|
if (wsConnected) {
|
||||||
|
ws?.sink.close(1000, "disconnect before initWs");
|
||||||
|
}
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
connectionError.value = "";
|
connectionError.value = "";
|
||||||
wsConnected = false;
|
wsConnected = false;
|
||||||
@ -142,6 +146,7 @@ class _GoMixHomeState extends State<GoMixHome> {
|
|||||||
wsConnected = false;
|
wsConnected = false;
|
||||||
if (connectionError.value != "") return;
|
if (connectionError.value != "") return;
|
||||||
Future.delayed(const Duration(seconds: 2), () {
|
Future.delayed(const Duration(seconds: 2), () {
|
||||||
|
if (wsConnected) return;
|
||||||
initWs();
|
initWs();
|
||||||
});
|
});
|
||||||
}, onError: (err) {
|
}, onError: (err) {
|
||||||
@ -221,7 +226,9 @@ class _GoMixHomeState extends State<GoMixHome> {
|
|||||||
icon: const Icon(Icons.remove_circle_outline_outlined),
|
icon: const Icon(Icons.remove_circle_outline_outlined),
|
||||||
color: Colors.red,
|
color: Colors.red,
|
||||||
tooltip: 'Not connected',
|
tooltip: 'Not connected',
|
||||||
onPressed: () {},
|
onPressed: () {
|
||||||
|
initWs();
|
||||||
|
},
|
||||||
),
|
),
|
||||||
actions: <Widget>[
|
actions: <Widget>[
|
||||||
Padding(
|
Padding(
|
||||||
|
Reference in New Issue
Block a user