mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
parent
5ac15e620a
commit
2413738082
@ -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",
|
||||
|
@ -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>
|
||||
@ -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,
|
||||
@ -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>
|
||||
@ -95,6 +114,7 @@
|
||||
defaults: {
|
||||
name: {value:""},
|
||||
channel: {value:"", required:true},
|
||||
cluster: {value:"mt1"},
|
||||
eventname: {value:""}
|
||||
},
|
||||
credentials: {
|
||||
|
@ -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
|
||||
@ -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
|
||||
});
|
||||
});
|
||||
@ -73,7 +75,7 @@ module.exports = function(RED) {
|
||||
|
||||
RED.nodes.registerType("pusher in",PusherNode,{
|
||||
credentials: {
|
||||
pusherappkey_sub: "text"
|
||||
pusherappkeysub: "text"
|
||||
}
|
||||
});
|
||||
RED.nodes.registerType("pusher out",PusherNodeSend,{
|
||||
@ -81,6 +83,7 @@ module.exports = function(RED) {
|
||||
pusherappid: {type:"text"},
|
||||
pusherappkey: {type:"text"},
|
||||
pusherappsecret: {type:"password"}
|
||||
}
|
||||
},
|
||||
encrypted: true
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user