From 0a43a43a166d2e2b551f543de61090637bd8b387 Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Wed, 30 Jul 2014 12:20:08 +0200 Subject: Do not broadcast initialization data to all clients. Instead, send the data as a response to the initialization request message. This simplifies the code and makes it more predictable, as we do not spam all clients with initialization broadcasts anymore. Note that the pending initialization "feature" is removed, but I don't see a need for it anymore. If you want to delay client initialization, do it on the client side. Change-Id: I1ab71fd6c9e809ccb6085f1a3fbac3eb9b2e910b Reviewed-by: Jocelyn Turcotte --- src/webchannel/qwebchannel.js | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) (limited to 'src/webchannel/qwebchannel.js') diff --git a/src/webchannel/qwebchannel.js b/src/webchannel/qwebchannel.js index d2c6525..13e9da5 100644 --- a/src/webchannel/qwebchannel.js +++ b/src/webchannel/qwebchannel.js @@ -82,9 +82,6 @@ var QWebChannel = function(transport, initCallback) case QWebChannelMessageTypes.propertyUpdate: channel.handlePropertyUpdate(data); break; - case QWebChannelMessageTypes.init: - channel.handleInit(data); - break; default: console.error("invalid message received:", message.data); break; @@ -149,30 +146,20 @@ var QWebChannel = function(transport, initCallback) channel.exec({type: QWebChannelMessageTypes.idle}); } - // prevent multiple initialization which might happen with multiple webchannel clients. - this.initialized = false; - this.handleInit = function(message) + this.debug = function(message) { - if (channel.initialized) { - return; - } - channel.initialized = true; - for (var objectName in message.data) { - var data = message.data[objectName]; - var object = new QObject(objectName, data, channel); + channel.send({type: QWebChannelMessageTypes.debug, data: message}); + }; + + channel.exec({type: QWebChannelMessageTypes.init}, function(data) { + for (var objectName in data) { + var object = new QObject(objectName, data[objectName], channel); } if (initCallback) { initCallback(channel); } channel.exec({type: QWebChannelMessageTypes.idle}); - } - - this.debug = function(message) - { - channel.send({type: QWebChannelMessageTypes.debug, data: message}); - }; - - channel.exec({type: QWebChannelMessageTypes.init}); + }); }; function QObject(name, data, webChannel) -- cgit v1.2.1