mirror of
https://github.com/betaflight/betaflight-configurator.git
synced 2025-07-26 09:45:28 +03:00
Fix socket reset (#4304)
* Fix socket reset * Fix dropdown being disabled
This commit is contained in:
parent
b5ec4c36cb
commit
9e2dfa362b
2 changed files with 25 additions and 22 deletions
|
@ -76,20 +76,15 @@ class WebsocketSerial extends EventTarget {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.ws.onclose = function (e) {
|
this.ws.onclose = async function (e) {
|
||||||
console.log(`${socket.logHead} Connection closed: `, e);
|
console.log(`${socket.logHead} Connection closed: `, e);
|
||||||
|
|
||||||
socket.disconnect(() => {
|
await socket.disconnect();
|
||||||
socket.dispatchEvent(new CustomEvent("disconnect", this.disconnect.bind(this)));
|
socket.dispatchEvent(new CustomEvent("disconnect", { detail: { socketId: socket.address } }));
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.ws.onerror = function (e) {
|
this.ws.onerror = function (e) {
|
||||||
console.error(`${socket.logHead} Connection error: `, e);
|
console.error(`${socket.logHead} Connection error: `, e);
|
||||||
|
|
||||||
socket.disconnect(() => {
|
|
||||||
socket.dispatchEvent(new CustomEvent("disconnect", this.disconnect.bind(this)));
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.ws.onmessage = async function (msg) {
|
this.ws.onmessage = async function (msg) {
|
||||||
|
|
|
@ -234,6 +234,23 @@ function setConnectionTimeout() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resetConnection() {
|
||||||
|
// reset connect / disconnect button
|
||||||
|
$("div#connectbutton div.connect_state").text(i18n.getMessage("connect"));
|
||||||
|
$("div#connectbutton a.connect").removeClass("active");
|
||||||
|
|
||||||
|
CONFIGURATOR.connectionValid = false;
|
||||||
|
CONFIGURATOR.cliValid = false;
|
||||||
|
CONFIGURATOR.cliActive = false;
|
||||||
|
CONFIGURATOR.cliEngineValid = false;
|
||||||
|
CONFIGURATOR.cliEngineActive = false;
|
||||||
|
|
||||||
|
// unlock port select & baud
|
||||||
|
PortHandler.portPickerDisabled = false;
|
||||||
|
// reset data
|
||||||
|
isConnected = false;
|
||||||
|
}
|
||||||
|
|
||||||
function abortConnection() {
|
function abortConnection() {
|
||||||
GUI.timeout_remove("connecting"); // kill connecting timer
|
GUI.timeout_remove("connecting"); // kill connecting timer
|
||||||
|
|
||||||
|
@ -244,14 +261,7 @@ function abortConnection() {
|
||||||
|
|
||||||
gui_log(i18n.getMessage("serialPortOpenFail"));
|
gui_log(i18n.getMessage("serialPortOpenFail"));
|
||||||
|
|
||||||
$("div#connectbutton div.connect_state").text(i18n.getMessage("connect"));
|
resetConnection();
|
||||||
$("div#connectbutton a.connect").removeClass("active");
|
|
||||||
|
|
||||||
// unlock port select & baud
|
|
||||||
PortHandler.portPickerDisabled = false;
|
|
||||||
|
|
||||||
// reset data
|
|
||||||
isConnected = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -696,6 +706,10 @@ function onClosed(result) {
|
||||||
$("#dataflash_wrapper_global").hide();
|
$("#dataflash_wrapper_global").hide();
|
||||||
$("#quad-status_wrapper").hide();
|
$("#quad-status_wrapper").hide();
|
||||||
|
|
||||||
|
console.log("[SERIAL-BACKEND] Connection closed:", result);
|
||||||
|
|
||||||
|
resetConnection();
|
||||||
|
|
||||||
clearLiveDataRefreshTimer();
|
clearLiveDataRefreshTimer();
|
||||||
|
|
||||||
MSP.clearListeners();
|
MSP.clearListeners();
|
||||||
|
@ -705,12 +719,6 @@ function onClosed(result) {
|
||||||
serial.removeEventListener("connect", connectHandler);
|
serial.removeEventListener("connect", connectHandler);
|
||||||
serial.removeEventListener("disconnect", disconnectHandler);
|
serial.removeEventListener("disconnect", disconnectHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
CONFIGURATOR.connectionValid = false;
|
|
||||||
CONFIGURATOR.cliValid = false;
|
|
||||||
CONFIGURATOR.cliActive = false;
|
|
||||||
CONFIGURATOR.cliEngineValid = false;
|
|
||||||
CONFIGURATOR.cliEngineActive = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function read_serial(info) {
|
export function read_serial(info) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue