简体   繁体   English

从 PWA 服务工作者调用 Firebase Callable Function 以响应对推送通知的点击

[英]Calling a Firebase Callable Function from a PWA service worker in response to a click on a push notification

My PWA and service worker are in place, I have push notifications setup, and I have a listener ready for when they are clicked.我的 PWA 和 service worker 已经就位,我已经设置了推送通知,并且我已经准备好了一个监听器,以便在它们被点击时使用。 Now I want to call a Firebase Callable Function from within this listener.现在我想从这个监听器中调用 Firebase Callable Function。

From the doc , the only Firebase library a service worker can use is Firebase Messaging:文档中,服务工作者可以使用的唯一 Firebase 库是 Firebase 消息:

// Give the service worker access to Firebase Messaging. // 授予服务工作者对 Firebase 消息传递的访问权限。
// Note that you can only use Firebase Messaging here. // 注意这里只能使用Firebase Messaging。 Other Firebase libraries其他 Firebase 库
// are not available in the service worker. // 在服务工作者中不可用。

So the piece that facilitates calls to Callable Functions is not available, right?因此,促进调用 Callable Functions 的部分不可用,对吗? Is the only option left for me to use the protocol specs and call them directly?我唯一的选择是使用 协议规范并直接调用它们吗? Using fetch for instance.例如使用fetch Any example would be great!任何例子都会很棒!

Here's my sample on using Callable Functions, with REST API:这是我使用可调用函数的示例,带有 REST API:

This is the worker source:这是工人来源:

I chose to go this way, because it's not much harder than using Firebase clients, and I already had similar code available.我选择了 go 这种方式,因为它并不比使用 Firebase 客户端难多少,而且我已经有类似的代码可用。

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

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