Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions nodes/pubnub-node-red.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@

<script type="text/x-red" data-help-name="pubnub out">
<p>Publishes <b>msg.payload</b> to the PubNub channel specified by the edit window.</p>
<p>Messages will publish whatever your default channel(s) are (as defined in the config),
or you can pass it a dynamic <code>msg.channel</code> to publish to instead.
<p>The <code>msg.payload</code> input may be a string or a JSON object</p>
</script>

Expand Down
26 changes: 13 additions & 13 deletions nodes/pubnub-node-red.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
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.log('Failure sending message ' + msg.payload + ' ' + JSON.stringify(status, null, '\t') + 'Please retry publish!');
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
Expand Down