2018-02-12 15:35:08 +01:00
|
|
|
#pragma once
|
|
|
|
|
2018-04-18 18:39:25 +02:00
|
|
|
#include <QByteArray>
|
2018-02-12 15:35:08 +01:00
|
|
|
#include <QJsonDocument>
|
2018-04-18 18:39:25 +02:00
|
|
|
#include <QJsonObject>
|
2018-02-12 15:35:08 +01:00
|
|
|
#include <QJsonParseError>
|
2018-04-18 18:39:25 +02:00
|
|
|
#include <QLocalServer>
|
|
|
|
#include <QLocalSocket>
|
|
|
|
#include <QObject>
|
|
|
|
#include <QQuickItem>
|
|
|
|
#include <QSharedDataPointer>
|
|
|
|
#include <QSharedPointer>
|
2018-02-12 15:35:08 +01:00
|
|
|
#include <QTimer>
|
|
|
|
|
2018-04-18 18:39:25 +02:00
|
|
|
class ScreenPlaySDK : public QQuickItem {
|
2018-02-12 15:35:08 +01:00
|
|
|
Q_OBJECT
|
|
|
|
Q_DISABLE_COPY(ScreenPlaySDK)
|
|
|
|
|
|
|
|
public:
|
2018-04-18 18:39:25 +02:00
|
|
|
ScreenPlaySDK(QQuickItem* parent = nullptr);
|
2018-02-12 15:35:08 +01:00
|
|
|
~ScreenPlaySDK();
|
|
|
|
|
|
|
|
Q_PROPERTY(QString contentType READ contentType WRITE setContentType NOTIFY contentTypeChanged)
|
|
|
|
Q_PROPERTY(bool isConnected READ isConnected WRITE setIsConnected NOTIFY isConnectedChanged)
|
2018-03-12 16:20:48 +01:00
|
|
|
Q_PROPERTY(QString appID READ appID WRITE setAppID NOTIFY appIDChanged)
|
|
|
|
|
2018-02-12 15:35:08 +01:00
|
|
|
QString contentType() const
|
|
|
|
{
|
|
|
|
return m_contentType;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isConnected() const
|
|
|
|
{
|
|
|
|
return m_isConnected;
|
|
|
|
}
|
|
|
|
|
2018-03-12 16:20:48 +01:00
|
|
|
QString appID() const
|
|
|
|
{
|
|
|
|
return m_appID;
|
|
|
|
}
|
|
|
|
|
2018-02-12 15:35:08 +01:00
|
|
|
public slots:
|
|
|
|
void connected();
|
|
|
|
void disconnected();
|
|
|
|
void bytesWritten(qint64 bytes);
|
|
|
|
void readyRead();
|
|
|
|
void error(QLocalSocket::LocalSocketError socketError);
|
|
|
|
|
|
|
|
void setContentType(QString contentType)
|
|
|
|
{
|
|
|
|
if (m_contentType == contentType)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_contentType = contentType;
|
|
|
|
|
2018-04-18 18:39:25 +02:00
|
|
|
if (isConnected()) {
|
2018-02-12 15:35:08 +01:00
|
|
|
m_socket.data()->write(QByteArray(m_contentType.toLatin1()));
|
|
|
|
m_socket.data()->flush();
|
|
|
|
m_socket.data()->waitForBytesWritten();
|
|
|
|
}
|
|
|
|
emit contentTypeChanged(m_contentType);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setIsConnected(bool isConnected)
|
|
|
|
{
|
|
|
|
if (m_isConnected == isConnected)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_isConnected = isConnected;
|
|
|
|
emit isConnectedChanged(m_isConnected);
|
|
|
|
}
|
|
|
|
|
2018-03-12 16:20:48 +01:00
|
|
|
void setAppID(QString appID)
|
|
|
|
{
|
|
|
|
if (m_appID == appID)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_appID = appID;
|
|
|
|
emit appIDChanged(m_appID);
|
2018-04-18 18:39:25 +02:00
|
|
|
|
2018-03-12 16:20:48 +01:00
|
|
|
m_socket.data()->write(QByteArray(appID.toUtf8()));
|
|
|
|
m_socket.data()->waitForBytesWritten();
|
|
|
|
}
|
|
|
|
|
2018-02-12 15:35:08 +01:00
|
|
|
signals:
|
2018-03-12 16:20:48 +01:00
|
|
|
void incommingMessage(QString key, QString value);
|
2018-02-12 15:35:08 +01:00
|
|
|
void incommingMessageError(QString msg);
|
|
|
|
|
|
|
|
void sdkConnected();
|
|
|
|
void sdkDisconnected();
|
|
|
|
void sdkSocketError(QString type);
|
|
|
|
|
|
|
|
void contentTypeChanged(QString contentType);
|
|
|
|
void isConnectedChanged(bool isConnected);
|
|
|
|
|
2018-03-12 16:20:48 +01:00
|
|
|
void appIDChanged(QString appID);
|
|
|
|
|
2018-02-12 15:35:08 +01:00
|
|
|
private:
|
|
|
|
QSharedPointer<QLocalSocket> m_socket;
|
|
|
|
|
|
|
|
QString m_contentType = "undefined";
|
|
|
|
bool m_isConnected = false;
|
2018-03-12 16:20:48 +01:00
|
|
|
|
|
|
|
QString m_appID;
|
2018-02-12 15:35:08 +01:00
|
|
|
};
|