-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpusceiver-node.js
37 lines (33 loc) · 1.31 KB
/
pusceiver-node.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
var util = require('util');
var url = require('url');
var Firebase = require('./firebase-node');
var rootRef = new Firebase('https://pusceiver.firebaseIO.com/');
var FirebaseTokenGenerator = require("firebase-token-generator");
var tokenGenerator = new FirebaseTokenGenerator(process.env.FIREBASE_APP_SECRET);
var token = tokenGenerator.createToken({}, {admin: true, debug: true});
var Kaiseki = require('kaiseki');
var kaiseki = new Kaiseki(process.env.PARSE_APP_ID, process.env.PARSE_REST_API_KEY);
function push_notification(itemSnapshot) {
var notification = {
//channels: [''],
where: { "deviceType": "ios" },
data: {
p: url.parse(itemSnapshot.ref().toString()).path,
alert: itemSnapshot.val()
}
};
kaiseki.sendPushNotification(notification, function(err, res, body, success) {
if (success) {
console.log('Push notification successfully sent:', body);
} else {
console.log('Could not send push notification:', err, body);
}
});
}
util.debug("pusceiver-node will start");
rootRef.auth(token);
rootRef.child("users").on('child_added', function(userSnapshot) {
userSnapshot.ref().child('items').startAt(Date.now()).on('child_added', function(itemSnapshot) {
push_notification(itemSnapshot);
});
});