创建一个像 OneSignal 这样的网络推送通知服务 [英] Create a web push notification service like OneSignal

查看:68
本文介绍了创建一个像 OneSignal 这样的网络推送通知服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们需要开发类似于 OneSignal 的东西(仅限网络,没有本机应用程序)供私人使用.我们可以从哪里开始?有没有我们可以使用的开源项目?

解决方案

每个浏览器都实现自己的推送服务,因此使用私有/自定义推送服务需要重新创建(至少部分)推送 &Service Worker API 在客户端实现类似行为.Google 有一个写得很好的高级概述;请参阅谁和什么是推送服务?"第 2 步的部分. 同样值得注意的是,虽然可以创建推送服务本身,但您将失去浏览器为 Web 应用程序提供的功能(例如,即使 Web 应用程序不在前台),因为浏览器只会寻找自己的推送服务.

在浏览器之外(例如 Electron 应用),您仍然需要重新创建(部分)推与Service Worker API 在客户端实现类似的行为.在这种情况下,如果可用,您可能仍然最好为目标平台使用本机推送服务.

如果内容隐私是最终目标:WebPush 协议在客户端和应用服务器之间提供了一种加密手段,因此 Push Service 无法读取通知内容.这一点,再加上对标准推送 API 的接受,使得在大多数情况下都可以使用 3rd 方推送服务,并且与从头开始构建所有内容相比,这是微不足道的.

但是,如果你绝对需要做一个自定义的 Push Service,Mozilla 的 Push Service 是我找到的唯一完全开源的解决方案.它可能不是您开箱即用"所需要的,但可能很接近.到目前为止,只有客户端和管理 SDK 是 Firebase 的开源软件.>

We need to develop something similar to OneSignal (only web, no native apps) for private use. Where can we start? Is there some open source project we can use?

解决方案

Each browser implements their own Push Service, so using a private/custom Push Service necessitates re-creating (at least portions of) the Push & Service Worker API's to achieve similar behavior client-side. Google has a nicely-written high-level overview; see the "Who and What is the Push Service?" section of Step 2. It's also worth noting that while the Push Service itself may be created, you will lose the functionality the browser provides the web app (e.g. waking the service worker on receiving a notification, even if the web app isn't in the foreground), because the browser will only be looking to its own Push Service.

Outside the browser (e.g. an Electron app), you will still need to re-create (portions of) the Push & Service Worker API's to achieve similar behavior client-side. In this case, you're likely still better off using a native Push Service for the target platform, if available.

If content privacy is the ultimate goal: the WebPush protocol provides a means of encryption between the client and application server, so the Push Service can't read the notification content. This, combined with the acceptance of a standard Push API, makes using a 3rd party Push Service allowable for most scenarios, and trivial compared to building everything from scratch.

However, if you absolutely need to make a custom Push Service, Mozilla's Push Service is the only fully open-source solution I've found. It may not be exactly what you need "out of the box", but may be close. Only the client and admin SDK's are open-source for Firebase, so far.

这篇关于创建一个像 OneSignal 这样的网络推送通知服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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