1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00

update pusher nodes to later api

to close #347 and close #348
This commit is contained in:
Dave Conway-Jones 2017-08-27 14:00:20 +01:00
parent 5ac15e620a
commit 2413738082
No known key found for this signature in database
GPG Key ID: 81B04231572A9A2D
3 changed files with 50 additions and 27 deletions

View File

@ -1,10 +1,10 @@
{ {
"name" : "node-red-node-pusher", "name" : "node-red-node-pusher",
"version" : "0.0.6", "version" : "0.1.0",
"description" : "A Node-RED node to send and receive messages using Pusher.com", "description" : "A Node-RED node to send and receive messages using Pusher.com",
"dependencies" : { "dependencies" : {
"pusher": "1.0.5", "pusher": "^1.5.1",
"pusher-client": "0.2.3" "pusher-client": "^1.1.0"
}, },
"repository" : { "repository" : {
"type":"git", "type":"git",

View File

@ -9,8 +9,17 @@
<input type="text" id="node-input-eventname" placeholder="test_event_name"> <input type="text" id="node-input-eventname" placeholder="test_event_name">
</div> </div>
<div class="form-row"> <div class="form-row">
<label for="node-input-appkey_sub"><i class="fa fa-lock"></i> App Key</label> <label for="node-input-pusherappkeysub"><i class="fa fa-lock"></i> App Key</label>
<input type="text" id="node-input-pusherappkey_sub" placeholder="key"> <input type="text" id="node-input-pusherappkeysub" placeholder="key">
</div>
<div class="form-row">
<label for="node-input-cluster"><i class="fa fa-server"></i> Cluster</label>
<select type="text" id="node-input-cluster">
<option value="mt1">us-east-1 (US - default)</option>
<option value="eu">eu-west-1 (Europe)</option>
<option value="ap1">ap-southeast-1 (Singapore)</option>
<option value="ap2">ap-south-1 (Mumbai)</option>
</select>
</div> </div>
<div class="form-row"> <div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label> <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
@ -30,10 +39,11 @@
defaults: { defaults: {
name: {value:""}, name: {value:""},
channel: {value:"", required:true}, channel: {value:"", required:true},
cluster: {value:"mt1"},
eventname: {value:"", required:true} eventname: {value:"", required:true}
}, },
credentials: { credentials: {
pusherappkey_sub: "text" pusherappkeysub: {type:"text"}
}, },
inputs:0, inputs:0,
outputs:1, outputs:1,
@ -60,27 +70,36 @@
</div> </div>
<div class="form-row"> <div class="form-row">
<label for="node-input-appid"><i class="fa fa-tag"></i> App ID</label> <label for="node-input-pusherappid"><i class="fa fa-tag"></i> App ID</label>
<input type="text" id="node-input-pusherappid" placeholder="app_id"> <input type="text" id="node-input-pusherappid" placeholder="app_id">
</div> </div>
<div class="form-row"> <div class="form-row">
<label for="node-input-appkey"><i class="fa fa-lock"></i> App Key</label> <label for="node-input-pusherappkey"><i class="fa fa-lock"></i> App Key</label>
<input type="text" id="node-input-pusherappkey" placeholder="key"> <input type="text" id="node-input-pusherappkey" placeholder="key">
</div> </div>
<div class="form-row"> <div class="form-row">
<label for="node-input-topic"><i class="fa fa-asterisk"></i> App Secret</label> <label for="node-input-pusherappsecret"><i class="fa fa-asterisk"></i> App Secret</label>
<input type="password" id="node-input-pusherappsecret" placeholder="secret"> <input type="password" id="node-input-pusherappsecret" placeholder="secret">
</div> </div>
<div class="form-row">
<label for="node-input-cluster"><i class="fa fa-server"></i> Cluster</label>
<select type="text" id="node-input-cluster">
<option value="mt1">us-east-1 (US - default)</option>
<option value="eu">eu-west-1 (Europe)</option>
<option value="ap1">ap-southeast-1 (Singapore)</option>
<option value="ap2">ap-south-1 (Mumbai)</option>
</select>
</div>
<div class="form-row"> <div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label> <label for="node-input-name"><i class="fa fa-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>
<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.</p> <p>Pusher output node for sending messages to a specific channel/event.</p>
<p>You need an App key, secret and ID of a Pusher app.</p> <p>You need an App key, secret and ID of a Pusher app.</p>
@ -95,6 +114,7 @@
defaults: { defaults: {
name: {value:""}, name: {value:""},
channel: {value:"", required:true}, channel: {value:"", required:true},
cluster: {value:"mt1"},
eventname: {value:""} eventname: {value:""}
}, },
credentials: { credentials: {

View File

@ -6,36 +6,36 @@ module.exports = function(RED) {
//node for subscribing to an event/channel //node for subscribing to an event/channel
function PusherNode(n) { function PusherNode(n) {
// Create a RED node
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.channel = n.channel;
this.eventname = n.eventname;
this.cluster = n.cluster || "mt1";
var node = this; var node = this;
var credentials = this.credentials; var credentials = this.credentials;
if ((credentials) && (credentials.hasOwnProperty("pusherappkey_sub"))) { this.appkey = credentials.pusherappkey_sub; } if ((credentials) && (credentials.hasOwnProperty("pusherappkeysub"))) {
node.appkey = credentials.pusherappkeysub;
}
else { this.error("No Pusher app key set for input node"); } else { this.error("No Pusher app key set for input node"); }
//get parameters from user
this.channel = n.channel;
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(''+node.appkey, {cluster:node.cluster, encrypted:true});
node.channel = socket.subscribe(''+this.channel); var chan = socket.subscribe(''+node.channel);
socket.bind(''+this.eventname, chan.bind(''+node.eventname,
function(data) { function(data) {
var msg = {topic:this.eventname}; var msg = {topic:node.eventname, channel:node.channel};
if (data.hasOwnProperty("payload")) { msg.payload = data.payload; } if (data.hasOwnProperty("payload")) { msg.payload = data.payload; }
else { msg.payload = data; } else { msg.payload = data; }
node.send(msg); node.send(msg);
} }
); );
this.on("close", function() { node.on("close", function() {
socket.disconnect(); socket.disconnect();
}); });
} }
//Node for sending Pusher events //Node for sending Pusher events
function PusherNodeSend(n) { function PusherNodeSend(n) {
// Create a RED node // Create a RED node
@ -54,15 +54,17 @@ module.exports = function(RED) {
//get parameters from user //get parameters from user
this.channel = n.channel; this.channel = n.channel;
this.eventname = n.eventname; this.eventname = n.eventname;
this.cluster = n.cluster || "mt1";
var pusher = new Pusher({ var pusherd = new Pusher({
appId: this.appid, appId: this.appid,
key: this.appkey, key: this.appkey,
secret: this.appsecret secret: this.appsecret,
cluster: this.cluster
}); });
node.on("input", function(msg) { node.on("input", function(msg) {
pusher.trigger(this.channel, this.eventname, { pusherd.trigger(this.channel, this.eventname, {
"payload": msg.payload "payload": msg.payload
}); });
}); });
@ -73,7 +75,7 @@ module.exports = function(RED) {
RED.nodes.registerType("pusher in",PusherNode,{ RED.nodes.registerType("pusher in",PusherNode,{
credentials: { credentials: {
pusherappkey_sub: "text" pusherappkeysub: "text"
} }
}); });
RED.nodes.registerType("pusher out",PusherNodeSend,{ RED.nodes.registerType("pusher out",PusherNodeSend,{
@ -81,6 +83,7 @@ module.exports = function(RED) {
pusherappid: {type:"text"}, pusherappid: {type:"text"},
pusherappkey: {type:"text"}, pusherappkey: {type:"text"},
pusherappsecret: {type:"password"} pusherappsecret: {type:"password"}
} },
encrypted: true
}); });
} }