diff options
author | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2019-11-23 03:02:50 +0100 |
---|---|---|
committer | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2019-11-23 03:02:50 +0100 |
commit | 38504478508ae4297fc6ab14e3643d3cfbe19a99 (patch) | |
tree | 19c49c4583a6d0d7a30d0fbf73d3227201673a63 | |
parent | 7db2967fb0ea643d9defda4fd67dbe9969ee7d5e (diff) | |
parent | b2685b64d1f2fef2ef1f3f3542379fb8f052d113 (diff) | |
download | qtwebchannel-38504478508ae4297fc6ab14e3643d3cfbe19a99.tar.gz |
Merge remote-tracking branch 'origin/5.14' into 5.15
Change-Id: Iea2856ddca7885742d2f52352ecf9d996937b35f
-rw-r--r-- | examples/webchannel/nodejs/chatclient.js | 4 | ||||
-rwxr-xr-x | examples/webchannel/qwclient/qwclient.js | 18 | ||||
-rw-r--r-- | examples/webchannel/shared/qwebchannel.js | 42 |
3 files changed, 29 insertions, 35 deletions
diff --git a/examples/webchannel/nodejs/chatclient.js b/examples/webchannel/nodejs/chatclient.js index 76b620c..6d231a2 100644 --- a/examples/webchannel/nodejs/chatclient.js +++ b/examples/webchannel/nodejs/chatclient.js @@ -85,7 +85,7 @@ var createWebChannel = function(transport, rlif) { // i.e. the server wants to 'send text'. // This can be confusing, as we connect to the signal // to receive incoming messages on our side - channel.objects.dialog.sendText.connect(function(message) { + channel.objects.core.sendText.connect(function(message) { process.stdout.cursorTo(0); process.stdout.clearLine(0); console.log(' << ' + message); @@ -107,7 +107,7 @@ var createWebChannel = function(transport, rlif) { // is called with our message. // Again the naming is for the server side, // i.e. the slot is used _by the server_ to receive text. - channel.objects.dialog.receiveText(l); + channel.objects.core.receiveText(l); console.log(' >> ' + l); } rlif.prompt(); diff --git a/examples/webchannel/qwclient/qwclient.js b/examples/webchannel/qwclient/qwclient.js index 0b0909f..cd277f1 100755 --- a/examples/webchannel/qwclient/qwclient.js +++ b/examples/webchannel/qwclient/qwclient.js @@ -114,7 +114,8 @@ var setupRepl = function() { var r = repl.start({ prompt: "webchannel> ", input: process.stdin, - output: process.stdout + output: process.stdout, + ignoreUndefined: true }); r.context.serverAddress = serverAddress; @@ -122,10 +123,15 @@ var setupRepl = function() { r.context.channels = channels; r.context.lsObjects = function() { - channels.forEach(function(channel) { - console.log('Channel ' + channel); - Object.keys(channel.objects); - }); + for (let i = 0; i < channels.length; ++i) { + const channel = channels[i]; + if (!channel) // closed and removed channel in repl + continue; + + console.log('-- Channel "c' + i + '" objects:'); + for (const obj of Object.keys(channel.objects)) + console.log(obj, ':', channel.objects[obj]); + } } return r; } @@ -135,7 +141,7 @@ var welcome = function() { console.log('Use openChannel(url) to connect to a service.'); console.log('For the standalone example, just openChannel() should suffice.'); console.log('Opened channels have their objects aliased to c<channel number>, i.e. c0'); - console.log('So for the standalone example try: c0.dialog.receiveText(\'hello world\')'); + console.log('So for the standalone example try: c0.core.receiveText(\'hello world\')'); } welcome(); diff --git a/examples/webchannel/shared/qwebchannel.js b/examples/webchannel/shared/qwebchannel.js index fca45d9..32ad51e 100644 --- a/examples/webchannel/shared/qwebchannel.js +++ b/examples/webchannel/shared/qwebchannel.js @@ -140,15 +140,14 @@ var QWebChannel = function(transport, initCallback) this.handlePropertyUpdate = function(message) { - for (var i in message.data) { - var data = message.data[i]; + message.data.forEach(data => { var object = channel.objects[data.object]; if (object) { object.propertyUpdate(data.signals, data.properties); } else { console.warn("Unhandled property update: " + data.object + "::" + data.signal); } - } + }); channel.exec({type: QWebChannelMessageTypes.idle}); } @@ -158,13 +157,15 @@ var QWebChannel = function(transport, initCallback) }; channel.exec({type: QWebChannelMessageTypes.init}, function(data) { - for (var objectName in data) { - var object = new QObject(objectName, data[objectName], channel); + for (const objectName of Object.keys(data)) { + new QObject(objectName, data[objectName], channel); } + // now unwrap properties, which might reference other registered objects - for (var objectName in channel.objects) { + for (const objectName of Object.keys(channel.objects)) { channel.objects[objectName].unwrapProperties(); } + if (initCallback) { initCallback(channel); } @@ -191,19 +192,14 @@ function QObject(name, data, webChannel) { if (response instanceof Array) { // support list of objects - var ret = new Array(response.length); - for (var i = 0; i < response.length; ++i) { - ret[i] = object.unwrapQObject(response[i]); - } - return ret; + return response.map(qobj => object.unwrapQObject(qobj)) } if (!(response instanceof Object)) return response; - if (!response["__QObject*__"] - || response.id === undefined) { + if (!response["__QObject*__"] || response.id === undefined) { var jObj = {}; - for (var propName in response) { + for (const propName of Object.keys(response)) { jObj[propName] = object.unwrapQObject(response[propName]); } return jObj; @@ -226,13 +222,7 @@ function QObject(name, data, webChannel) // just assigning {} though would not have the desired effect, but the // below also ensures all external references will see the empty map // NOTE: this detour is necessary to workaround QTBUG-40021 - var propertyNames = []; - for (var propertyName in qObject) { - propertyNames.push(propertyName); - } - for (var idx in propertyNames) { - delete qObject[propertyNames[idx]]; - } + Object.keys(qObject).forEach(name => delete qObject[name]); } }); // here we are already initialized, and thus must directly unwrap the properties @@ -242,7 +232,7 @@ function QObject(name, data, webChannel) this.unwrapProperties = function() { - for (var propertyIdx in object.__propertyCache__) { + for (const propertyIdx of Object.keys(object.__propertyCache__)) { object.__propertyCache__[propertyIdx] = object.unwrapQObject(object.__propertyCache__[propertyIdx]); } } @@ -318,12 +308,12 @@ function QObject(name, data, webChannel) this.propertyUpdate = function(signals, propertyMap) { // update property cache - for (var propertyIndex in propertyMap) { + for (const propertyIndex of Object.keys(propertyMap)) { var propertyValue = propertyMap[propertyIndex]; object.__propertyCache__[propertyIndex] = this.unwrapQObject(propertyValue); } - for (var signalName in signals) { + for (const signalName of Object.keys(signals)) { // Invoke all callbacks, as signalEmitted() does not. This ensures the // property cache is updated before the callbacks are invoked. invokeSignalCallbacks(signalName, signals[signalName]); @@ -447,9 +437,7 @@ function QObject(name, data, webChannel) data.signals.forEach(function(signal) { addSignal(signal, false); }); - for (var name in data.enums) { - object[name] = data.enums[name]; - } + Object.assign(object, data.enums); } //required for use with nodejs |