@@ -7,7 +7,7 @@ const cryptoUtils = require('./cryptoUtils');
77const GCMTimeToLiveMax = 4 * 7 * 24 * 60 * 60 ; // GCM allows a max of 4 weeks
88const GCMRegistrationTokensMax = 1000 ;
99
10- function GCM ( args ) {
10+ export function GCM ( args ) {
1111 if ( typeof args !== 'object' || ! args . apiKey ) {
1212 throw new Parse . Error ( Parse . Error . PUSH_MISCONFIGURED ,
1313 'GCM Configuration is invalid' ) ;
@@ -22,16 +22,8 @@ function GCM(args) {
2222 * @returns {Object } A promise which is resolved after we get results from gcm
2323 */
2424GCM . prototype . send = function ( data , devices ) {
25- let pushId = cryptoUtils . newObjectId ( ) ;
26- let timeStamp = Date . now ( ) ;
27- let expirationTime ;
28- // We handle the expiration_time convertion in push.js, so expiration_time is a valid date
29- // in Unix epoch time in milliseconds here
30- if ( data [ 'expiration_time' ] ) {
31- expirationTime = data [ 'expiration_time' ] ;
32- }
3325 // Generate gcm payload
34- let gcmPayload = generateGCMPayload ( data . data , pushId , timeStamp , expirationTime ) ;
26+ let gcmPayload = generateGCMPayload ( data ) ;
3527 // Make and send gcm request
3628 let message = new gcm . Message ( gcmPayload ) ;
3729
@@ -68,7 +60,17 @@ GCM.prototype.send = function(data, devices) {
6860 * @param {Number|undefined } expirationTime A number whose format is the Unix Epoch or undefined
6961 * @returns {Object } A promise which is resolved after we get results from gcm
7062 */
71- function generateGCMPayload ( coreData , pushId , timeStamp , expirationTime ) {
63+ export function generateGCMPayload ( data ) {
64+ let pushId = cryptoUtils . newObjectId ( ) ;
65+ let timeStamp = Date . now ( )
66+ let coreData = data . data ;
67+ let expirationTime ;
68+ // We handle the expiration_time convertion in push.js, so expiration_time is a valid date
69+ // in Unix epoch time in milliseconds here
70+ if ( data [ 'expiration_time' ] ) {
71+ expirationTime = data [ 'expiration_time' ] ;
72+ }
73+
7274 let payloadData = {
7375 'time' : new Date ( timeStamp ) . toISOString ( ) ,
7476 'push_id' : pushId ,
@@ -78,6 +80,7 @@ function generateGCMPayload(coreData, pushId, timeStamp, expirationTime) {
7880 priority : 'normal' ,
7981 data : payloadData
8082 } ;
83+
8184 if ( expirationTime ) {
8285 // The timeStamp and expiration is in milliseconds but gcm requires second
8386 let timeToLive = Math . floor ( ( expirationTime - timeStamp ) / 1000 ) ;
@@ -110,4 +113,3 @@ if (typeof process !== 'undefined' && process.env.NODE_ENV === 'test') {
110113 GCM . generateGCMPayload = generateGCMPayload ;
111114 GCM . sliceDevices = sliceDevices ;
112115}
113- module . exports = GCM ;
0 commit comments