2018-02-12 15:35:08 +01:00
|
|
|
#include "screenplaysdk.h"
|
|
|
|
|
|
|
|
ScreenPlaySDK::ScreenPlaySDK(QQuickItem *parent):
|
|
|
|
QQuickItem(parent)
|
|
|
|
{
|
|
|
|
// By default, QQuickItem does not draw anything. If you subclass
|
|
|
|
// QQuickItem to create a visual item, you will need to uncomment the
|
|
|
|
// following line and re-implement updatePaintNode()
|
|
|
|
|
|
|
|
// setFlag(ItemHasContents, true);
|
|
|
|
m_socket = QSharedPointer<QLocalSocket>(new QLocalSocket());
|
|
|
|
m_socket.data()->setServerName("ScreenPlay");
|
|
|
|
QObject::connect(m_socket.data(), &QLocalSocket::connected, this, &ScreenPlaySDK::connected);
|
|
|
|
QObject::connect(m_socket.data(), &QLocalSocket::disconnected, this, &ScreenPlaySDK::disconnected);
|
|
|
|
QObject::connect(m_socket.data(), &QLocalSocket::bytesWritten, this, &ScreenPlaySDK::bytesWritten);
|
|
|
|
QObject::connect(m_socket.data(), &QLocalSocket::readyRead, this, &ScreenPlaySDK::readyRead);
|
|
|
|
QObject::connect(m_socket.data(), QOverload<QLocalSocket::LocalSocketError>::of(&QLocalSocket::error), this, &ScreenPlaySDK::error);
|
|
|
|
m_socket.data()->connectToServer();
|
|
|
|
}
|
|
|
|
|
|
|
|
ScreenPlaySDK::~ScreenPlaySDK()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScreenPlaySDK::connected()
|
|
|
|
{
|
|
|
|
setIsConnected(true);
|
|
|
|
emit sdkConnected();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScreenPlaySDK::disconnected()
|
|
|
|
{
|
|
|
|
setIsConnected(false);
|
|
|
|
emit sdkDisconnected();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScreenPlaySDK::bytesWritten(qint64 bytes)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScreenPlaySDK::readyRead()
|
|
|
|
{
|
|
|
|
QString tmp = m_socket.data()->readAll();
|
|
|
|
QJsonParseError err;
|
2018-03-12 16:20:48 +01:00
|
|
|
auto doc = QJsonDocument::fromJson(QByteArray::fromStdString(tmp.toStdString()),&err);
|
2018-02-12 15:35:08 +01:00
|
|
|
|
|
|
|
if (!(err.error == QJsonParseError::NoError)) {
|
2018-03-12 16:20:48 +01:00
|
|
|
emit incommingMessageError(err.errorString());
|
2018-02-12 15:35:08 +01:00
|
|
|
return;
|
|
|
|
}
|
2018-03-12 16:20:48 +01:00
|
|
|
QJsonObject ob = doc.object();
|
|
|
|
QJsonObject::iterator iterator;
|
|
|
|
for (iterator = ob.begin(); iterator != ob.end(); iterator++) {
|
|
|
|
qDebug() << iterator.key() << ob.value(iterator.key()).toString();
|
|
|
|
emit incommingMessage(iterator.key(), ob.value(iterator.key()).toString());
|
|
|
|
}
|
2018-02-12 15:35:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScreenPlaySDK::error(QLocalSocket::LocalSocketError socketError)
|
|
|
|
{
|
|
|
|
emit sdkSocketError("Error");
|
|
|
|
|
|
|
|
if(socketError == QLocalSocket::LocalSocketError::ConnectionRefusedError){
|
|
|
|
//QCoreApplication::quit();
|
|
|
|
}
|
|
|
|
}
|