问题描述
我正在使用Firebase Cloud Messaging向Web应用程序的用户发送通知。 这是我当前对firebase-messaging-sw.js的设置
importScripts('https://www.gstatic.com/firebasejs/5.5.0/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/5.5.0/firebase-messaging.js');
firebase.initializeApp({
'messagingSenderId': '123456'
});
const messaging = firebase.messaging();
messaging.setBackgroundMessageHandler(function(payload) {
console.log('[firebase-messaging-sw.js] Received background message ',payload);
// Customize notification here
const title = 'New Order';
const notificationoptions = {
body: 'Background Message body.',renotify: true,tag: "newOrder",vibrate: [200,100,200,200],requireInteraction: true,};
return self.registration.showNotification(title,notificationoptions);
});
self.addEventListener('notificationclick',function(event) {
let url = 'https://dashboard.inhouSEOrders.io';
event.notification.close(); // Android needs explicit close.
event.waitUntil(
clients.matchAll({type: 'window'}).then( windowClients => {
// Check if there is already a window/tab open with the target URL
for (var i = 0; i < windowClients.length; i++) {
var client = windowClients[i];
// If so,just focus it.
if (client.url === url && 'focus' in client) {
return client.focus();
}
}
// If not,then open the target URL in a new window/tab.
if (clients.openWindow) {
return clients.openWindow(url);
}
})
);
});
我见过Google聊天之类的PWA,通知会播放自定义声音。我假设可以在服务工作者中完成此操作,但是我该怎么做呢? 过去,我曾使用Howler在浏览器中播放声音,但是这要求用户进行一些交互才能播放声音。那么如何在服务人员中播放声音?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)