2016-02-08 12:02:07 -08:00
|
|
|
// Push Adapter
|
|
|
|
|
//
|
|
|
|
|
// Allows you to change the push notification mechanism.
|
|
|
|
|
//
|
|
|
|
|
// Adapter classes must implement the following functions:
|
2016-02-10 12:03:02 -08:00
|
|
|
// * getValidPushTypes()
|
2016-02-08 12:02:07 -08:00
|
|
|
// * send(devices, installations)
|
|
|
|
|
//
|
|
|
|
|
// Default is ParsePushAdapter, which uses GCM for
|
|
|
|
|
// android push and APNS for ios push.
|
2016-02-21 12:02:18 -05:00
|
|
|
|
2016-02-10 12:03:02 -08:00
|
|
|
export class PushAdapter {
|
|
|
|
|
send(devices, installations) { }
|
2016-02-08 12:02:07 -08:00
|
|
|
|
2016-02-21 12:02:18 -05:00
|
|
|
/**
|
|
|
|
|
* Get an array of valid push types.
|
|
|
|
|
* @returns {Array} An array of valid push types
|
|
|
|
|
*/
|
|
|
|
|
getValidPushTypes() {
|
|
|
|
|
return this.validPushTypes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**g
|
|
|
|
|
* Classify the device token of installations based on its device type.
|
|
|
|
|
* @param {Object} installations An array of installations
|
|
|
|
|
* @param {Array} validPushTypes An array of valid push types(string)
|
|
|
|
|
* @returns {Object} A map whose key is device type and value is an array of device
|
|
|
|
|
*/
|
|
|
|
|
static classifyInstallation(installations, validPushTypes) {
|
|
|
|
|
// Init deviceTokenMap, create a empty array for each valid pushType
|
|
|
|
|
let deviceMap = {};
|
|
|
|
|
for (let validPushType of validPushTypes) {
|
|
|
|
|
deviceMap[validPushType] = [];
|
|
|
|
|
}
|
|
|
|
|
for (let installation of installations) {
|
|
|
|
|
// No deviceToken, ignore
|
|
|
|
|
if (!installation.deviceToken) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
let pushType = installation.deviceType;
|
|
|
|
|
if (deviceMap[pushType]) {
|
|
|
|
|
deviceMap[pushType].push({
|
|
|
|
|
deviceToken: installation.deviceToken,
|
|
|
|
|
appIdentifier: installation.appIdentifier
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
console.log('Unknown push type from installation %j', installation);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return deviceMap;
|
|
|
|
|
}
|
2016-02-08 12:02:07 -08:00
|
|
|
}
|
|
|
|
|
|
2016-02-10 12:03:02 -08:00
|
|
|
export default PushAdapter;
|