add WebSockets support

This commit is contained in:
Syping 2020-09-19 09:31:57 +02:00
parent 2af86f0524
commit d4a25b8346
5 changed files with 223 additions and 104 deletions

View file

@ -19,8 +19,10 @@
#ifndef SMSUBSERVER_H
#define SMSUBSERVER_H
#include <QWebSocketServer>
#include <QLocalServer>
#include <QLocalSocket>
#include <QWebSocket>
#include <QObject>
struct SMSubServerSettings
@ -29,26 +31,36 @@ struct SMSubServerSettings
bool isLocal;
};
class SMSubServer : public QLocalServer
class SMSubServer : public QObject
{
Q_OBJECT
public:
SMSubServer(SMSubServerSettings *serverSettings, const QString &socket);
SMSubServer(SMSubServerSettings *serverSettings, const QString &serverName, const quint16 &port);
bool isListening();
enum ServerType { Local, WebSocket };
Q_ENUM(ServerType)
public slots:
void writeOutput(const QByteArray &output);
void registerToken(const QString &token);
private slots:
void incomingConnection(quintptr socketDescriptor);
void wsMessageReceived(const QByteArray &message);
void lsReadyRead();
void newConnection();
void deleteSocket();
void readyRead();
private:
inline void debugOutput(QLocalSocket *socket, const QByteArray &message);
inline void debugOutput(QObject *socket, const QByteArray &message);
inline void sendMessage(QObject *socket, const QByteArray &message);
void messageReceived(QObject *socket, const QByteArray &message);
SMSubServerSettings *serverSettings;
QVector<QLocalSocket*> sockets;
QVector<QObject*> sockets;
QVector<QString> tokens;
ServerType type;
QObject *server;
signals:
void tokenRegistered(const QString &password);