master
dsc 2 years ago
parent 4a8e27b031
commit 758cc0926d

@ -2,7 +2,7 @@
op Maemo:
```
sudo apt install -y ccache cmake build-essential libx11-dev zlib1g-dev libpng-dev qtbase5-dev libqt5svg5-dev libqt5svg5-dev libqt5maemo5-dev libqt5x11extras5-dev gdb libqt5quickcontrols2-5 qtquickcontrols2-5-dev qml-module-qtquick-controls2 qml-module-qtquick2 qml-module-qtquick-layouts qml-module-qtquick-controls qml-module-qtquick-extras qml-module-qtquick-dialogs libqt5websockets5-dev libqt5x11extras5-dev qml-module-qtquick-controls qml-module-qtquick-layouts qtquickcontrols2-5-dev
sudo apt install -y ccache cmake build-essential libx11-dev zlib1g-dev libpng-dev qtbase5-dev libqt5svg5-dev libqt5svg5-dev libqt5maemo5-dev libqt5x11extras5-dev gdb libqt5quickcontrols2-5 qtquickcontrols2-5-dev qml-module-qtquick-controls2 qml-module-qtquick2 qml-module-qtquick-layouts qml-module-qtquick-controls qml-module-qtquick-extras qml-module-qtquick-dialogs libqt5x11extras5-dev qml-module-qtquick-controls qml-module-qtquick-layouts qtquickcontrols2-5-dev
```
As `user`:

1
debian/control vendored

@ -12,7 +12,6 @@ Build-Depends: debhelper (>= 10),
libqt5svg5-dev,
libqt5maemo5-dev,
libqt5x11extras5-dev,
libqt5websockets5-dev,
qtquickcontrols2-5-dev,
libosso-abook-dev,
Homepage: https://github.com/maemo-leste/conversations

@ -15,7 +15,7 @@ file(GLOB SOURCE_FILES
"models/*.cpp"
)
find_package(Qt5 REQUIRED COMPONENTS Core Widgets Gui Network Svg Xml Quick QuickWidgets Qml QuickControls2 WebSockets)
find_package(Qt5 REQUIRED COMPONENTS Core Widgets Gui Network Svg Xml Quick QuickWidgets Qml QuickControls2)
if(MAEMO)
find_package(Qt5 REQUIRED COMPONENTS Maemo5)
endif()
@ -100,7 +100,6 @@ target_link_libraries(conversations PUBLIC
Qt5::QuickWidgets
Qt5::Qml
Qt5::QuickControls2
Qt5::WebSockets
Threads::Threads
${GLib_LIBRARY}
${RTCOM-EVENTLOGGER_LIBRARIES}

@ -1,79 +0,0 @@
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2020-2021, The Monero Project.
#include <QObject>
#include <QNetworkAccessManager>
#include <QScreen>
#include <QDesktopWidget>
#include "wsclient.h"
#include "conversations.h"
WSClient::WSClient(Conversations *ctx, const QString &url, QObject *parent) :
QObject(parent),
m_ctx(ctx) {
connect(&this->webSocket, &QWebSocket::binaryMessageReceived, this, &WSClient::onbinaryMessageReceived);
connect(&this->webSocket, &QWebSocket::connected, this, &WSClient::onConnected);
connect(&this->webSocket, &QWebSocket::disconnected, this, &WSClient::closed);
connect(&this->webSocket, QOverload<QAbstractSocket::SocketError>::of(&QWebSocket::error), this, &WSClient::onError);
this->url = QString("ws://%1/ws").arg(url);
qCritical() << this->url;
connect(&m_pingTimer, &QTimer::timeout, [this]{
if (this->webSocket.state() == QAbstractSocket::ConnectedState)
this->webSocket.ping();
});
m_pingTimer.setInterval(30 * 1000);
m_pingTimer.start();
}
void WSClient::sendMsg(const QByteArray &data) {
auto state = this->webSocket.state();
if(state == QAbstractSocket::ConnectedState)
this->webSocket.sendBinaryMessage(data);
}
void WSClient::start() {
// connect & reconnect on errors/close
#ifdef QT_DEBUG
qDebug() << "WebSocket connect:" << url.url();
#endif
this->webSocket.open(QUrl(this->url));
if(!this->m_connectionTimer.isActive()) {
connect(&this->m_connectionTimer, &QTimer::timeout, this, &WSClient::checkConnection);
this->m_connectionTimer.start(2000);
}
}
void WSClient::checkConnection() {
auto state = this->webSocket.state();
if(state == QAbstractSocket::UnconnectedState) {
#ifdef QT_DEBUG
qDebug() << "WebSocket reconnect";
#endif
this->start();
}
}
void WSClient::onConnected() {
#ifdef QT_DEBUG
qDebug() << "WebSocket connected";
#endif
emit connectionEstablished();
}
void WSClient::onError(QAbstractSocket::SocketError error) {
qCritical() << "WebSocket error: " << error;
auto state = this->webSocket.state();
if(state == QAbstractSocket::ConnectedState || state == QAbstractSocket::ConnectingState)
this->webSocket.abort();
}
void WSClient::onbinaryMessageReceived(const QByteArray &message) {
#ifdef QT_DEBUG
qDebug() << "WebSocket (client) received:" << message;
#endif
QJsonDocument doc = QJsonDocument::fromJson(message);
QJsonObject object = doc.object();
emit WSMessage(object);
}

@ -1,40 +0,0 @@
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2020-2021, The Monero Project.
#ifndef ECHOCLIENT_H
#define ECHOCLIENT_H
#include <QObject>
#include <QWebSocket>
#include <QTimer>
class Conversations;
class WSClient : public QObject
{
Q_OBJECT
public:
explicit WSClient(Conversations *ctx, const QString &url, QObject *parent = nullptr);
void start();
void sendMsg(const QByteArray &data);
QWebSocket webSocket;
QString url;
signals:
void closed();
void connectionEstablished();
void WSMessage(QJsonObject message);
private slots:
void onConnected();
void onbinaryMessageReceived(const QByteArray &message);
void checkConnection();
void onError(QAbstractSocket::SocketError error);
private:
QTimer m_connectionTimer;
QTimer m_pingTimer;
Conversations *m_ctx;
};
#endif // ECHOCLIENT_H
Loading…
Cancel
Save