How we can use it?
See original GitHub issueHi there, i need some help on this angular-web-notification.
Let me first explain it, i am using the code below which register to service worker and i get push notification in chrome i.e sw.js( name of file ) `use strict’;
const applicationServerPublicKey = 'key';
function urlB64ToUint8Array(base64String) {
const padding = '='.repeat((4 - base64String.length % 4) % 4);
const base64 = (base64String + padding)
.replace(/\-/g, '+')
.replace(/_/g, '/');
const rawData = window.atob(base64);
const outputArray = new Uint8Array(rawData.length);
for (var i = 0; i < rawData.length; ++i) {
outputArray[i] = rawData.charCodeAt(i);
}
return outputArray;
}
self.addEventListener('push', function(event) {
console.log('[Service Worker] Push Received.');
// console.log(`[Service Worker] Push had this data: "${event.data.text()}"`);
console.log(event.data);
console.log(event.data.json());
console.log(typeof (event.data.json()));
console.log(event);
const title = 'xyz';
const options = {
body: 'Message Received \n ' + event.data.json().message,
icon: 'images/icon.png',
// badge: 'images/badge.png',
data : event.data.json()
};
event.waitUntil(self.registration.showNotification(title, options));
});
self.addEventListener('notificationclick', function(event) {
console.log('[Service Worker] Notification click Received.');
event.notification.close();
event.waitUntil(
clients.openWindow('url');
);
});
self.addEventListener('pushsubscriptionchange', function(event) {
console.log('[Service Worker]: \'pushsubscriptionchange\' event fired.');
const applicationServerKey = urlB64ToUint8Array(applicationServerPublicKey);
event.waitUntil(
self.registration.pushManager.subscribe({
userVisibleOnly: true,
applicationServerKey: applicationServerKey
})
.then(function(newSubscription) {
console.log('[Service Worker] New subscription: ', newSubscription);
})
);
});`
`if ('serviceWorker' in navigator && 'PushManager' in window) {
navigator.serviceWorker.register('../sw.js')
.then(function (swReg) {
onServiceWorkerReady(swReg);
swRegistration.pushManager.subscribe({
userVisibleOnly: true,
applicationServerKey: applicationServerKey
})
.then(function (subscription) {
updateSubscriptionOnServer(subscription);
isSubscribed = true;
//updateBtn();
})
.catch(function (err) {
console.log('Failed to subscribe the user: ', err);
// updateBtn();
// });
})
.catch(function (error) {
console.error('Service Worker Error', error);
});
} else {
console.warn('Push messaging is not supported');
//pushButton.textContent = 'Push Not Supported';
}
`
What i need is that when i get notification from web-server , i also need my angular-app to perform some action. By using the above, i am not able catch any event or maybe i don’t know how to do that. Links i try to figured out
- https://github.com/sagiegurari/angular-web-notification
- https://github.com/jmsanpascual/angular-desktop-notification
- https://github.com/matiboy/angular-browser-push-notifications
I cannot exactly figure out, how i suppose to use your lib that help me to perform action in angular-app whenever i push notification or service worker get push notification.
Thank you,
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Uses of It @ The Internet Grammar of English
Uses of It · What time is it? It is four o'clock. It is snowing. It's going to rain · Hold it! Take...
Read more >Usage of "How can we" and "How we can" in the following case
The first sentence is grammatical, whereas the second one is not so. The phrase "Would you mind" is in the interrogative.
Read more >Learn English Grammar: USE, USED, and USED TO - YouTube
How do you use the verb USE ? The answer is, in several different ways! In this lesson, I will explain how to...
Read more >How we can use the hiring process to bring out the best in ...
Traditional job interviews are stressful interrogations that can often exclude marginalized populations. Here's how psychologist and ...
Read more >The Most Common Words in English: 8 ways to use 'THAT'
In this lesson, I will teach you eight different uses of 'that'. We 'll look at grammar as well as common expressions THAT...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
No issues. In case if you have something feel free to write here, it will help me. You can close it if you want. Thank you very much.
So if I understand correctly (might not, hard to understand the flow from your question),