2

Is there any way to send device to device notification without using cloud functions or firebase console. eg. like when sending a message in chat app, another user should receive a notification of message received like in WhatsApp. Thanks

  • This question is pretty vague; have you worked with built in Firebase Database functionality? e.g. one user observes a private message node and when the other user posts a message to that node, the first user receives an event? What are the requirements for the 'notification'? Can you clarify and update your question? – Jay Jun 04 '18 at 17:39

1 Answers1

1

It depends on what you mean by "without cloud functions". There is no direct device to device feature in FCM so to send an FCM message to a device you do need a back end of some type.

You could use the realtime features of Cloud Firestore or Realtime Database to be notified when a new message has been written and generate the notification locally, however this would only work for foregrounded case.

Arthur Thompson
  • 9,087
  • 4
  • 29
  • 33
  • I've read some posts that we can make a post request directly to the server (using retrofit etc.) from our app and then receive those as data notifications which would work when app is foreground or in background. But all those require to store legacy server key locally which I dont think is safe, so any ideas ? – K'aRtiK Sharma Jun 04 '18 at 15:35
  • @K'aRtiKSharma No, you do not need to store a legacy server key locally. Why would you think that's a requirement? – Jay Jun 04 '18 at 17:40
  • @Jay I referred to this https://stackoverflow.com/questions/37435750/how-to-send-device-to-device-messages-using-firebase-cloud-messaging?rq=1. But I wanted to know if we can do this without storing legacy_server_key. – K'aRtiK Sharma Jun 05 '18 at 04:10
  • @K'aRtiKSharma That answer is leveraging another server and using that key in an 'unintended' way. See my comment on your question as 'messaging' other users (device to device via the Firebase server) is fairly straight forward using Firebase Database observers and events. – Jay Jun 05 '18 at 17:20
  • @K'aRtiKSharma You are correct that putting the server key in your client app is not safe, you should never do that. The easiest way to send a message would be to use a callable cloud function, that is even easier than using retrofit and does not require the server key to be in your client app. https://firebase.google.com/docs/functions/callable – Arthur Thompson Jun 07 '18 at 00:11