简体   繁体   English

Firebase 消息传递服务可以作为 websockets/服务器发送事件的可扩展替代品吗?

[英]Can Firebase Messaging Service be a scalable replacement to websockets / server sent events?

I am developing a webapp and currently my app server uses Server Sent Events to maintain a connection to the user to efficiently push things like new messages and other events to them without them having to constantly poll the server to ask.我正在开发一个 web 应用程序,目前我的应用程序服务器使用服务器发送事件来维护与用户的连接,以有效地将新消息和其他事件等内容推送给他们,而无需他们不断轮询服务器进行询问。

I'm looking for a way to implement Push Notifications such that I can use the Notification Web API to deliver notifications to the user either when they are in a separate tab, or when they have it running on their phone and they have Chrome minimized.我正在寻找一种实现推送通知的方法,这样我就可以使用Notification Web API在用户位于单独的选项卡中时向用户发送通知,或者当他们在手机上运行通知并且将 Chrome 最小化时。

After some research, it looks like Google Cloud Messaging has been replaced by Firebase Cloud Messaging, and this is the recommended service to use to deliver push notifications.经过一些研究,看起来 Google Cloud Messaging 已被 Firebase Cloud Messaging 取代,这是推荐用于传递推送通知的服务。 It looks like it works by having the user maintain a persistent connection the Firebase Servers and your personal app server posts requests to Firebase for them to deliver to the user.看起来它的工作原理是让用户保持 Firebase 服务器和您的个人应用服务器向 Firebase 发送请求以交付给用户的持久连接。

My question: does this alleviate the need to implement and maintain an SSE / WebSocket server?我的问题:这是否减轻了实施和维护 SSE/WebSocket 服务器的需要? I'm wondering if I can't just forward all my events through FireBase instead and have them be delivered to the user via their service.我想知道我是否不能只是通过 FireBase 转发我的所有事件,并通过他们的服务将它们交付给用户。 That is, I would have two classes of messages both sent from Firebase:也就是说,我会从 Firebase 发送两类消息:

One would be the typical "notifications" which are interpreted as such by the user (such as a new message), and require local permissions for the Notifications API.一种是典型的“通知”,由用户解释(例如新消息),并且需要通知 API 的本地权限。 And then the other type would be other "real-time" updates that wouldn't require a notification (such as a message being edited, or the "user is typing a message" prompt)然后另一种类型是不需要通知的其他“实时”更新(例如正在编辑的消息,或“用户正在输入消息”提示)

Is this sort of thing possible / recommended, or is my understanding flawed in some aspect of this?这种事情是可能的/推荐的,还是我的理解在某些方面有缺陷?

Nothing you're describing seems outside of capabilities of FCM.您所描述的一切似乎都超出了 FCM 的能力。

It looks like it works by having the user maintain a persistent connection the Firebase Servers看起来它的工作原理是让用户保持与 Firebase 服务器的持久连接

Actually, it's not the "user".实际上,它不是“用户”。 It's the messaging infrastructure provided by the device.它是设备提供的消息传递基础设施。 For Android, the message get routed through Google Play services, which runs as a privileged process in the background.对于 Android,消息通过 Google Play 服务路由,该服务在后台作为特权进程运行。 For iOS, messges go through Apple's APNS.对于 iOS,消息通过 Apple 的 APNS。 These components maintain an open socket to their respective services, and they're more effective than the app managing the socket on its own, because the app can't manage a socket in the background indefinitely - the OS will shut it down after some time.这些组件为各自的服务维护一个打开的套接字,它们比应用程序自己管理套接字更有效,因为应用程序不能无限期地在后台管理套接字——操作系统会在一段时间后关闭它. This means the app can wake up and receive messages soon after they're sent.这意味着应用程序可以在消息发送后立即唤醒并接收消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM