forked from pubnub/javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpublish.js
More file actions
81 lines (65 loc) · 1.49 KB
/
publish.js
File metadata and controls
81 lines (65 loc) · 1.49 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/* ---------------------------------------------------------------------------
Init PubNub and Get your PubNub API Keys:
http://www.pubnub.com/account#api-keys
--------------------------------------------------------------------------- */
var pubnub = require("./../pubnub.js").init({
publish_key : "demo",
ssl : true,
subscribe_key : "demo",
cipher_key : "demo",
result : rlog,
status : slog
});
var pubnub_pam = require("./../pubnub.js").init({
publish_key : "pam",
ssl : true,
subscribe_key : "pam",
result : rlog,
status : slog
});
var channel = "abcd";
var message = "Hello World !!!"
function rlog(r){
console.log("RESULT");
console.log(JSON.stringify(r,null,2));
}
function slog(r){
console.log(JSON.stringify("STATUS"));
console.log(JSON.stringify(r,null,2));
}
function log(r) {
console.log(JSON.stringify(r));
}
//pubnub.where_now({
// channel : 'crypto'
//});
//pubnub.history({
// channel : 'crypto'
//})
//pubnub_pam.history({
// channel : 'abcd'
//})
pubnub.publish({
channel : channel,
message : message
});
pubnub.publish({
channel : channel,
message : message,
callback : log,
error : log
});
pubnub.subscribe({
'channel' : 'a',
'connect' : function(r) {
console.log('CONNECT : ' + r);
},
'callback' : function(r) {
console.log(JSON.stringify(r));
}
})
pubnub.subscribe({
'channel' : 'b',
'status' : slog,
'result' : rlog
})