Skip to content

Commit 2e89ba4

Browse files
committed
Extract FCM_BATCH_SIZE constant
1 parent cc90415 commit 2e89ba4

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/sendFCM.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ const { FCM_METHOD } = require("./constants");
44
const FcmMessage = require("./utils/fcmMessage");
55
const { containsValidRecipients } = require("./utils/tools");
66

7+
// https://firebase.google.com/docs/cloud-messaging/send/admin-sdk?hl=en#send-a-batch-of-messages
8+
const FCM_BATCH_SIZE = 500;
9+
710
const getRecipientList = (obj) =>
811
obj.tokens ?? [obj.token, obj.condition, obj.topic].filter(Boolean);
912

@@ -87,10 +90,10 @@ const sendFCM = (regIds, data, settings) => {
8790
promises.push(sendChunk(firebaseApp, data.recipients, fcmMessage));
8891
} else {
8992
do {
90-
const registrationTokens = regIds.slice(chunk * 500, (chunk + 1) * 500);
93+
const registrationTokens = regIds.slice(chunk * FCM_BATCH_SIZE, (chunk + 1) * FCM_BATCH_SIZE);
9194
promises.push(sendChunk(firebaseApp, { tokens: registrationTokens }, fcmMessage));
9295
chunk += 1;
93-
} while (500 * chunk < regIds.length);
96+
} while (FCM_BATCH_SIZE * chunk < regIds.length);
9497
}
9598

9699
return Promise.all(promises).then((results) => {

0 commit comments

Comments
 (0)