summaryrefslogtreecommitdiff
path: root/src/webchannel/qwebchannel.cpp
diff options
context:
space:
mode:
authorMilian Wolff <milian.wolff@kdab.com>2014-02-05 17:44:03 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-03-21 15:59:25 +0100
commit48e814442e6e8507aacd16362b44d5754c059228 (patch)
tree592f3916bf2e5dc18d57a62c3baf1ba0ae2bbf09 /src/webchannel/qwebchannel.cpp
parente3e4d6a18d63537459f0e616360e53e816927f76 (diff)
downloadqtwebchannel-48e814442e6e8507aacd16362b44d5754c059228.tar.gz
Send response data only to target client.
Before, the response was sent to all clients in a broad-cast and had to be filtered on the client-side. This required additional client identification data to be added to all requests and responses. Now, we keep track of the transport and transport-internal client and only send the response to that client. This is very benefitial for multi-client setups but also reduces traffic for single-client setups and thus their performance. Change-Id: Ia1ef5e031b0058222083d352a8aa28a7d566a6ca Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/webchannel/qwebchannel.cpp')
-rw-r--r--src/webchannel/qwebchannel.cpp28
1 files changed, 11 insertions, 17 deletions
diff --git a/src/webchannel/qwebchannel.cpp b/src/webchannel/qwebchannel.cpp
index 5e8e320..75d1a4b 100644
--- a/src/webchannel/qwebchannel.cpp
+++ b/src/webchannel/qwebchannel.cpp
@@ -50,13 +50,8 @@
QT_BEGIN_NAMESPACE
-void QWebChannelPrivate::sendJSONMessage(const QJsonValue &id, const QJsonValue &data, bool response) const
+QByteArray generateJSONMessage(const QJsonValue &id, const QJsonValue &data, bool response)
{
- if (transports.isEmpty()) {
- qWarning("QWebChannel is not connected to any transports, cannot send messages.");
- return;
- }
-
QJsonObject obj;
if (response) {
obj[QStringLiteral("response")] = true;
@@ -66,11 +61,7 @@ void QWebChannelPrivate::sendJSONMessage(const QJsonValue &id, const QJsonValue
obj[QStringLiteral("data")] = data;
}
QJsonDocument doc(obj);
- const QByteArray &message = doc.toJson(QJsonDocument::Compact);
-
- foreach (QWebChannelTransportInterface *transport, transports) {
- transport->sendMessage(message);
- }
+ return doc.toJson(QJsonDocument::Compact);
}
QWebChannel::QWebChannel(QObject *parent)
@@ -136,14 +127,17 @@ void QWebChannel::disconnectFrom(QWebChannelTransportInterface *transport)
}
}
-void QWebChannel::respond(const QJsonValue &messageId, const QJsonValue &data) const
-{
- d->sendJSONMessage(messageId, data, true);
-}
-
void QWebChannel::sendMessage(const QJsonValue &id, const QJsonValue &data) const
{
- d->sendJSONMessage(id, data, false);
+ if (d->transports.isEmpty()) {
+ qWarning("QWebChannel is not connected to any transports, cannot send messages.");
+ return;
+ }
+
+ const QByteArray &message = generateJSONMessage(id, data, false);
+ foreach (QWebChannelTransportInterface *transport, d->transports) {
+ transport->sendMessage(message);
+ }
}
QT_END_NAMESPACE