diff options
author | Milian Wolff <milian.wolff@kdab.com> | 2014-07-10 00:05:28 +0200 |
---|---|---|
committer | Milian Wolff <milian.wolff@kdab.com> | 2014-07-29 13:58:04 +0200 |
commit | 94912cf26ba70a2cadd23f1c931395be64c11eac (patch) | |
tree | 28cfa1d98bbcc7eeccba6de1e3317e30add56a2f /tests/auto/qml/testtransport.cpp | |
parent | 77a4c34bb0f3b8cc3107f9fc6be0f5f7b23bb9d6 (diff) | |
download | qtwebchannel-94912cf26ba70a2cadd23f1c931395be64c11eac.tar.gz |
Refactor and streamline API and IPC protocol.
This patch removes the obsolete API support to send raw messages using
a QWebChannel. Instead, it is encouraged to directly use WebSockets or
navigator.qt.
By doing so, we can cleanup the code considerably. While at it, the
transport API is adapted to work on QJsonObject messages, instead of
QStrings. This will allow us to use more efficient formats in e.g.
QtWebKit or QtWebEngine. One could also implement a JSONRPC interface
using a custom transport then.
Change-Id: Ia8c125a5558507b3cbecf128a46b19fdb013f47b
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@digia.com>
Diffstat (limited to 'tests/auto/qml/testtransport.cpp')
-rw-r--r-- | tests/auto/qml/testtransport.cpp | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/tests/auto/qml/testtransport.cpp b/tests/auto/qml/testtransport.cpp index a332955..d73a4b8 100644 --- a/tests/auto/qml/testtransport.cpp +++ b/tests/auto/qml/testtransport.cpp @@ -41,6 +41,10 @@ #include "testtransport.h" +#include <QDebug> +#include <QJsonDocument> +#include <QJsonObject> + QT_BEGIN_NAMESPACE TestTransport::TestTransport(QObject *parent) @@ -49,9 +53,25 @@ TestTransport::TestTransport(QObject *parent) } -void TestTransport::sendTextMessage(const QString &message) +void TestTransport::sendMessage(const QJsonObject &message) +{ + emit sendMessageRequested(message); +} + +void TestTransport::receiveMessage(const QString &message) { - emit sendTextMessageRequested(message); + QJsonParseError error; + QJsonDocument doc = QJsonDocument::fromJson(message.toUtf8(), &error); + if (error.error) { + qWarning("Failed to parse JSON message: %s\nError is: %s", + qPrintable(message), qPrintable(error.errorString())); + return; + } else if (!doc.isObject()) { + qWarning("Received JSON message that is not an object: %s", + qPrintable(message)); + return; + } + emit messageReceived(doc.object(), this); } QT_END_NAMESPACE |