feat(service-worker): handle 'notificationclick' events (#25860)

The previous version did not support the 'notificationclick' event.
Add event handler for the event and provide an observable of
clicked notifications in the SwPush service.

Closes #20956, #22311

PR Close #25860
This commit is contained in:
Joost Zoellner
2018-09-07 14:56:40 +02:00
committed by Kara Erickson
parent ea0a99610d
commit cf6ea283bb
8 changed files with 80 additions and 0 deletions

View File

@ -25,6 +25,8 @@ export class SwPush {
*/
readonly messages: Observable<object>;
readonly messagesClicked: Observable<object>;
/**
* Emits the currently active
* [PushSubscription](https://developer.mozilla.org/en-US/docs/Web/API/PushSubscription)
@ -45,12 +47,16 @@ export class SwPush {
constructor(private sw: NgswCommChannel) {
if (!sw.isEnabled) {
this.messages = NEVER;
this.messagesClicked = NEVER;
this.subscription = NEVER;
return;
}
this.messages = this.sw.eventsOfType<PushEvent>('PUSH').pipe(map(message => message.data));
this.messagesClicked =
this.sw.eventsOfType('NOTIFICATION_CLICK').pipe(map((message: any) => message.data));
this.pushManager = this.sw.registration.pipe(map(registration => registration.pushManager));
const workerDrivenSubscriptions = this.pushManager.pipe(switchMap(pm => pm.getSubscription()));