forked from pubnub/javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhistory.js
More file actions
49 lines (42 loc) · 1.47 KB
/
Copy pathhistory.js
File metadata and controls
49 lines (42 loc) · 1.47 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
45
46
47
48
49
/* ---------------------------------------------------------------------------
Init PubNub and Get your PubNub API Keys:
http://www.pubnub.com/account#api-keys
--------------------------------------------------------------------------- */
var pubnub = require("./../pubnub.js");
var channel = 'my_channel';
var network = pubnub.init({
publish_key : "demo",
subscribe_key : "demo"
});
/* ---------------------------------------------------------------------------
Print All
--------------------------------------------------------------------------- */
get_all_history({
channel : channel,
callback : function(messages) {
console.log(messages);
}
})
/* ---------------------------------------------------------------------------
Get All History Message for a CHANNEL
--------------------------------------------------------------------------- */
function get_all_history(args) {
var channel = args['channel']
, callback = args['callback']
, start = 0
, history = [];
(function add_messages() {
network.detailedHistory({
channel : channel,
start : start,
reverse : true,
callback : function(messages) {
var msgs = messages[0]
, end = start = messages[2];
if (!msgs.length) return callback(history);
history = history.concat(msgs);
add_messages();
}
});
})();
}