サイトに新しいアイテムを追加すると、すべてのクライアントがブラウザで通知を確認できるように、Web 通知をサイトに配置しようとしています。
angular-web-notificationを選択し、Bower を介してアプリにインストールし、ローカルでテストしましたが、問題なく動作しましたが、サイトを本番環境にデプロイした後、本番環境で再度テストしたところ、通知はブラウザでのみ来ており、サイトの通知を許可したすべてのクライアント。
これが私のコードです:
.directive('showButton', ['webNotification', function (webNotification) {
return {
restrict: 'C',
scope: {
notificationTitle: '=',
notificationMsg: '=',
notificationUrl: '='
},
link: function (scope, element) {
console.log("coming to directive notifications")
element.on('click', function onClick() {
console.log("coming to directive notifications click")
if ((scope.notificationTitle) && (scope.notificationMsg)) {
webNotification.showNotification(scope.notificationTitle, {
body: scope.notificationMsg,
icon: 'https://lh3.googleusercontent.com/BCOE0vqCfr8aqpIKEF7QEt-qa7p8I7KDg58Juz6M6_YGb4l7phrO2vMvi_SDy10ucQ=w300',
onClick: function onNotificationClicked() {
console.log('Notification clicked.');
window.open(scope.notificationUrl, '_blank')
},
autoClose: 4000 //auto close the notification after 4 seconds (you can manually close it via hide function)
}, function onShow(error, hide) {
if (error) {
window.alert('Unable to show notification: ' + error.message);
} else {
console.log('Notification Shown.');
setTimeout(function hideNotification() {
console.log('Hiding notification....');
hide(); //manually close the notification (you can skip this if you use the autoClose option)
}, 5000);
}
});
}
});
}
};
}]);