没有专用的XMPP服务器,是否可以使用FCM在Web上在生产PWA中广播消息? [英] Is it possible to broadcast messages in a production PWA using FCM for Web without having a dedicated XMPP server?

查看:164
本文介绍了没有专用的XMPP服务器,是否可以使用FCM在Web上在生产PWA中广播消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个建筑问题。我还没有实现FCM,但据我所知,有人需要在现实世界的场景中部署一个XMPP服务器,该场景提供注册设备令牌的清单。



在我的使用情况下,我想只播放有关重要更新信息的短消息,如在15:00的XY展示者会话被取消,而我对设备令牌不感兴趣。我的应用程序是一个渐进的Web应用程序,所以我会使用FCM的Web。



到目前为止我看到的演示显示一个客户端接收设备令牌,那么特定的设备令牌是从调试环境中拿来的,用来发送演示消息给客户端 - 这样就绕过了部署独立XMPP服务器的需求,但仅仅用于演示目的。



我想避免使用XMPP服务器,如果可能的话,我根本不想处理设备令牌。 Firebase的FCM / GCM服务器无论如何都有它们。我的计划是为该频道选择一个主题名称(这是我的应用程序实际使用的唯一主题),并将消息推送到正在收听该主题的设备。这是一个可行的计划?我还没有发现任何这方面的提及。 Firebase在内部知道所有的令牌,如果我不需要部署服务器,它会使架构变得更简单。



我不知道如何解散/到期设备令牌会发生在Firebase身上,但如果我将运行自己的XMPP服务器和配置令牌,那就是另一个我不得不面对的问题。 解决方案方法

要将消息发送到设备(所谓的下游消息),您需要指定服务器密钥。顾名思义,这个密钥只能存在于服务器或其他可信赖的环境中。因此,要发送消息到设备,您将需要在受信任的环境中运行代码。



然而,服务器不必说XMPP协议。您也可以使用HTTP调用FCM服务器。但是服务器是需要的,只是因为发送下游消息只能从服务器完成。



有关使用此方法发送设备到设备消息的简单示例,请参阅我的博客文章使用Firebase数据库在Android设备之间发送通知云消息传递。这是关于Android的,但是使用Firebase数据库作为消息队列的方法同样适用于所有平台。



要映射的棘手的一点是(正如您已经提到的)事实上,FCM还没有提供主题。上次我测试的时候,你可以调用一个服务器端的端点来订阅一个主题,就像这个答案中所描述的那样: GCM:你如何订阅一个设备到一个主题?


This is an architectural question. I haven't implemented FCM yet, but as far as I understand someone needs to deploy an XMPP server in a real world scenario which provisions the inventory of the registered device tokens.

In my use case I'd like to just broadcast short messages about important update information, like "XY presenter's session at 15:00 got cancelled" and I'm not interested in the device tokens. My application is a Progressive Web App, so I would use FCM for Web.

The demos I saw so far showed a client receiving the device token, then that specific device token was picked up from the debug environment and used to send the demo message to the client - thus bypassing the need of a deployed stand-alone XMPP server, but just for demo purposes.

I'd want to avoid the use of an XMPP server, I'm not interested in dealing with the device tokens at all - if possible. Firebase's FCM/GCM server have them anyway. My plan is to pick a single topic name for that channel (the only topic what my app would use actually at this point), and push messages to the devices who listen to that topic. Is this a viable plan? I haven't found any mention of this whatsoever. Firebase knows all the tokens internally and it would make the architecture simpler if I don't have to deploy a server.

I don't know how the decomission/expiration of the device tokens would happen on Firebase's side, but that's another issue I'd have to deal with if I'll run my own XMPP server and provision tokens.

解决方案

To send messages to a device (so-called downstream messages), you need to specify the server key. As its name implies, this key should only be present on a server or in some other trusted environment. So to send messages to devices you will need to run code in a trusted environment.

The server doesn't have to speak the XMPP protocol however. You can also just use HTTP to call the FCM servers. But a server will be needed, simply because sending downstream messages can only be done from a server.

For a simple example of sending device-to-device messages with this approach, see my blog post Sending notifications between Android devices with Firebase Database and Cloud Messaging. It's about Android, but the same approach of using the Firebase Database as a message queue will work across all platforms.

The tricky bit to map will be (as you already mention) the fact that topics are not available to FCM for the web yet. Last time I tested, you could call a server-side end-point to subscribe to a topic, like described in this answer: GCM: How do you subscribe a device to a topic?.

这篇关于没有专用的XMPP服务器,是否可以使用FCM在Web上在生产PWA中广播消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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