MCPcopy Create free account
hub / github.com/angular/angular / unsubscribe

Method unsubscribe

packages/service-worker/src/push.ts:259–290  ·  view source on GitHub ↗

* Unsubscribes from Service Worker push notifications. * * @returns A Promise that is resolved when the operation succeeds, or is rejected if there is no * active subscription or the unsubscribe operation fails.

()

Source from the content-addressed store, hash-verified

257 * active subscription or the unsubscribe operation fails.
258 */
259 unsubscribe(): Promise<void> {
260 if (!this.sw.isEnabled) {
261 return Promise.reject(new Error(ERR_SW_NOT_SUPPORTED));
262 }
263
264 const doUnsubscribe = (sub: PushSubscription | null) => {
265 if (sub === null) {
266 throw new RuntimeError(
267 RuntimeErrorCode.NOT_SUBSCRIBED_TO_PUSH_NOTIFICATIONS,
268 (typeof ngDevMode === 'undefined' || ngDevMode) &&
269 'Not subscribed to push notifications.',
270 );
271 }
272
273 return sub.unsubscribe().then((success) => {
274 if (!success) {
275 throw new RuntimeError(
276 RuntimeErrorCode.PUSH_SUBSCRIPTION_UNSUBSCRIBE_FAILED,
277 (typeof ngDevMode === 'undefined' || ngDevMode) && 'Unsubscribe failed!',
278 );
279 }
280
281 this.subscriptionChanges.next(null);
282 });
283 };
284
285 return new Promise((resolve, reject) => {
286 this.subscription
287 .pipe(take(1), switchMap(doUnsubscribe))
288 .subscribe({next: resolve, error: reject});
289 });
290 }
291
292 private decodeBase64(input: string): string {
293 return atob(input);

Callers

nothing calls this directly

Calls 3

takeFunction · 0.85
subscribeMethod · 0.65
rejectMethod · 0.45

Tested by

no test coverage detected