#ifndef CWEBSOCKETPROC_H
#define CWEBSOCKETPROC_H

#include <QtCore/QObject>
#include <QtWebSockets/QWebSocket>
#include <QTimer>
#include <QMaskGenerator>


class CWebsocketProc : public QObject
{
    Q_OBJECT
public:
    CWebsocketProc();
    ~CWebsocketProc();
    void setUrl(QString sUrl, QString sToken, QString sKey);
    void open();
    void open(QString sUrl, QString sToken, QString sKey);
    void close();
    qint64 sendText(QString sText);

    bool isConnected();
signals:
    void connected();
    void clientOffLine();
    void networkWeak();
    void websocketError(QString sErrorStr);

   void mobileStatus(__int64 nExamRecordDataId, int nOrder, QString sScanStatus);
   void fileAnswer(__int64 nExamRecordDataId, int nOrder, QString sFileType, QString sFileUrl);
private Q_SLOTS:
    void onDisconnected();
    void onConnected();
    void onTextReceived(QString msg);
    void reconnect();
private:    
    QWebSocket *m_pWebsocket;

    QTimer *m_pTime;
    int m_nTimeOutLimit;
    int m_nTimeOutSecord;
    int m_nTimeOutTimes;

    QString m_sUrl;
    QString m_sToken;
    QString m_sKey;

    bool m_bConnected;

    bool m_isExitClosed;
};

extern std::shared_ptr<CWebsocketProc> g_websocketPtr;

#endif // CWEBSOCKETPROC_H
