Skip to content

Commit

Permalink
push
Browse files Browse the repository at this point in the history
  • Loading branch information
Bharat23 committed Jul 12, 2018
1 parent b2f3176 commit dae3c49
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 13 deletions.
Binary file added .DS_Store
Binary file not shown.
6 changes: 3 additions & 3 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ <h2 class="mdl-card__title-text">Welcome</h2>
var registerServiceWorker = () => {
var success = (reg) => {
console.log('Service Worker Registered Successfully', reg);
return reg.pushManager.getSubscription()
// return reg.pushManager.getSubscription()
};
let subscribe = (subscribeState) => {
if (subscribeState === null) {
Expand All @@ -179,9 +179,9 @@ <h2 class="mdl-card__title-text">Welcome</h2>
console.log('Service worker registeration failed', err);
};
if('serviceWorker' in navigator){
navigator.serviceWorker.register('/sw-wb.js')
navigator.serviceWorker.register('/my-sw-new.js')
.then(success)
.then(subscribe)
// .then(subscribe)
.catch(error);
}
};
Expand Down
38 changes: 38 additions & 0 deletions app/my-sw-new.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const CACHE_NAME = 'cache_v1';

const PRECACHE_LIST = [
'/static/js/material.min.js',
'/static/css/material.min.css',
'/index.html',
'/',
];

self.addEventListener('install', (e) => {
e.waitUntil(
caches
.open(CACHE_NAME)
.then(cache => {
return cache.addAll(PRECACHE_LIST);
})
);
});

self.addEventListener('fetch', e => {
e.respondWith(
caches.match(e.request)
.then(response => {
if (response) {
return response;
}

let requestClone = e.request.clone();
return fetch(requestClone)
.then((res) => {
if (!res || res.status !== 200 || res.type !== 'basic') {
return res;
}
})

})
);
});
Binary file added app/static/.DS_Store
Binary file not shown.
20 changes: 10 additions & 10 deletions app/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,16 @@ const changeButtonStatus = (status) => {
};

const subscribeForPush = () => {
navigator.serviceWorker.ready
.then((reg) => {
console.log('here', reg);
reg.pushManager.subscribe({ userVisibleOnly: true })
.then(subscribe => {
console.log(subscribe.endpoint, 'subscribed');
storeSubscriptionDetails(subscribe.endpoint);
})
.catch(err => console.error(err));
})
// navigator.serviceWorker.ready
// .then((reg) => {
// console.log('here', reg);
// reg.pushManager.subscribe({ userVisibleOnly: true })
// .then(subscribe => {
// console.log(subscribe.endpoint, 'subscribed');
// storeSubscriptionDetails(subscribe.endpoint);
// })
// .catch(err => console.error(err));
// })
};

const subscribeToNotification = () => {
Expand Down

0 comments on commit dae3c49

Please sign in to comment.