How does the firebase for sending notifications work?

2

This question does not have to be with codes, but to understand the operation of the firebase.

I want to set up a system that notifies the user to an Android app through a PHP web service. From what I researched, the easiest way is to use firebase (and it worked perfectly for me), but I wanted to set up an independent webservice.

My question is:

How does the firebase notify the mobile? From what I've seen, we can make sure that the cell phone checks for every X minutes, but that would not consume enough data traffic?

How does firebase notify the user instantly? I wanted to understand this logic, to prevent the user from checking that there are new notifications every X minutes.

    
asked by anonymous 07.12.2017 / 01:44

2 answers

2

It works exactly as you're thinking: a service on the device maintains a connection with Google's servers.

The fundamental difference is that this service serves multiple servers / clients, all those who have overlapped the service, not just your server / client.

By having a single service that serves multiple servers and provides / distributes messages to multiple clients, it allows traffic to be used more efficiently rather than each client / server having its own service.

                ------------        ------------        ------------
                |Servidor A|        |Servidor B|        |Servidor C|
                ------------        ------------        ------------
                     |                    |                   |
                     |                    |                   |
                     ---------------------|--------------------
                                          |
                                       -------
                                       | FCM |
                                       ------- 
                                          |
                                          |
                       -------------------|--------------------
                       |                  |                   |
                ---------------     ---------------     ---------------
                |Dispositivo 1|     |Dispositivo 2|     |Dispositivo 3|
                ---------------     ---------------     ---------------
                   |        |          |        |              |       
                -------  -------    -------  -------        -------
                |App 1|  |App 2|    |App 1|  |App 2|        |App 2|
                -------  -------    -------  -------        -------

Firebase Cloud Messaging serves as an intermediary between your server and your devices. It is responsible for receiving the messages, managing them and forwarding them to the respective devices.

    
07.12.2017 / 15:57
0

On the server side (in your PHP case), after some event (for example, at the end of your save server method on the server), call the firebase library to send a push message to a user through of a unique identifier (made available by the firebase library on the device). Example on nodejs: link .

In the device (IOS, ANDROID ...), you will implement an onMessage method (provided by the firebase library on the device), which will automatically be triggered when a push arrives at the unique identifier of this device. Example for a Javascrip client: link .

    
07.12.2017 / 04:16