-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathstreaming.js
43 lines (33 loc) · 1.13 KB
/
streaming.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
module.exports = function(RED) {
var nforce = require('nforce');
function Streaming(config) {
RED.nodes.createNode(this,config);
this.connection = RED.nodes.getNode(config.connection);
var node = this;
// create connection object
var org = nforce.createConnection({
clientId: this.connection.consumerKey,
clientSecret: this.connection.consumerSecret,
redirectUri: this.connection.callbackUrl,
environment: this.connection.environment,
mode: 'single'
});
org.authenticate({ username: this.connection.username, password: this.connection.password }, function(err, oauth) {
if(err) node.err(err);
var client = org.createStreamClient();
var stream = client.subscribe({ topic: config.pushTopic });
node.log("Subscribing to topic: " + config.pushTopic );
stream.on('error', function(err) {
node.log('Subscription error!!!');
node.log(err);
client.disconnect();
});
stream.on('data', function(data) {
node.send({
payload: data
});
});
});
}
RED.nodes.registerType("streaming",Streaming);
}