Skip to content

Commit

Permalink
update pusher nodes to later api
Browse files Browse the repository at this point in the history
to close #347 and close #348
  • Loading branch information
Dave Conway-Jones committed Aug 27, 2017
1 parent 5ac15e6 commit 2413738
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 27 deletions.
6 changes: 3 additions & 3 deletions social/pusher/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"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",
"dependencies" : {
"pusher": "1.0.5",
"pusher-client": "0.2.3"
"pusher": "^1.5.1",
"pusher-client": "^1.1.0"
},
"repository" : {
"type":"git",
Expand Down
34 changes: 27 additions & 7 deletions social/pusher/pusher.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,17 @@
<input type="text" id="node-input-eventname" placeholder="test_event_name">
</div>
<div class="form-row">
<label for="node-input-appkey_sub"><i class="fa fa-lock"></i> App Key</label>
<input type="text" id="node-input-pusherappkey_sub" placeholder="key">
<label for="node-input-pusherappkeysub"><i class="fa fa-lock"></i> App Key</label>
<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 class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
Expand All @@ -30,10 +39,11 @@
defaults: {
name: {value:""},
channel: {value:"", required:true},
cluster: {value:"mt1"},
eventname: {value:"", required:true}
},
credentials: {
pusherappkey_sub: "text"
pusherappkeysub: {type:"text"}
},
inputs:0,
outputs:1,
Expand All @@ -60,27 +70,36 @@
</div>

<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">
</div>

<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">
</div>

<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">
</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">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
</script>


<script type="text/x-red" data-help-name="pusher out">
<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>
Expand All @@ -95,6 +114,7 @@
defaults: {
name: {value:""},
channel: {value:"", required:true},
cluster: {value:"mt1"},
eventname: {value:""}
},
credentials: {
Expand Down
37 changes: 20 additions & 17 deletions social/pusher/pusher.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,36 @@ module.exports = function(RED) {

//node for subscribing to an event/channel
function PusherNode(n) {
// Create a RED node
RED.nodes.createNode(this,n);

this.channel = n.channel;
this.eventname = n.eventname;
this.cluster = n.cluster || "mt1";
var node = this;
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"); }

//get parameters from user
this.channel = n.channel;
this.eventname = n.eventname;

//create a subscription to the channel and event defined by user
var socket = new PusherClient(''+this.appkey);
node.channel = socket.subscribe(''+this.channel);
socket.bind(''+this.eventname,
var socket = new PusherClient(''+node.appkey, {cluster:node.cluster, encrypted:true});
var chan = socket.subscribe(''+node.channel);
chan.bind(''+node.eventname,
function(data) {
var msg = {topic:this.eventname};
var msg = {topic:node.eventname, channel:node.channel};
if (data.hasOwnProperty("payload")) { msg.payload = data.payload; }
else { msg.payload = data; }
node.send(msg);
}
);

this.on("close", function() {
node.on("close", function() {
socket.disconnect();
});
}


//Node for sending Pusher events
function PusherNodeSend(n) {
// Create a RED node
Expand All @@ -54,15 +54,17 @@ module.exports = function(RED) {
//get parameters from user
this.channel = n.channel;
this.eventname = n.eventname;
this.cluster = n.cluster || "mt1";

var pusher = new Pusher({
var pusherd = new Pusher({
appId: this.appid,
key: this.appkey,
secret: this.appsecret
secret: this.appsecret,
cluster: this.cluster
});

node.on("input", function(msg) {
pusher.trigger(this.channel, this.eventname, {
pusherd.trigger(this.channel, this.eventname, {
"payload": msg.payload
});
});
Expand All @@ -73,14 +75,15 @@ module.exports = function(RED) {

RED.nodes.registerType("pusher in",PusherNode,{
credentials: {
pusherappkey_sub: "text"
pusherappkeysub: "text"
}
});
RED.nodes.registerType("pusher out",PusherNodeSend,{
credentials: {
pusherappid: {type:"text"},
pusherappkey: {type:"text"},
pusherappsecret: {type:"password"}
}
},
encrypted: true
});
}

1 comment on commit 2413738

@andersea
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit closes #189.

Please sign in to comment.