mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Quick tidy up of pusher node - remove final key from flow,
fix in/out order on palette.
This commit is contained in:
parent
6d7ecea8cd
commit
fe0222d498
@ -1,4 +1,5 @@
|
|||||||
<!--
|
<!--
|
||||||
|
|
||||||
Copyright 2014 Charalampos Doukas, @BuildingIoT
|
Copyright 2014 Charalampos Doukas, @BuildingIoT
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
@ -13,52 +14,47 @@
|
|||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
|
|
||||||
|
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<script type="text/x-red" data-template-name="pusher in">
|
<script type="text/x-red" data-template-name="pusher in">
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-topic"><i class="icon-tasks"></i>App Key:</label>
|
<label for="node-input-topic"><i class="icon-tasks"></i>App Key</label>
|
||||||
<input type="text" id="node-input-appkey_sub" placeholder="apikey">
|
<input type="text" id="node-input-appkey_sub" placeholder="apikey">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-topic"><i class="icon-tasks"></i>Channel:</label>
|
<label for="node-input-topic"><i class="icon-tasks"></i>Channel</label>
|
||||||
<input type="text" id="node-input-channel" placeholder="channel">
|
<input type="text" id="node-input-channel" placeholder="channel">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-topic"><i class="icon-tasks"></i>Even Name:</label>
|
<label for="node-input-topic"><i class="icon-tasks"></i>Event Name</label>
|
||||||
<input type="text" id="node-input-eventname" placeholder="eventname">
|
<input type="text" id="node-input-eventname" placeholder="eventname">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
||||||
<input type="text" id="node-input-name" placeholder="Name">
|
<input type="text" id="node-input-name" placeholder="Name">
|
||||||
</div>
|
</div>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- Next, some simple help text is provided for the node. -->
|
<!-- Next, some simple help text is provided for the node. -->
|
||||||
<script type="text/x-red" data-help-name="pusher in">
|
<script type="text/x-red" data-help-name="pusher in">
|
||||||
<p>Pusher input mode. Use this node to subscribe to a Pusher channel/event. You need a valid Pusher App key.</p>
|
<p>Pusher input mode. Use this node to subscribe to a Pusher channel/event. You need a valid Pusher App key.</p>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- Finally, the node type is registered along with all of its properties -->
|
<!-- Finally, the node type is registered along with all of its properties -->
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
RED.nodes.registerType('pusher in',{
|
RED.nodes.registerType('pusher in',{
|
||||||
category: 'social-output', // the palette category
|
category: 'social-input', // the palette category
|
||||||
color:"#A9D0F5",
|
color:"#A9D0F5",
|
||||||
defaults: { // defines the editable properties of the node
|
defaults: { // defines the editable properties of the node
|
||||||
name: {value:""}, // along with default values.
|
name: {value:""}, // along with default values.
|
||||||
channel: {value:"", required:true},
|
channel: {value:"", required:true},
|
||||||
eventname: {value:"", required:true}
|
eventname: {value:"", required:true}
|
||||||
},
|
},
|
||||||
inputs:0, // set the number of inputs - only 0 or 1
|
inputs:0, // set the number of inputs - only 0 or 1
|
||||||
outputs:1, // set the number of outputs - 0 to n
|
outputs:1, // set the number of outputs - 0 to n
|
||||||
icon: "pusher.png", // set the icon (held in public/icons)
|
icon: "pusher.png", // set the icon (held in public/icons)
|
||||||
label: function() { // sets the default label contents
|
label: function() { // sets the default label contents
|
||||||
return this.name||this.topic||"pusher";
|
return this.name||"pusher";
|
||||||
},
|
},
|
||||||
labelStyle: function() { // sets the class to apply to the label
|
labelStyle: function() { // sets the class to apply to the label
|
||||||
return this.name?"node_label_italic":"";
|
return this.name?"node_label_italic":"";
|
||||||
@ -67,8 +63,6 @@
|
|||||||
var credentials = {};
|
var credentials = {};
|
||||||
var newAppKey_sub = $('#node-input-appkey_sub').val();
|
var newAppKey_sub = $('#node-input-appkey_sub').val();
|
||||||
credentials.pusherappkey_sub = newAppKey_sub;
|
credentials.pusherappkey_sub = newAppKey_sub;
|
||||||
|
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: 'pusher/'+this.id,
|
url: 'pusher/'+this.id,
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
@ -119,35 +113,33 @@
|
|||||||
<input type="text" id="node-input-eventname" placeholder="eventname">
|
<input type="text" id="node-input-eventname" placeholder="eventname">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
||||||
<input type="text" id="node-input-name" placeholder="Name">
|
<input type="text" id="node-input-name" placeholder="Name">
|
||||||
</div>
|
</div>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- Next, some simple help text is provided for the node. -->
|
<!-- Next, some simple help text is provided for the node. -->
|
||||||
<script type="text/x-red" data-help-name="pusher out">
|
<script type="text/x-red" data-help-name="pusher out">
|
||||||
<p>Pusher output node for sending messages to a specific channel/event. You need an App key, secret and ID of a Pusher app. The node will send the payload of the incoming message.</p>
|
<p>Pusher output node for sending messages to a specific channel/event. You need an App key, secret and ID of a Pusher app. The node will send the payload of the incoming message.</p>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- Finally, the node type is registered along with all of its properties -->
|
<!-- Finally, the node type is registered along with all of its properties -->
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
RED.nodes.registerType('pusher out',{
|
RED.nodes.registerType('pusher out',{
|
||||||
category: 'social-input', // the palette category
|
category: 'social-output', // the palette category
|
||||||
color:"#A9D0F5",
|
color:"#A9D0F5",
|
||||||
defaults: { // defines the editable properties of the node
|
defaults: { // defines the editable properties of the node
|
||||||
name: {value:""}, // along with default values.
|
name: {value:""}, // along with default values.
|
||||||
channel: {value:"", required:true},
|
channel: {value:"", required:true},
|
||||||
eventname: {value:"", required:true},
|
eventname: {value:"", required:true}
|
||||||
appid: {value:"", required:true}
|
|
||||||
},
|
},
|
||||||
inputs:1, // set the number of inputs - only 0 or 1
|
inputs:1, // set the number of inputs - only 0 or 1
|
||||||
outputs:0, // set the number of outputs - 0 to n
|
outputs:0, // set the number of outputs - 0 to n
|
||||||
icon: "pusher.png", // set the icon (held in public/icons)
|
icon: "pusher.png", // set the icon (held in public/icons)
|
||||||
align: "right",
|
align: "right",
|
||||||
label: function() { // sets the default label contents
|
label: function() { // sets the default label contents
|
||||||
return this.name||this.topic||"pusher";
|
return this.name||"pusher";
|
||||||
},
|
},
|
||||||
labelStyle: function() { // sets the class to apply to the label
|
labelStyle: function() { // sets the class to apply to the label
|
||||||
return this.name?"node_label_italic":"";
|
return this.name?"node_label_italic":"";
|
||||||
@ -160,8 +152,6 @@
|
|||||||
credentials.pusherappid = newAppID;
|
credentials.pusherappid = newAppID;
|
||||||
credentials.pusherappkey = newAppKey;
|
credentials.pusherappkey = newAppKey;
|
||||||
credentials.pusherappsecret = newAppSecret;
|
credentials.pusherappsecret = newAppSecret;
|
||||||
|
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: 'pusher/'+this.id,
|
url: 'pusher/'+this.id,
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
@ -176,12 +166,10 @@
|
|||||||
}
|
}
|
||||||
if (data.pusherappkey) {
|
if (data.pusherappkey) {
|
||||||
$('#node-input-appkey').val(data.pusherappkey);
|
$('#node-input-appkey').val(data.pusherappkey);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.pusherappsecret) {
|
if (data.pusherappsecret) {
|
||||||
$('#node-input-appsecret').val(data.pusherappsecret);
|
$('#node-input-appsecret').val(data.pusherappsecret);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
ondelete: function() {
|
ondelete: function() {
|
||||||
|
@ -1,22 +1,22 @@
|
|||||||
/**
|
/**
|
||||||
* pusher_send.js
|
* pusher.js
|
||||||
* Subscription module for the Pusher service (www.pusher.com)
|
* Subscription module for the Pusher service (www.pusher.com)
|
||||||
* Requires 'pusher' module
|
* Requires 'pusher' and 'pusher-client' modules.
|
||||||
* Copyright 2014 Charalampos Doukas - @BuildingIoT
|
*
|
||||||
*
|
* Copyright 2014 Charalampos Doukas, @BuildingIoT
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
*
|
||||||
* you may not use this file except in compliance with the License.
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* You may obtain a copy of the License at
|
* you may not use this file except in compliance with the License.
|
||||||
*
|
* You may obtain a copy of the License at
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
*
|
||||||
*
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
*
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* See the License for the specific language governing permissions and
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* limitations under the License.
|
* See the License for the specific language governing permissions and
|
||||||
**/
|
* limitations under the License.
|
||||||
|
**/
|
||||||
|
|
||||||
var Pusher = require('pusher');
|
var Pusher = require('pusher');
|
||||||
var PusherClient = require('pusher-client');
|
var PusherClient = require('pusher-client');
|
||||||
@ -24,53 +24,6 @@ var PusherClient = require('pusher-client');
|
|||||||
// Require main module
|
// Require main module
|
||||||
var RED = require(process.env.NODE_RED_HOME+"/red/red");
|
var RED = require(process.env.NODE_RED_HOME+"/red/red");
|
||||||
|
|
||||||
|
|
||||||
// The main node definition - most things happen in here
|
|
||||||
//Node for sending Pusher events
|
|
||||||
function PusherNodeSend(n) {
|
|
||||||
// Create a RED node
|
|
||||||
RED.nodes.createNode(this,n);
|
|
||||||
|
|
||||||
var node = this;
|
|
||||||
|
|
||||||
var credentials = RED.nodes.getCredentials(n.id);
|
|
||||||
|
|
||||||
if ((credentials) && (credentials.hasOwnProperty("pusherappid"))) { this.appid = credentials.pusherappid; }
|
|
||||||
else { this.error("No Pusher api token set"); }
|
|
||||||
if ((credentials) && (credentials.hasOwnProperty("pusherappsecret"))) { this.appsecret = credentials.pusherappsecret; }
|
|
||||||
else { this.error("No Pusher user secret set"); }
|
|
||||||
|
|
||||||
if ((credentials) && (credentials.hasOwnProperty("pusherappkey"))) { this.appkey = credentials.pusherappkey; }
|
|
||||||
else { this.error("No Pusher user key set"); }
|
|
||||||
|
|
||||||
//get parameters from user
|
|
||||||
this.channel = n.channel;
|
|
||||||
this.eventname = n.eventname;
|
|
||||||
|
|
||||||
var pusher = new Pusher({
|
|
||||||
appId: this.appid,
|
|
||||||
key: this.appkey,
|
|
||||||
secret: this.appsecret
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
this.on("input", function(msg){
|
|
||||||
|
|
||||||
pusher.trigger(this.channel, this.eventname, {
|
|
||||||
"message": ""+msg.payload
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
this.on("close", function() {
|
|
||||||
// Called when the node is shutdown - eg on redeploy.
|
|
||||||
// Allows ports to be closed, connections dropped etc.
|
|
||||||
// eg: this.client.disconnect();
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//node for subscribing to an event/channel
|
//node for subscribing to an event/channel
|
||||||
function PusherNode(n) {
|
function PusherNode(n) {
|
||||||
// Create a RED node
|
// Create a RED node
|
||||||
@ -86,50 +39,69 @@ function PusherNodeSend(n) {
|
|||||||
this.channel = n.channel;
|
this.channel = n.channel;
|
||||||
this.eventname = n.eventname;
|
this.eventname = n.eventname;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//create a subscription to the channel and event defined by user
|
//create a subscription to the channel and event defined by user
|
||||||
var socket = new PusherClient(''+this.appkey);
|
var socket = new PusherClient(''+this.appkey);
|
||||||
var my_channel = socket.subscribe(''+this.channel);
|
var my_channel = socket.subscribe(''+this.channel);
|
||||||
socket.bind(''+this.eventname,
|
socket.bind(''+this.eventname,
|
||||||
function(data) {
|
function(data) {
|
||||||
|
|
||||||
var msg = {};
|
var msg = {};
|
||||||
msg.payload = data;
|
msg.payload = data;
|
||||||
node.send(msg);
|
node.send(msg);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
this.on("input", function(msg){
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
this.on("close", function() {
|
this.on("close", function() {
|
||||||
// Called when the node is shutdown - eg on redeploy.
|
|
||||||
// Allows ports to be closed, connections dropped etc.
|
|
||||||
// eg: this.client.disconnect();
|
|
||||||
socket.disconnect();
|
socket.disconnect();
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//Node for sending Pusher events
|
||||||
|
function PusherNodeSend(n) {
|
||||||
|
// Create a RED node
|
||||||
|
RED.nodes.createNode(this,n);
|
||||||
|
|
||||||
|
var node = this;
|
||||||
|
|
||||||
|
var credentials = RED.nodes.getCredentials(n.id);
|
||||||
|
|
||||||
|
if ((credentials) && (credentials.hasOwnProperty("pusherappid"))) { this.appid = credentials.pusherappid; }
|
||||||
|
else { this.error("No Pusher api token set"); }
|
||||||
|
if ((credentials) && (credentials.hasOwnProperty("pusherappsecret"))) { this.appsecret = credentials.pusherappsecret; }
|
||||||
|
else { this.error("No Pusher user secret set"); }
|
||||||
|
if ((credentials) && (credentials.hasOwnProperty("pusherappkey"))) { this.appkey = credentials.pusherappkey; }
|
||||||
|
else { this.error("No Pusher user key set"); }
|
||||||
|
|
||||||
|
//get parameters from user
|
||||||
|
this.channel = n.channel;
|
||||||
|
this.eventname = n.eventname;
|
||||||
|
|
||||||
|
var pusher = new Pusher({
|
||||||
|
appId: this.appid,
|
||||||
|
key: this.appkey,
|
||||||
|
secret: this.appsecret
|
||||||
|
});
|
||||||
|
|
||||||
|
this.on("input", function(msg){
|
||||||
|
pusher.trigger(this.channel, this.eventname, {
|
||||||
|
"message": ""+msg.payload
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
this.on("close", function() {
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
//debugging on the output:
|
//debugging on the output:
|
||||||
var displayResult = function(result) {
|
var displayResult = function(result) {
|
||||||
console.log(result);
|
node.log(result);
|
||||||
};
|
};
|
||||||
|
|
||||||
var displayError = function(err) {
|
var displayError = function(err) {
|
||||||
console.error(err);
|
node.log("Error: "+err);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Register the node by name. This must be called before overriding any of the
|
|
||||||
// Node functions.
|
|
||||||
RED.nodes.registerType("pusher out",PusherNodeSend);
|
|
||||||
RED.nodes.registerType("pusher in",PusherNode);
|
RED.nodes.registerType("pusher in",PusherNode);
|
||||||
|
RED.nodes.registerType("pusher out",PusherNodeSend);
|
||||||
|
|
||||||
var querystring = require('querystring');
|
var querystring = require('querystring');
|
||||||
|
|
||||||
@ -155,7 +127,7 @@ RED.httpAdmin.post('/pusher/:id',function(req,res) {
|
|||||||
req.on('end', function(){
|
req.on('end', function(){
|
||||||
var newCreds = querystring.parse(body);
|
var newCreds = querystring.parse(body);
|
||||||
var credentials = RED.nodes.getCredentials(req.params.id)||{};
|
var credentials = RED.nodes.getCredentials(req.params.id)||{};
|
||||||
|
|
||||||
if (newCreds.pusherappid == null || newCreds.pusherappid == "") {
|
if (newCreds.pusherappid == null || newCreds.pusherappid == "") {
|
||||||
delete credentials.pusherappid;
|
delete credentials.pusherappid;
|
||||||
} else {
|
} else {
|
||||||
@ -179,9 +151,7 @@ RED.httpAdmin.post('/pusher/:id',function(req,res) {
|
|||||||
credentials.pusherappkey_sub = newCreds.pusherappkey_sub||credentials.pusherappkey_sub;
|
credentials.pusherappkey_sub = newCreds.pusherappkey_sub||credentials.pusherappkey_sub;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
RED.nodes.addCredentials(req.params.id,credentials);
|
RED.nodes.addCredentials(req.params.id,credentials);
|
||||||
res.send(200);
|
res.send(200);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user