forked from pubnub/javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlistener.js
More file actions
44 lines (39 loc) · 1.27 KB
/
listener.js
File metadata and controls
44 lines (39 loc) · 1.27 KB
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
44
/* ---------------------------------------------------------------------------
Init PubNub and Get your PubNub API Keys:
http://www.pubnub.com/account#api-keys
--------------------------------------------------------------------------- */
var pubnub = require('./../pubnub');
var createPubNub = function(config) {
var that = {};
var handler = pubnub.init({
subscribe_key: 'demo'
});
that.subscribe = function(options) {
handler.subscribe(options);
};
return that;
};
var messaging = createPubNub();
var createListener = function(channel) {
messaging.subscribe({
channel : channel,
callback : function(message) {
console.log(new Date(), channel, 'Got Message:', message);
},
error : function() {
console.log(new Date(), channel, 'Connection Lost.');
},
connect : function() {
console.log(new Date(), channel, 'Connected.');
},
reconnect : function() {
console.log(new Date(), channel, 'Reconnected.');
},
disconnect : function() {
console.log(new Date(), channel, 'Disconnect.');
}
});
};
for ( var i = 2; i < process.argv.length; i += 1) {
createListener(process.argv[i]);
}