Repository navigation
Expand file tree
/
Copy pathapp.js
More file actions
51 lines (38 loc) · 1.44 KB
/
Copy pathapp.js
File metadata and controls
51 lines (38 loc) · 1.44 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
50
51
(function () {
// -----------------------------------------------------------------------
// PUBNUB SETUP
// -----------------------------------------------------------------------
var my_user_data = { name:"John" };
var pubnub_setup = {
user:my_user_data,
channel:'bootstrap-app',
publish_key:'demo',
subscribe_key:'demo',
custom_presence:false,
presence:false
};
// -----------------------------------------------------------------------
// CREATE CONNECTION FOR USER EVENTS
// -----------------------------------------------------------------------
var socket = io.connect('http://pubsub.pubnub.com/history', pubnub_setup);
// -----------------------------------------------------------------------
// WAIT FOR A CONNECTION, then publish and get history
// -----------------------------------------------------------------------
socket.on('connect', function () {
console.log('connected!!!');
seedHistory();
});
function seedHistory() {
for (a = 0; a < 9; a++) {
socket.send('test data ' + a, function (message) { console.log("Seeding history data: " + message)} );
}
getHistory(socket);
}
var getHistory = function() {
socket.history({'count':10}, function (response) {
console.log(response);
});
}
textDiv = document.getElementById('text');
textDiv.onclick = getHistory;
})();