(private sw: NgswCommChannel)
| 174 | private subscriptionChanges = new Subject<PushSubscription | null>(); |
| 175 | |
| 176 | constructor(private sw: NgswCommChannel) { |
| 177 | if (!sw.isEnabled) { |
| 178 | this.messages = NEVER; |
| 179 | this.notificationClicks = NEVER; |
| 180 | this.notificationCloses = NEVER; |
| 181 | this.pushSubscriptionChanges = NEVER; |
| 182 | this.subscription = NEVER; |
| 183 | return; |
| 184 | } |
| 185 | |
| 186 | this.messages = this.sw.eventsOfType<PushEvent>('PUSH').pipe(map((message) => message.data)); |
| 187 | |
| 188 | this.notificationClicks = this.sw |
| 189 | .eventsOfType('NOTIFICATION_CLICK') |
| 190 | .pipe(map((message: any) => message.data)); |
| 191 | |
| 192 | this.notificationCloses = this.sw |
| 193 | .eventsOfType('NOTIFICATION_CLOSE') |
| 194 | .pipe(map((message: any) => message.data)); |
| 195 | |
| 196 | this.pushSubscriptionChanges = this.sw |
| 197 | .eventsOfType('PUSH_SUBSCRIPTION_CHANGE') |
| 198 | .pipe(map((message: any) => message.data)); |
| 199 | |
| 200 | this.pushManager = this.sw.registration.pipe( |
| 201 | map( |
| 202 | (registration) => |
| 203 | (registration as ServiceWorkerRegistration & {pushManager: PushManager}).pushManager, |
| 204 | ), |
| 205 | ); |
| 206 | |
| 207 | const workerDrivenSubscriptions = this.pushManager.pipe( |
| 208 | switchMap((pm) => pm.getSubscription()), |
| 209 | ); |
| 210 | this.subscription = new Observable((subscriber) => { |
| 211 | const workerDrivenSubscription = workerDrivenSubscriptions.subscribe(subscriber); |
| 212 | const subscriptionChanges = this.subscriptionChanges.subscribe(subscriber); |
| 213 | return () => { |
| 214 | workerDrivenSubscription.unsubscribe(); |
| 215 | subscriptionChanges.unsubscribe(); |
| 216 | }; |
| 217 | }); |
| 218 | } |
| 219 | |
| 220 | /** |
| 221 | * Subscribes to Web Push Notifications, |
nothing calls this directly
no test coverage detected