Javascript 对于Web,如果同一应用程序在多个选项卡中打开,则会收到多个firebase通知
我正在使用@angular/fire作为angular 7的firebase推送通知。我收到的通知与我的应用程序在多个选项卡中打开的时间相同Javascript 对于Web,如果同一应用程序在多个选项卡中打开,则会收到多个firebase通知,javascript,angular,firebase,firebase-cloud-messaging,angularfire2,Javascript,Angular,Firebase,Firebase Cloud Messaging,Angularfire2,我正在使用@angular/fire作为angular 7的firebase推送通知。我收到的通知与我的应用程序在多个选项卡中打开的时间相同 receiveMessage() { this.angularFireMessaging.messages.subscribe( (payload) => { console.log("new message received. ", payload); // this.currentMessage
receiveMessage() {
this.angularFireMessaging.messages.subscribe(
(payload) => {
console.log("new message received. ", payload);
// this.currentMessage.next(payload);
console.log(thisref._router.url);
if(thisr[enter image description here][1]ef._router.url == '/playGame' && payload.data.gameId == window.localStorage.getItem(environment.gameId)) {
return
} else{
var notificationTitle = payload.notification.title;
var notificationOptions = {
body : payload.notification.body,
icon : payload.notification.icon,
// click_action : payload.notification.click_action
};
console.log(notificationOptions);
var notification = new Notification(notificationTitle,notificationOptions);
notification.onclick = function(event) {
// event.preventDefault(); // prevent the browser from focusing the Notification's tab
window.open(payload.notification.click_action , '_self');
// notification.close();
}
}
})
}
我在前台的浏览器中得到了每个标签的一个通知。所以我设置了下面的代码,它对我起作用了
if (!document.hidden) {
var notificationTitle = payload.notification.title;
var notificationOptions = {
body : payload.notification.body,
icon : payload.notification.icon,
// click_action : payload.notification.click_action
};
console.log(notificationOptions);
var notification = new Notification(notificationTitle,notificationOptions);
notification.onclick = function(event) {
// event.preventDefault(); // prevent the browser from focusing the Notification's tab
window.open(payload.notification.click_action , '_self');
// notification.close();
}
}
这不是意料之中的事吗?每个选项卡都订阅了该通知,并将独立于其他选项卡进行处理。我希望一次只收到一个通知。打开多少选项卡并不重要。你能帮帮我吗?这个@AshwiniPrajapati有什么解决方案吗?如果活动选项卡不是我的网站怎么办?在这种情况下,我想通知将被跳过