-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
58 lines (41 loc) · 1.06 KB
/
app.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
50
51
52
53
54
55
56
57
58
var express = require('express');
var server = express();
//server.use(express.urlencoded());
server.use(express.bodyParser());
var Params = require('constants');
// GCM config
var gcm = require('node-gcm');
// Server API key
var sender = new gcm.Sender('yourServerApiKey');
var registrationIds = [];
// Routes
// Register device
server.post("/register", function(req, res) {
var regId = req.body.regId;
registrationIds.push(regId);
console.log("new regId " + regId + "/n");
res.status(200);
});
// test push method
server.get('/test-push', function(req, res) {
sendPush();
res.status(200);
});
var sendPush = function () {
var message = new gcm.Message({
collapseKey: 'appmaster',
delayWhileIdle: true,
timeToLive: 3,
data: {
user: 'Fran',
message: 'Hola, que tal?',
photo: 'http://www.comolohago.cl/wp-content/uploads/2013/06/ANDROID.png'
}
});
sender.send(message, registrationIds, 4, function (err, result) {
console.log(result);
});
};
console.log("Server started");
server.listen(9999);
sendPush();