forked from pubnub/javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpn_message.js
More file actions
91 lines (64 loc) · 1.59 KB
/
pn_message.js
File metadata and controls
91 lines (64 loc) · 1.59 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
82
83
84
85
86
87
88
89
90
91
var PNmessage = require("../pubnub.js").PNmessage
var PUBNUB = require("../pubnub.js")
var pubnub = PUBNUB({
publish_key : "demo-36",
subscribe_key : "demo-36",
origin : "gcm-beta.pubnub.com"
});
// Create a pubnub message
var a = PNmessage()
// set pubnub object for pubnub message
a.pubnub = pubnub;
// set callback method
a.callback = console.log
// set error callback method
a.error = console.log
// set channel
a.channel = 'push'
// populating apns info
a.apns.alert = "this is alert"
a.apns.badge = 2
a.apns.key = "hi am apns"
// publish
a.publish()
// populating gcm info
a.gcm = ['i am gcm array']
// publish
a.publish()
// populating common info
a.mykey = "hi"
// publish
a.publish()
// populating all info in one go and publishing
var c = PNmessage()
c.pubnub = pubnub;
c.callback = console.log
c.error = console.log
c.channel = 'push'
c.gcm = {"message":"be sure not to send objects!", "foo":"bar" }
c.apns.alert = "this is alert"
c.apns.badge = 2
c.apns.key = "hi am apns"
c.mykey = "hi"
c.publish()
// following also works
pubnub.publish({
'channel' : 'push',
'message' : c,
'callback' : console.log,
'error' : console.log
});
// and this also works
pubnub.publish({'message' : c});
// and this too
var d = PNmessage({
'callback' : console.log,
'error' : console.log,
'channel' : 'push',
'apns' : {'alert' : "this is alert", 'badge' : 2, 'key' : "hi am apns"},
'gcm' : {"message":"be sure not to send objects!", "foo":"bar" },
'mykey' : "hi"
});
pubnub.publish({'message' : d});
// and this as well
d.publish()