使用Firebase的两个用户之间的数据交换 [英] Data exchange between two users using Firebase

查看:119
本文介绍了使用Firebase的两个用户之间的数据交换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道这个过程是如何被调用的。说我是应用程序的用户,我想知道是否有消息(或状态更改,我需要知道有关),我不知道这是否是最好的方法但我试图这样做:

  Firebase结构

用户>用户A> Status =No messages

每个用户都有一个节点状态,如上所见。
当用户A向用户B发送消息时,用户A将改变用户B的状态节点。



用户B已经听取了他自己的 Status 节点,现在知道有新东西了,可以读取这个消息。



这是否可以安全地使用Firebase?

解决方案

更简单的说明使用类似于你的场景就像一个聊天应用程序。用户A向用户B发送消息,然后用户B收到来自Firebase的通知。



从您描述的内容中,您打算为 Status >节点,并在用户更改时通知用户。这似乎是好的,但从以前的建议,保持听者积极倾向于在Android上有一个相应的活动套接字,这增加了电池的消耗。



建议你使用是 firebase -boud-messaging


Firebase Cloud Messaging Firebase 套件中的一个组件用于跨平台应用程序开发的工具。




  • 向上游/ 下游消息发送无限

  • 将消息发送到个人设备或用户群

  • 处理排队和交付的各个方面
  • 优化电池效率使用FCM,您可以通知客户端应用程序新电子邮件或其他数据可用于同步
  • / strong>即可。您可以发送通知来推动用户重新连接和保留。对于即时消息等用例,消息可以将高达4KB的有效载荷传输到客户端应用程序。

我认为这个<一个聊天应用程序的href =https://codelabs.developers.google.com/codelabs/firebase-android/#0 =nofollow> Firebase Codelab 也可能有所帮助。


I am not sure how is this process called. Say I am a user of the app and I want to know if there is a message for me (or a status change that I need to know about), I am not sure if this is the best way but I am trying to do it like this:

Firebase Structure

Users   >  User A  >   Status = "No messages"

Each user has a node Status as you can see above. When user A sends a message to user B, user A changes user B's Status node.

User B, that had been listening to his own Status node, is now aware that there is something new and can go read the message.

Is this possible and safe making use of Firebase only?

解决方案

On a simpler note, and more often used scenario similar to yours is like a Chat Application. User A sends a message to User B, User B then receives a notification from Firebase.

From what you have described, you intend to have a listener in place for the Status node, and inform the user whenever it changes. This seems okay, but from what was advised to me before, keeping the listener active tends to have a corresponding active socket on Android, which adds to battery consumption.

What I suggest you make use of is :

Firebase Cloud Messaging is a component of the Firebase suite of tools for cross-platform application development.

  • Send unlimited upstream/downstream messages
  • Send messages to individual devices or a user segment
  • Handle all aspects of queueing and delivery
  • Optimize for battery efficiency

Using FCM, you can notify a client app that new email or other data is available to sync. You can send notifications to drive user reengagement and retention. For use cases such as instant messaging, a message can transfer a payload of up to 4KB to a client app.

I think this Firebase Codelab for a Chat App might also be helpful.

这篇关于使用Firebase的两个用户之间的数据交换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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