diff options
author | Milian Wolff <milian.wolff@kdab.com> | 2014-02-05 17:44:03 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-03-21 15:59:25 +0100 |
commit | 48e814442e6e8507aacd16362b44d5754c059228 (patch) | |
tree | 592f3916bf2e5dc18d57a62c3baf1ba0ae2bbf09 /src/webchannel/qwebchannel.js | |
parent | e3e4d6a18d63537459f0e616360e53e816927f76 (diff) | |
download | qtwebchannel-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.js')
-rw-r--r-- | src/webchannel/qwebchannel.js | 15 |
1 files changed, 3 insertions, 12 deletions
diff --git a/src/webchannel/qwebchannel.js b/src/webchannel/qwebchannel.js index 33f4cf5..9529c0b 100644 --- a/src/webchannel/qwebchannel.js +++ b/src/webchannel/qwebchannel.js @@ -57,13 +57,6 @@ var QWebChannelMessageTypes = { var QWebChannel = function(baseUrlOrSocket, initCallback, rawChannel) { var channel = this; - // support multiple channels listening to the same socket - // the responses to channel.exec must be distinguishable - // see: http://stackoverflow.com/a/2117523/35250 - this.id = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { - var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); - return v.toString(16); - }); this.send = function(data) { if (typeof(data) !== "string") { @@ -82,10 +75,8 @@ var QWebChannel = function(baseUrlOrSocket, initCallback, rawChannel) jsonData.data = {}; } if (jsonData.response) { - if (jsonData.id[0] === channel.id) { - channel.execCallbacks[jsonData.id[1]](jsonData.data); - delete channel.execCallbacks[jsonData.id]; - } + channel.execCallbacks[jsonData.id](jsonData.data); + delete channel.execCallbacks[jsonData.id]; } else if (channel.subscriptions[jsonData.id]) { channel.subscriptions[jsonData.id].forEach(function(callback) { (callback)(jsonData.data); } @@ -153,7 +144,7 @@ var QWebChannel = function(baseUrlOrSocket, initCallback, rawChannel) } var id = channel.execId++; channel.execCallbacks[id] = callback; - channel.send({"id": [channel.id, id], "data": data}); + channel.send({"id": id, "data": data}); }; this.objectMap = {}; |