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