question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How we can use it?

See original GitHub issue

Hi 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

  1. https://github.com/sagiegurari/angular-web-notification
  2. https://github.com/jmsanpascual/angular-desktop-notification
  3. 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:closed
  • Created 6 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
narendrasinghrathorecommented, Jun 21, 2017

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.

2reactions
sagieguraricommented, Jun 20, 2017

So if I understand correctly (might not, hard to understand the flow from your question),

  1. service worker gets some event and than shows web notification
  2. you want angular app to do some http call when service worker shows a notification am I right?
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found