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
63 changes: 48 additions & 15 deletions nodes/pubnub-node-red.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
<label for="node-input-channel"><i class="fa fa-tasks"></i> Channel</label>
<input type="text" id="node-input-channel" placeholder="node-red">
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name">
</div>
<div class="form-tips">You may listen to a list of comma-separated channels - ch1,ch2,etc.</div>
</script>

Expand All @@ -20,19 +24,20 @@
<script type="text/javascript">
RED.nodes.registerType('pubnub in',{
category: 'input',
color:"Silver",
color:"#19a2c6",
inputs:0,
outputs:1,
icon: "pnTiny.png",
label: function() {
return this.channel||"pubnub";
return this.name ||"pubnub";
},
labelStyle: function() {
return this.channel?"node_label_italic":"";
},
defaults: {
keys: {type:"pubnub-keys",required:true},
channel: {value:"node-red",required:true}
channel: {value:"node-red",required:true},
name: {value:""}
}
});
</script>
Expand All @@ -47,6 +52,10 @@
<label for="node-input-channel"><i class="fa fa-tasks"></i> Channel</label>
<input type="text" id="node-input-channel" placeholder="node-red">
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name">
</div>
</script>

<script type="text/x-red" data-help-name="pubnub out">
Expand All @@ -57,45 +66,69 @@
<script type="text/javascript">
RED.nodes.registerType('pubnub out',{
category: 'output',
color:"Silver",
color:"#19a2c6",
inputs:1,
outputs:0,
icon: "pnTiny.png",
align: "right",
label: function() {
return this.channel||"pubnub";
return this.name ||"pubnub";
},
labelStyle: function() {
return this.channel?"node_label_italic":"";
},
defaults: {
keys: {type:"pubnub-keys",required:true},
channel: {value:"node-red",required:true}
channel: {value:"node-red",required:true},
name: {value:""}
}
});
</script>


<script type="text/x-red" data-template-name="pubnub-keys">
<div class="form-row">
<label for="node-config-input-pub_key"><i class="fa fa-tag"></i> Publish Key</label>
<input type="text" id="node-config-input-pub_key">
<label for="node-config-input-publish_key"><i class="fa fa-tag"></i> Publish Key</label>
<input type="text" id="node-config-input-publish_key">
</div>
<div class="form-row">
<label for="node-config-input-subscribe_key"><i class="fa fa-tag"></i> Subscribe Key</label>
<input type="text" id="node-config-input-subscribe_key">
</div>
<div class="form-row">
<label for="node-config-input-auth_key"><i class="fa fa-tag"></i> Auth Key</label>
<input type="password" id="node-config-input-auth_key">
</div>
<div class="form-row">
<label for="node-config-input-sub_key"><i class="fa fa-tag"></i> Subscribe Key</label>
<input type="text" id="node-config-input-sub_key">
<label for="node-config-input-cipher_key"><i class="fa fa-tag"></i> Cipher Key</label>
<input type="password" id="node-config-input-cipher_key">
</div>
<div class="form-row">
<label><i class="fa fa-lock"></i>&nbsp;</label>
<input type="checkbox" id="node-config-input-ssl" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-config-input-ssl">SSL</label>
</div>
<div class="form-row">
<label for="node-config-input-uuid"><i class="fa fa-user"></i> UUID</label>
<input type="text" id="node-config-input-uuid">
</div>
</script>

<script type="text/javascript">
RED.nodes.registerType('pubnub-keys',{
category: 'config',
defaults: {
pub_key: {value:"demo",required:true},
sub_key: {value:"demo",required:true}
defaults: { },
credentials: {
publish_key: {value:"demo",required:true},
subscribe_key: {value:"demo",required:true},
auth_key: {value:"demo"},
cipher_key: {value:"demo"},
ssl: {value:true},
uuid: {value:null},
},
label: function() {
return this.pub_key+"/"+this.sub_key;
}
return "PubNub"; //this.credentials.publish_key+"/"+this.credentials.subscribe_key;
},
exportable: false
});
</script>
25 changes: 19 additions & 6 deletions nodes/pubnub-node-red.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@ module.exports = function(RED) {
// This is a config node holding the keys for connecting to PubNub
function PubnubKeysNode(n) {
RED.nodes.createNode(this,n);
this.publish_key = n.pub_key;
this.subscribe_key = n.sub_key;
}
RED.nodes.registerType("pubnub-keys",PubnubKeysNode);
RED.nodes.registerType("pubnub-keys",PubnubKeysNode,{
credentials: {
publish_key: { type:"text" },
subscribe_key: { type:"text" },
auth_key: { type:"password" },
cipher_key: { type:"password" },
ssl: { type:"bool" },
uuid : { type:"text" }
}
});


//
Expand All @@ -18,6 +25,8 @@ module.exports = function(RED) {
RED.nodes.createNode(this,n);
this.channel = n.channel;
this.keys = n.keys;


this.keysConfig = RED.nodes.getNode(this.keys);

// Establish a new connection
Expand Down Expand Up @@ -114,13 +123,17 @@ module.exports = function(RED) {
//
function PNInit(node) {
node.status({fill:"red",shape:"ring",text:"disconnected"});
var keys = node.keysConfig;
var keys = node.keysConfig.credentials;
if (keys) {
node.log("Connecting to PubNub (" +
keys.publish_key + ":" + keys.subscribe_key+")");
node.pn_obj = PN.init({
node.pn_obj = PN({
publish_key : keys.publish_key,
subscribe_key : keys.subscribe_key
subscribe_key : keys.subscribe_key,
auth_key : keys.auth_key,
cipher_key : keys.cipher_key,
ssl : keys.ssl,
uuid : keys.uuid
});
node.status({fill:"yellow",shape:"dot",text:"connected"});
}
Expand Down