From 34413af4340b7cf60145b34430a528228fc73bbd Mon Sep 17 00:00:00 2001 From: Shane Ballman Date: Tue, 10 Oct 2017 13:43:27 -0400 Subject: [PATCH 1/2] Enables a dynamic msg.channel for the publish function --- nodes/pubnub-node-red.html | 2 ++ nodes/pubnub-node-red.js | 30 +++++++++++++++--------------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/nodes/pubnub-node-red.html b/nodes/pubnub-node-red.html index 07e896e..5e19be3 100755 --- a/nodes/pubnub-node-red.html +++ b/nodes/pubnub-node-red.html @@ -80,6 +80,8 @@ diff --git a/nodes/pubnub-node-red.js b/nodes/pubnub-node-red.js index f7f79a1..692b152 100755 --- a/nodes/pubnub-node-red.js +++ b/nodes/pubnub-node-red.js @@ -117,24 +117,24 @@ module.exports = function (RED) { // Publish to a channel if (this.pn_obj != null) { - if (this.channel) { node = this; this.on('input', function (msg) { - this.log('Publishing to channel ' + node.channel); - - node.pn_obj.publish({ channel: node.channel, message: msg.payload }, function (status, response) { - if (status.error) { - node.log('Failure sending message ' + msg.payload + ' ' + JSON.stringify(status, null, '\t') + 'Please retry publish!'); - } else { - node.log('Success sending message ' + msg.payload + ' ' + JSON.stringify(response, null, '\t')); - } - }); + var _channel = (msg.channel) ? msg.channel : node.channel; + if (_channel) { + this.log('Publishing to channel ' + _channel); + node.pn_obj.publish({ channel: _channel, message: msg.payload }, function (status, response) { + if (status.error) { + node.warn('Failure sending message ' + msg.payload + ' ' + JSON.stringify(status, null, '\t') + 'Please retry publish!'); + } else { + node.log('Success sending message ' + msg.payload + ' ' + JSON.stringify(response, null, '\t')); + } + }); + this.status({ fill: 'green', shape: 'dot', text: 'published' }); + } else { + this.warn('Unknown channel name!'); + this.status({ fill: 'green', shape: 'ring', text: 'channel?' }); + } }); - this.status({ fill: 'green', shape: 'dot', text: 'published' }); - } else { - this.warn('Unknown channel name!'); - this.status({ fill: 'green', shape: 'ring', text: 'channel?' }); - } } // Destroy on node close event From 74e73ddffb421a09b1cd004416812626a6e5d7f9 Mon Sep 17 00:00:00 2001 From: Shane Ballman Date: Tue, 10 Oct 2017 14:08:00 -0400 Subject: [PATCH 2/2] Making Travis-CI happy --- nodes/pubnub-node-red.js | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/nodes/pubnub-node-red.js b/nodes/pubnub-node-red.js index 692b152..9f7a29e 100755 --- a/nodes/pubnub-node-red.js +++ b/nodes/pubnub-node-red.js @@ -117,24 +117,24 @@ module.exports = function (RED) { // Publish to a channel if (this.pn_obj != null) { - node = this; - this.on('input', function (msg) { - var _channel = (msg.channel) ? msg.channel : node.channel; - if (_channel) { - this.log('Publishing to channel ' + _channel); - node.pn_obj.publish({ channel: _channel, message: msg.payload }, function (status, response) { - if (status.error) { - node.warn('Failure sending message ' + msg.payload + ' ' + JSON.stringify(status, null, '\t') + 'Please retry publish!'); - } else { - node.log('Success sending message ' + msg.payload + ' ' + JSON.stringify(response, null, '\t')); - } - }); - this.status({ fill: 'green', shape: 'dot', text: 'published' }); - } else { - this.warn('Unknown channel name!'); - this.status({ fill: 'green', shape: 'ring', text: 'channel?' }); - } - }); + node = this; + this.on('input', function (msg) { + var outChannel = (msg.channel) ? msg.channel : node.channel; + if (outChannel) { + this.log('Publishing to channel ' + outChannel); + node.pn_obj.publish({ channel: outChannel, message: msg.payload }, function (status, response) { + if (status.error) { + node.warn('Failure sending message ' + msg.payload + ' ' + JSON.stringify(status, null, '\t') + 'Please retry publish!'); + } else { + node.log('Success sending message ' + msg.payload + ' ' + JSON.stringify(response, null, '\t')); + } + }); + this.status({ fill: 'green', shape: 'dot', text: 'published' }); + } else { + this.warn('Unknown channel name!'); + this.status({ fill: 'green', shape: 'ring', text: 'channel?' }); + } + }); } // Destroy on node close event