FCM error handling with Meteor.bind
This commit is contained in:
parent
8780edc832
commit
20359a79e3
1 changed files with 16 additions and 11 deletions
|
|
@ -15,8 +15,11 @@ import gcm from 'node-gcm';
|
||||||
import { trim } from '/imports/ui/components/NotificationsObserver/util.js';
|
import { trim } from '/imports/ui/components/NotificationsObserver/util.js';
|
||||||
|
|
||||||
Meteor.startup(() => {
|
Meteor.startup(() => {
|
||||||
|
let validFcmSender = true;
|
||||||
|
|
||||||
if (!(Meteor.settings.private.fcmApiToken && Meteor.settings.private.fcmApiToken.length > 0)) {
|
if (!(Meteor.settings.private.fcmApiToken && Meteor.settings.private.fcmApiToken.length > 0)) {
|
||||||
console.warn('Missing settings.private.fcmApiToken key, mobile notifications will not work');
|
console.warn('Missing settings.private.fcmApiToken key, mobile notifications will not work');
|
||||||
|
validFcmSender = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const fcmSender = new gcm.Sender(Meteor.settings.private.fcmApiToken);
|
const fcmSender = new gcm.Sender(Meteor.settings.private.fcmApiToken);
|
||||||
|
|
@ -38,9 +41,9 @@ Meteor.startup(() => {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
function imgEl(lat, lng) {
|
function imgEl(lat, lng) {
|
||||||
return `<img src="${imgUrl(lat, lng)}" width="640" height="480"/>`;
|
return `<img src="${imgUrl(lat, lng)}" width="640" height="480"/>`;
|
||||||
} */
|
} */
|
||||||
|
|
||||||
function process(notif) {
|
function process(notif) {
|
||||||
if (isMailServerMaster && notif.type === 'mobile' && !notif.notified) {
|
if (isMailServerMaster && notif.type === 'mobile' && !notif.notified) {
|
||||||
|
|
@ -75,14 +78,16 @@ Meteor.startup(() => {
|
||||||
} else {
|
} else {
|
||||||
registrationTokens.push(user.fireBaseToken);
|
registrationTokens.push(user.fireBaseToken);
|
||||||
// FIXME: better join users
|
// FIXME: better join users
|
||||||
fcmSender.send(msg, { registrationTokens }, (err, response) => {
|
if (validFcmSender) {
|
||||||
if (err) {
|
fcmSender.send(msg, { registrationTokens }, Meteor.bindEnvironment(function processResult(err, response) {
|
||||||
console.error(err);
|
if (err) {
|
||||||
} else {
|
console.error(`FCM error: ${err}`);
|
||||||
console.log(response);
|
} else {
|
||||||
Notifications.update(notif._id, { $set: { notified: true, notifiedAt: new Date() } });
|
console.log(`FCM response: ${response}`);
|
||||||
}
|
Notifications.update(notif._id, { $set: { notified: true, notifiedAt: new Date() } });
|
||||||
});
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (notif.type === 'web' && !notif.emailNotified) {
|
} else if (notif.type === 'web' && !notif.emailNotified) {
|
||||||
const user = Meteor.users.findOne({ _id: notif.userId });
|
const user = Meteor.users.findOne({ _id: notif.userId });
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue