-
Notifications
You must be signed in to change notification settings - Fork 1
/
example.js
49 lines (36 loc) · 1.18 KB
/
example.js
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
/* Examples:
**
** - How to spin a Server to save Subscription ID from clients
** - How to send Push notifications to clients.
**
*/
var gcm = require('./index');
// set the new server and the entry points before any app.listen().
var GcmServer = new gcm.Server({
port: 3000
});
GcmServer.setNewTokenEntryPoint('/gcm/token/new');
GcmServer.onNewToken(function(params, save){
// ... params validation and filtering
save({token: params.token, name: params.name}); // save into db (async).
});
GcmServer.start();
// Use gcm to send a Message.
/*
var message = new gcm.Message();
message.addData('hello', 'world');
message.addNotification('title', 'Hello');
message.addNotification('icon', 'ic_launcher');
message.addNotification('body', 'World');
//Add your mobile device registration tokens here
var regTokens = ['ecG3ps_bNBk:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxXl7TDJkW'];
//Replace your developer API key with GCM enabled here
var sender = new gcm.Sender('AIza*******************5O6FM');
sender.send(message, regTokens, function (err, response) {
if(err) {
console.error(err);
} else {
console.log(response);
}
});
*/