Settings: allow disabling websocket

This commit is contained in:
tobtoht
2022-03-04 22:55:29 +01:00
parent 7f73decc41
commit 07d7dfffcb
8 changed files with 76 additions and 2 deletions
+15 -1
View File
@@ -38,15 +38,29 @@ void WebsocketClient::sendMsg(const QByteArray &data) {
}
void WebsocketClient::start() {
if (m_stopped) {
return;
}
// connect & reconnect on errors/close
qDebug() << "WebSocket connect:" << m_url.url();
auto state = webSocket.state();
if (state != QAbstractSocket::ConnectedState && state != QAbstractSocket::ConnectingState) {
webSocket.open(m_url);
}
}
void WebsocketClient::restart() {
m_stopped = false;
this->start();
}
void WebsocketClient::stop() {
m_stopped = true;
webSocket.close();
m_connectionTimeout.stop();
}
void WebsocketClient::onConnected() {
qDebug() << "WebSocket connected";
emit connectionEstablished();
+3
View File
@@ -16,6 +16,8 @@ class WebsocketClient : public QObject {
public:
explicit WebsocketClient(QObject *parent = nullptr);
void start();
void restart();
void stop();
void sendMsg(const QByteArray &data);
QWebSocket webSocket;
@@ -39,6 +41,7 @@ private:
QTimer m_connectionTimeout;
int m_timeout = 10;
int m_websocketUrlIndex = 0;
bool m_stopped = false;
};
#endif //FEATHER_WEBSOCKETCLIENT_H
+1
View File
@@ -67,6 +67,7 @@ static const QHash<Config::ConfigKey, ConfigDirective> configStrings = {
{Config::balanceDisplay, {QS("balanceDisplay"), Config::BalanceDisplay::spendablePlusUnconfirmed}},
{Config::inactivityLockEnabled, {QS("inactivityLockEnabled"), false}},
{Config::inactivityLockTimeout, {QS("inactivityLockTimeout"), 10}},
{Config::disableWebsocket, {QS("disableWebsocket"), false}},
{Config::multiBroadcast, {QS("multiBroadcast"), true}},
{Config::warnOnExternalLink,{QS("warnOnExternalLink"), true}},
+1
View File
@@ -71,6 +71,7 @@ public:
balanceDisplay,
inactivityLockEnabled,
inactivityLockTimeout,
disableWebsocket,
multiBroadcast,
warnOnExternalLink,