From 3056b40ce932b0a0231d07bf0c3d9998ae621277 Mon Sep 17 00:00:00 2001 From: hdoukas Date: Fri, 16 May 2014 18:13:02 +0200 Subject: [PATCH] added pusher node Added nodes for pushing events to Pusher service and subscribing to notifications from channels/events --- social/pusher/114-pusher_send.html | 81 +++++++++++++++++++++++++++++ social/pusher/114-pusher_send.js | 80 ++++++++++++++++++++++++++++ social/pusher/114-pusher_sub.html | 68 ++++++++++++++++++++++++ social/pusher/114-pusher_sub.js | 80 ++++++++++++++++++++++++++++ social/pusher/icons/pusher.png | Bin 0 -> 4216 bytes 5 files changed, 309 insertions(+) create mode 100644 social/pusher/114-pusher_send.html create mode 100644 social/pusher/114-pusher_send.js create mode 100644 social/pusher/114-pusher_sub.html create mode 100644 social/pusher/114-pusher_sub.js create mode 100644 social/pusher/icons/pusher.png diff --git a/social/pusher/114-pusher_send.html b/social/pusher/114-pusher_send.html new file mode 100644 index 00000000..cb3d00d0 --- /dev/null +++ b/social/pusher/114-pusher_send.html @@ -0,0 +1,81 @@ + + + + + + + + + diff --git a/social/pusher/114-pusher_send.js b/social/pusher/114-pusher_send.js new file mode 100644 index 00000000..ab2c5fd5 --- /dev/null +++ b/social/pusher/114-pusher_send.js @@ -0,0 +1,80 @@ +/** + * pusher_send.js + * Subscription module for the Pusher service (www.pusher.com) + * Requires 'pusher' module + * 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. + * You may obtain a copy of the License at + * + * 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, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + + +var Pusher = require('pusher'); + +// Require main module +var RED = require(process.env.NODE_RED_HOME+"/red/red"); + + +// The main node definition - most things happen in here +function PusherNodeSend(n) { + // Create a RED node + RED.nodes.createNode(this,n); + + var node = this; + + //get parameters from user + this.appid = n.appid; + this.appkey = n.appkey; + this.appsecret = n.appsecret; + 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(); + }); + + } + + //hue debugging on the output: + var displayResult = function(result) { + console.log(result); +}; + +var displayError = function(err) { + console.error(err); +}; + + + + +// Register the node by name. This must be called before overriding any of the +// Node functions. +RED.nodes.registerType("Pusher out",PusherNodeSend); diff --git a/social/pusher/114-pusher_sub.html b/social/pusher/114-pusher_sub.html new file mode 100644 index 00000000..270eb20b --- /dev/null +++ b/social/pusher/114-pusher_sub.html @@ -0,0 +1,68 @@ + + + + + + + + + diff --git a/social/pusher/114-pusher_sub.js b/social/pusher/114-pusher_sub.js new file mode 100644 index 00000000..96012ae5 --- /dev/null +++ b/social/pusher/114-pusher_sub.js @@ -0,0 +1,80 @@ +/** + * pusher_sub.js + * Subscription module for the Pusher service (www.pusher.com) + * Requires 'pusher-client' module + * 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. + * You may obtain a copy of the License at + * + * 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, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + + +var Pusher = require('pusher-client'); + +// Require main module +var RED = require(process.env.NODE_RED_HOME+"/red/red"); + + +// The main node definition - most things happen in here +function PusherNode(n) { + // Create a RED node + RED.nodes.createNode(this,n); + + var node = this; + + //get parameters from user + this.apikey = n.apikey; + this.channel = n.channel; + this.eventname = n.eventname; + + + + //create a subscription to the channel and event defined by user + var socket = new Pusher(''+this.apikey); + var my_channel = socket.subscribe(''+this.channel); + socket.bind(''+this.eventname, + function(data) { + + var msg = {}; + msg.payload = data; + node.send(msg); + } + ); + + this.on("input", function(msg){ + + }); + + + 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(); + }); + + } + + //hue debugging on the output: + var displayResult = function(result) { + console.log(result); +}; + +var displayError = function(err) { + console.error(err); +}; + + + + +// Register the node by name. This must be called before overriding any of the +// Node functions. +RED.nodes.registerType("Pusher",PusherNode); diff --git a/social/pusher/icons/pusher.png b/social/pusher/icons/pusher.png new file mode 100644 index 0000000000000000000000000000000000000000..04bc1635e9625bce080af99091303b31ca353e51 GIT binary patch literal 4216 zcmZuz1z1#F*BxMx4(U=yB&23&1sQ6nL1HK!kQ#bu0ZHkSk`_Vf5)cGwMur9vq*GcL zIt2mAAKv%p^_u>fDh5 zA^-qL<xp0gE>YXy}m&Jy0tG z9)Q3P3*mBCAXK8e$@9cQw;4}4oZVcJjx0FHY@Fm5HKMacOF<2&8}K%4~uTiuX&0ixMRy6ue?LmJwi_9J{IYCK9LUh{&L6;SzD0e|GI z5t^F%L8Y_ua2p(8ftliOLU6f`UHZqfKY(%E0FWw;73r9_BYxonh?CkSzPM0E{gJTA0C*NyFGT_) z;ARCk$KRrHt6!~7_9}J$m@>J_Ts3LzY$Qba+>5U>Dr@lj~P5f3V+t!x; z*s{%^rpdY6emdvSuimG6dt96S8FJAX`g8W1A0dqlfI|+0ceg6B$$Ee)ha0lEg^!v$ zAiys|K-KK~{o7&o#tH2|$+^j*HaG2E@iOhee5(&mGlQJIHHAqWrS@!}K6zBYC=+-O zPA_7qh$|>8c&yOdOHP^6Z*hJ^eYw~yf&Sjz#{WLEnQQbU zkcRk=F8DKva}zQ9rQ6Zjyf6XyhDspn;6z`Ypa9rC0uDzRZ+zd4XVgNZU$I|oO5;Dd z#tM61teo5-GmLaxP?K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