first commit
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
#ifndef WEBSOCKETCLIENT_H
|
||||
#define WEBSOCKETCLIENT_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QWebSocket>
|
||||
#include <QUrl>
|
||||
#include <QTimer>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
|
||||
class WebSocketClient : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit WebSocketClient(QObject *parent = nullptr);
|
||||
~WebSocketClient();
|
||||
|
||||
// Внешние методы
|
||||
Q_INVOKABLE bool connectToServer(const QString &url);
|
||||
Q_INVOKABLE void disconnectFromServer();
|
||||
Q_INVOKABLE void sendMessage(const QString &message);
|
||||
Q_INVOKABLE bool isConnected() const;
|
||||
|
||||
// Методы для Twitch чата
|
||||
Q_INVOKABLE void connectToTwitchChat(const QString &oauthToken, const QString &nickname, const QString &channel);
|
||||
Q_INVOKABLE void joinChannel(const QString &channel);
|
||||
Q_INVOKABLE void sendChatMessage(const QString &channel, const QString &message);
|
||||
|
||||
signals:
|
||||
// Внешние сигналы
|
||||
void onNewMessage(const QString &message);
|
||||
void onConnected();
|
||||
void onDisconnected();
|
||||
void onError(const QString &errorMessage);
|
||||
|
||||
private slots:
|
||||
// Внутренние слоты
|
||||
void onConnectedInternal();
|
||||
void onDisconnectedInternal();
|
||||
void onTextMessageReceived(const QString &message);
|
||||
void onErrorInternal(QAbstractSocket::SocketError error);
|
||||
void onSslErrors(const QList<QSslError> &errors);
|
||||
void onPingTimeout();
|
||||
void pingServer();
|
||||
private:
|
||||
// Внутренние методы
|
||||
void send(const QString &data);
|
||||
void sendIrcCommand(const QString &command, const QString ¶meters = "");
|
||||
void authenticate(const QString &oauthToken, const QString &nickname);
|
||||
|
||||
private:
|
||||
QWebSocket *m_webSocket;
|
||||
QTimer *m_pingTimer;
|
||||
bool m_isConnected;
|
||||
QString m_nickname;
|
||||
QString m_currentChannel;
|
||||
QString m_oauthToken;
|
||||
bool m_channelJoined;
|
||||
};
|
||||
|
||||
#endif // WEBSOCKETCLIENT_H
|
||||
Reference in New Issue
Block a user