diff options
author | Liang Qi <liang.qi@qt.io> | 2017-09-20 11:38:57 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2017-09-20 11:38:57 +0200 |
commit | ba755c28ea0cd35cfa9d8c77ef7f2c61437ad25b (patch) | |
tree | 3379cee43d6acae95312e51e6cd05c3c4198a95e /examples/webchannel/qwclient/qwclient.js | |
parent | 749951c19cbb7d301bed20f24d16dd4e713485c2 (diff) | |
parent | d84318e98aa3cbac11b4f95b3581e95aab96a34a (diff) | |
download | qtwebchannel-ba755c28ea0cd35cfa9d8c77ef7f2c61437ad25b.tar.gz |
Merge remote-tracking branch 'origin/5.9' into 5.10v5.10.0-beta3v5.10.0-beta2v5.10.0-beta1
Change-Id: I54f0bcd46ffb496156e46d723275cdd29601e45c
Diffstat (limited to 'examples/webchannel/qwclient/qwclient.js')
-rwxr-xr-x | examples/webchannel/qwclient/qwclient.js | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/examples/webchannel/qwclient/qwclient.js b/examples/webchannel/qwclient/qwclient.js index 0e28328..0b0909f 100755 --- a/examples/webchannel/qwclient/qwclient.js +++ b/examples/webchannel/qwclient/qwclient.js @@ -49,6 +49,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + 'use strict'; var repl = require('repl'); var WebSocket = require('faye-websocket').Client; @@ -62,7 +63,7 @@ if (autoConnect === __filename) { autoConnect = false; } -var openChannel = function (address) { +var openChannel = function(address) { // this should be bound to the repl var self = this; address = address ? address : serverAddress; @@ -72,25 +73,27 @@ var openChannel = function (address) { var ws = new WebSocket(address); - ws.on('open', function (event) { + ws.on('open', function(event) { var transport = { - onmessage: function (data) {}, - send: function (data) { - ws.send(data, {binary: false}); - } + onmessage: function(data) {}, + send: function(data) { + ws.send(data, { + binary: false + }); + } }; - ws.on('message', function (event) { - transport.onmessage(event); + ws.on('message', function(event) { + transport.onmessage(event); }); // onmessage - var webChannel = new QWebChannel(transport, function (channel) { + var webChannel = new QWebChannel(transport, function(channel) { channels.push(channel); var channelIdx = (channels.length - 1); console.log('channel opened', channelIdx); // Create a nice alias to access this channels objects self.context['c' + channelIdx] = channel.objects; - ws.on('close', function () { + ws.on('close', function() { for (var i = 0; i < channels.length; ++i) { if (channels[i] === channel) { console.log('channel closed', i); @@ -102,7 +105,7 @@ var openChannel = function (address) { }); // new QWebChannel }); // onopen - ws.on('error', function (error) { + ws.on('error', function(error) { console.log('websocket error', error.message); }); }; // openChannel @@ -119,7 +122,7 @@ var setupRepl = function() { r.context.channels = channels; r.context.lsObjects = function() { - channels.forEach(function(channel){ + channels.forEach(function(channel) { console.log('Channel ' + channel); Object.keys(channel.objects); }); |