如何通过Firebase在用户之间发送直接消息? [英] How to send direct message via Firebase from user to user?

查看:94
本文介绍了如何通过Firebase在用户之间发送直接消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的是菜鸟,需要个建议.

I am really rookie and need an advice.

我有阅读文档,据我了解,如果您需要发送直接消息,请按照后续步骤:

I have read documentation, and as far as i understood if you need send direct message, follow next steps:

  1. 进行身份验证,最终您获得 Firebase TokenId userId
  2. 将它们发送到服务器端并将其存储在数据库中
  3. 当您要发送消息时,需要创建 json 并放入内 topic text resipent userId 内,等等...
  4. 通过HTTP将此 json 发送到服务器端
  5. 服务器检索此 json 时,应使用Firebase API进行操作在firebase中使用随机名称创建新消息bloc child
  6. 最终服务器必须通过从消息中获取的userId在数据库中找到配方用户.
  7. 服务器将通过userId查找当前的配方用户后,接下来我们应使用 firebase tokenId 来发送通知.
  8. 并使用以下数据发送配方用户通知-新名称消息组 child
  9. 收件人将连接到当前所在的位置并检索数据
  1. Make authentification, eventually you get Firebase TokenId and userId
  2. Send them to your server side and store it in DB
  3. When you are going to send a message you need create json and put inside topic text and resipent userId so on...
  4. Send this json via HTTP to your server side
  5. When server retrive this json, it should use Firebase API to create new message bloc child with random name in firebase
  6. Eventually server have to find recipent user in DB by userId that we get from message.
  7. After server will find current recipent user by userId , next we should take firebase tokenId In order to sent notification .
  8. And send recipent user notification with such data - name of new message bloc child
  9. Recipent will connect to this current bloc and retrive data

据我所知,如果错了,请修理我吗?

It is as i understood this consept, fix me please if smth wrong?

推荐答案

您建议的方法听起来不错.要实现的最重要的事情是,您需要应用服务器将下游消息发送到设备.使用数据库作为应用程序与应用程序服务器之间的通信机制是一种流行的方法.

Your suggested approach sounds good. The most important thing to realize is that you require an app server to send a downstream message to a device. Using the database as the communication mechanism between the app and the app server is a popular approach.

您还可以使用 Cloud Messaging的上游功能.但是我从来没有尝试过这种方法,因为数据库对我来说很好用,而且我对学习另一个协议(XMPP)几乎没有兴趣.

You could also use Cloud Messaging's upstream capabilities. But I've never tried that approach, because the database works fine for me and I had little interest in learning yet another protocol (XMPP).

您可以在此Firebase博客文章中了解如何实现它在具有Firebase数据库和Cloud Messaging的Android设备之间发送通知.

You can read how I implemented it in this Firebase blog post Sending notifications between Android devices with Firebase Database and Cloud Messaging.

这篇关于如何通过Firebase在用户之间发送直接消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆