Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send device to device messages using Firebase Cloud Messaging?

After searching the docs I could not find any info on how to send device to device messages using FCM without the use of an external server.

For example, if I was creating a chat application I would need to send push notifications to users about unread messages since they won't be online all the time and I can't have a persistent service in the background that would always be connected to the real time database because that would be too resource heavy.

So how would I send a push notification to a user "A" when a certain user "B" sends him/her a chat message? Do I need an external server for this or can it be done with just Firebase servers?

like image 540
Suyash Avatar asked May 25 '16 11:05

Suyash


People also ask

How do I send data to Firebase Cloud Messaging?

Go to Firebase console — →Project Settings — →Cloud Messaging. To send the message select Body — →Raw — →JSON(application/json). You can send Notification Payload , Data Payload and even both using POSTMAN service.

How do I use Firebase Cloud Messaging?

Firebase Cloud Messaging (FCM) is a cross-platform messaging solution that lets you deliver messages for free. It allows you to send push notifications from the Firebase console or from the application server or some trusted server where logic runs. First, create a new Android Studio project and add the dependencies.

How do I send messages to multiple devices in Firebase?

Firebase Cloud Messaging provides these two ways to target a message to multiple devices: Topic messaging, which allows you to send a message to multiple devices that have opted in to a particular topic. Device group messaging, which allows you to send a message to multiple devices that belong to a group you define.

How do I send FCM messages using the firebase admin SDK?

The Firebase Admin Node.js SDK supports methods for sending (FCM) messages based on the Legacy FCM server API . These methods accept different arguments compared to the send () method. You should use the send () method whenever possible, and only use the methods described in this page when sending messages to individual devices or device groups.

What is device group messaging in Firebase?

Firebase Admin SDK for Node.js based on the legacy protocols also provide device group messaging capabilities. The maximum number of members allowed for a notification key is 20. You can create device groups and generate notification keys via an app server or an Android client.


1 Answers

UPDATE: It is now possible to use firebase cloud functions as the server for handling push notifications. Check out their documentation here

============

According to the docs you must implement a server for handling push notifications in device to device communication.

Before you can write client apps that use Firebase Cloud Messaging, you must have an app server that meets the following criteria:

...

You'll need to decide which FCM connection server protocol(s) you want to use to enable your app server to interact with FCM connection servers. Note that if you want to use upstream messaging from your client applications, you must use XMPP. For a more detailed discussion of this, see Choosing an FCM Connection Server Protocol.

If you only need to send basic notifications to your users from the server. You can use their serverless solution, Firebase Notifications.

See a comparison here between FCM and Firebase Notifications: https://firebase.google.com/support/faq/#messaging-difference

like image 139
eikooc Avatar answered Sep 17 '22 02:09

eikooc