@angular/service-worker
Version:
Angular - service worker tooling!
34 lines • 7.42 kB
JavaScript
/**
* @license Angular v7.0.2
* (c) 2010-2018 Google, Inc. https://angular.io/
* License: MIT
*/
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("rxjs"),require("rxjs/operators"),require("@angular/core"),require("@angular/common")):"function"==typeof define&&define.amd?define("@angular/service-worker",["exports","rxjs","rxjs/operators","@angular/core","@angular/common"],r):r((e.ng=e.ng||{},e.ng.serviceWorker={}),e.rxjs,e.rxjs.operators,e.ng.core,e.ng.common)}(this,function(e,r,t,n,i){"use strict";var o=function(){return(o=Object.assign||function e(r){for(var t,n=1,i=arguments.length;n<i;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(r[o]=t[o]);return r}).apply(this,arguments)};function s(e,r,t,n){var i,o=arguments.length,s=o<3?r:null===n?n=Object.getOwnPropertyDescriptor(r,t):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,r,t,n);else for(var a=e.length-1;a>=0;a--)(i=e[a])&&(s=(o<3?i(s):o>3?i(r,t,s):i(r,t))||s);return o>3&&s&&Object.defineProperty(r,t,s),s}function a(e,r){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,r)}
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/var u="Service workers are disabled or not supported by this browser",c=function(){function e(e){if(this.serviceWorker=e,e){var n=r.fromEvent(e,"controllerchange").pipe(t.map(function(){return e.controller})),i=r.defer(function(){return r.of(e.controller)}),o=r.concat(i,n);this.worker=o.pipe(t.filter(function(e){return!!e})),this.registration=this.worker.pipe(t.switchMap(function(){return e.getRegistration()}));var s=r.fromEvent(e,"message").pipe(t.map(function(e){return e.data})).pipe(t.filter(function(e){return e&&e.type})).pipe(t.publish());s.connect(),this.events=s}else this.worker=this.events=this.registration=function a(e){return r.defer(function(){return r.throwError(new Error(e))})}(u)}return e.prototype.postMessage=function(e,r){return this.worker.pipe(t.take(1),t.tap(function(t){t.postMessage(o({action:e},r))})).toPromise().then(function(){})},e.prototype.postMessageWithStatus=function(e,r,t){var n=this.waitForStatus(t),i=this.postMessage(e,r);return Promise.all([n,i]).then(function(){})},e.prototype.generateNonce=function(){return Math.round(1e7*Math.random())},e.prototype.eventsOfType=function(e){return this.events.pipe(t.filter(function(r){return r.type===e}))},e.prototype.nextEventOfType=function(e){return this.eventsOfType(e).pipe(t.take(1))},e.prototype.waitForStatus=function(e){return this.eventsOfType("STATUS").pipe(t.filter(function(r){return r.nonce===e}),t.take(1),t.map(function(e){if(!e.status)throw new Error(e.error)})).toPromise()},Object.defineProperty(e.prototype,"isEnabled",{get:function(){return!!this.serviceWorker},enumerable:!0,configurable:!0}),e}(),p=function(){function e(e){if(this.sw=e,this.subscriptionChanges=new r.Subject,!e.isEnabled)return this.messages=r.NEVER,void(this.subscription=r.NEVER);this.messages=this.sw.eventsOfType("PUSH").pipe(t.map(function(e){return e.data})),this.pushManager=this.sw.registration.pipe(t.map(function(e){return e.pushManager}));var n=this.pushManager.pipe(t.switchMap(function(e){return e.getSubscription()}));this.subscription=r.merge(n,this.subscriptionChanges)}return Object.defineProperty(e.prototype,"isEnabled",{get:function(){return this.sw.isEnabled},enumerable:!0,configurable:!0}),e.prototype.requestSubscription=function(e){var r=this;if(!this.sw.isEnabled)return Promise.reject(new Error(u));for(var n={userVisibleOnly:!0},i=this.decodeBase64(e.serverPublicKey.replace(/_/g,"/").replace(/-/g,"+")),o=new Uint8Array(new ArrayBuffer(i.length)),s=0;s<i.length;s++)o[s]=i.charCodeAt(s);return n.applicationServerKey=o,this.pushManager.pipe(t.switchMap(function(e){return e.subscribe(n)}),t.take(1)).toPromise().then(function(e){return r.subscriptionChanges.next(e),e})},e.prototype.unsubscribe=function(){var e=this;return this.sw.isEnabled?this.subscription.pipe(t.take(1),t.switchMap(function(r){if(null===r)throw new Error("Not subscribed to push notifications.");return r.unsubscribe().then(function(r){if(!r)throw new Error("Unsubscribe failed!");e.subscriptionChanges.next(null)})})).toPromise():Promise.reject(new Error(u))},e.prototype.decodeBase64=function(e){return atob(e)},s([n.Injectable(),a("design:paramtypes",[c])],e)}(),f=function(){function e(e){if(this.sw=e,!e.isEnabled)return this.available=r.NEVER,void(this.activated=r.NEVER);this.available=this.sw.eventsOfType("UPDATE_AVAILABLE"),this.activated=this.sw.eventsOfType("UPDATE_ACTIVATED")}return Object.defineProperty(e.prototype,"isEnabled",{get:function(){return this.sw.isEnabled},enumerable:!0,configurable:!0}),e.prototype.checkForUpdate=function(){if(!this.sw.isEnabled)return Promise.reject(new Error(u));var e=this.sw.generateNonce();return this.sw.postMessageWithStatus("CHECK_FOR_UPDATES",{statusNonce:e},e)},e.prototype.activateUpdate=function(){if(!this.sw.isEnabled)return Promise.reject(new Error(u));var e=this.sw.generateNonce();return this.sw.postMessageWithStatus("ACTIVATE_UPDATE",{statusNonce:e},e)},s([n.Injectable(),a("design:paramtypes",[c])],e)}(),l=function l(){},h=new n.InjectionToken("NGSW_REGISTER_SCRIPT");function g(e,r,o,s){return function(){var a=e.get(n.ApplicationRef);if(i.isPlatformBrowser(s)&&"serviceWorker"in navigator&&!1!==o.enabled){var u=a.isStable.pipe(t.filter(function(e){return!!e}),t.take(1)).toPromise();navigator.serviceWorker.addEventListener("controllerchange",function(){null!==navigator.serviceWorker.controller&&navigator.serviceWorker.controller.postMessage({action:"INITIALIZE"})}),u.then(function(){return navigator.serviceWorker.register(r,{scope:o.scope})})}}}function v(e,r){return new c(i.isPlatformBrowser(r)&&!1!==e.enabled?navigator.serviceWorker:void 0)}var d=function(){function e(){}var r;return r=e,e.register=function(e,t){return void 0===t&&(t={}),{ngModule:r,providers:[{provide:h,useValue:e},{provide:l,useValue:t},{provide:c,useFactory:v,deps:[l,n.PLATFORM_ID]},{provide:n.APP_INITIALIZER,useFactory:g,deps:[n.Injector,h,l,n.PLATFORM_ID],multi:!0}]}},r=s([n.NgModule({providers:[p,f]})],e)}();
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/e.ɵangular_packages_service_worker_service_worker_a=c,e.ɵangular_packages_service_worker_service_worker_b=l,e.ɵangular_packages_service_worker_service_worker_c=h,e.ɵangular_packages_service_worker_service_worker_d=g,e.ɵangular_packages_service_worker_service_worker_e=v,e.ServiceWorkerModule=d,e.SwPush=p,e.SwUpdate=f,Object.defineProperty(e,"__esModule",{value:!0})});