Skip to content

Commit

Permalink
Implement unregister for Push API (#510)
Browse files Browse the repository at this point in the history
Implemented unregister function for push api.

ISSUE=none
  • Loading branch information
haeungun authored and romandev committed Nov 11, 2017
1 parent 1ab2f8f commit c2c3e05
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions client/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import absolute from './absolute';

async function main() {
console.log(await absolute.push.register('key'));
console.log(await absolute.push.unregister());
}

main();
25 changes: 22 additions & 3 deletions client/push/push_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ export default class PushManager {
}

async register(key: string): Promise<string> {
// Not implemented yet

if (navigator.serviceWorker) {
navigator.serviceWorker.register('/push_service_worker.js')
.then((registration: ServiceWorkerRegistration) => {
Expand Down Expand Up @@ -66,7 +64,28 @@ export default class PushManager {
}

async unregister(): Promise<boolean> {
// Not implemented yet
if (!navigator.serviceWorker) {
return false;
}

navigator.serviceWorker.ready
.then((registration: ServiceWorkerRegistration) => {
registration.pushManager.getSubscription()
.then((subscription: PushSubscription) => {
if (subscription) {
subscription.unsubscribe();
return true;
}
return false;
})
.catch((error: Error) => {
// Not implemented yet
})
})
.catch((error: Error) => {
// Not implemented yet
})

return false;
}
}

0 comments on commit c2c3e05

Please sign in to comment.