DiagramDesigner/diagramCommunication/include/webSocketChannel.h

39 lines
912 B
C
Raw Normal View History

2025-12-12 17:46:37 +08:00
// WebSocketChannel.h
#pragma once
#include "baseChannel.h"
#include <QWebSocket>
class DIAGRAM_DESIGNER_PUBLIC WebSocketChannel : public BaseChannel
{
Q_OBJECT
public:
struct WebSocketConfig {
int heartbeatInterval = 30000;
};
WebSocketChannel(const ChannelConfig& config, QObject* parent = nullptr);
bool connect() override;
bool disconnect() override;
bool isConnected() const override;
bool send(const QByteArray& data) override;
bool sendText(const QString& text);
void setWebSocketConfig(const WebSocketConfig& config);
signals:
void textMessageReceived(const QString& message);
private slots:
void onConnected();
void onDisconnected();
void onTextMessageReceived(const QString& message);
void onBinaryMessageReceived(const QByteArray& message);
private:
QWebSocket* m_webSocket = nullptr;
WebSocketConfig m_wsConfig;
};