samedi 8 avril 2017

firebase cloud messaging for web; data message not received

I am using fcm to send events from my web-server to browser clients. Unfortunately the messages are only received when the body includes a "notification" object (see here). Since messages including a notification object are automatically shown as a browser notification if the website isn't focused, I'd rather use a data message since I do not want to show a browser notification. If I just include a "data" object in the fcm message, the message is not received. I followed this tutorial.

Message is received by browser:

 {
    "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
    "notification" : {
      "body" : "great match!",
      "title" : "Portugal vs. Denmark",
      "icon" : "myicon"
    }
  }

Message is not received by browser:

{
   "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
   "data" : {
     "Nick" : "Mario",
     "body" : "great match!",
     "Room" : "PortugalVSDenmark"
   },
 }




Aucun commentaire:

Enregistrer un commentaire