jlcvp / fcm-node

A Node.JS simple interface to Google's Firebase Cloud Messaging (FCM) for Android & iOS & Web Notification and data push
MIT License
125 stars 46 forks source link

Send fcm synchronous call available ? #55

Closed srigiri92 closed 4 years ago

srigiri92 commented 4 years ago

Hi,

I'm facing following issue,


 var isSent =false

for(let token of tokens){ 
 isSent = await fcm.send(message, async (err, response)=> {
          if (err) {
                        console.log("Something has gone wrong!");
                        return false;
                    } else {
                        console.log("Successfully sent with response: ", response);
                        return true;
                    }
                });
}

Here isSent is always undefined , Is there is any synchronous call to send FCM messages ?
jlcvp commented 4 years ago

try like this

let isSent =false

for(let token of tokens){ 
  isSent = await new Promise((resolve, _) => { 
    fcm.send(message, (err, response)=> {
        if (err) {
          console.log("Something has gone wrong!");
          resolve(false);
        } else {
          console.log("Successfully sent with response: ", response);
          resolve(true);
        }
    });
 });
}