I want to add at my project a chat but only user to user. Just two users, not subscribe to a topic. As @KMatle advises us:
Please take it as a example how to communicate between devices via FCM without a server in the middle. Do not publish a similar app to the PlayStore. It is good for SOME devices as each device will send it's identification data to all devices an vice versa. When the number of apps grow, there is a huge communication traffic (1 Mio devices will send a message to 999.999 devices and will retrieve 999.999 messages from all the others)
So my question is how can achieve this? Is it better to create a new topic for both users or exists another to way to send a message to a single device. I think tokens changes randomly how can we catch this?
For example if i want to send a message to a user and token has changes i think user never get this message.
I use to store the token of each user in a DB (phone # along with the token which Firebase assigns to each user). When I need to comunicate with each user, I get the key by phone # and send the message directly to the user. You can handle a status on the DB as well. Not ready/ready is generally enough. So every user must update the DB to keep informations up to date
I use to store the token of each user in a DB (phone # along with the token which Firebase assigns to each user). When I need to comunicate with each user, I get the key by phone # and send the message directly to the user. You can handle a status on the DB as well. Not ready/ready is generally enough. So every user must update the DB to keep informations up to date
In order to keep this DB up to date with new tokens, app needs to run a service (even it is in background) every couple of secs. Is this the right way? Moreover i would like to know from example which parts of code should i keep and use it in order to send to a single TOKEN-DEVICE(which i would get from a db).
Thank you in advance.
As Erel said, you'll need a server to store all the tokens. I use a cheap hosted solution with php & MySql. Even more important: You need to handle users which have to register/login (security) like in this forum. For sure you need to store other informations, too depending on your app.