EthanNeedsHelpCoding
EthanNeedsHelpCoding

Reputation: 149

Can I use FCM’s onMessage functions to create a live-chat application?

I’m making an app using react with firebase, and a large part of my app involves group communication. Currently I have FCM sending notifications to people within the group whenever someone types a message into chat. Can I use onMessage to load messages in real time for all group members to see, without needing to refresh the page, or do I need to set up firebase real time database ?

Any help/advice is greatly appreciated !

Upvotes: 1

Views: 1363

Answers (1)

Tarik Huber
Tarik Huber

Reputation: 7418

I would recommend to store the messages in one of the Firebase databases. For multiple reasons. You can only send FCM messages from the backend so you need a trigger for that. Idealy when a new messages is added to the database. If all users for a group listen to messages in a group chat they would see them when you setup a realtime listener. This would work much faster and more reliable than using FCM for realtime data. FCM is idealy used to notify users when they are outside of the app or inside the app but not in the chat by using onMessage. The UI should rely only the databse data and not FCM.

Upvotes: 2

Related Questions