1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | import * as i0 from '@angular/core';
|
9 | import { ModuleWithProviders } from '@angular/core';
|
10 | import { Observable } from 'rxjs';
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | declare class NgswCommChannel {
|
16 | private serviceWorker;
|
17 | readonly worker: Observable<ServiceWorker>;
|
18 | readonly registration: Observable<ServiceWorkerRegistration>;
|
19 | readonly events: Observable<TypedEvent>;
|
20 | constructor(serviceWorker: ServiceWorkerContainer | undefined);
|
21 | postMessage(action: string, payload: Object): Promise<void>;
|
22 | postMessageWithOperation(type: string, payload: Object, operationNonce: number): Promise<boolean>;
|
23 | generateNonce(): number;
|
24 | eventsOfType<T extends TypedEvent>(type: T['type'] | T['type'][]): Observable<T>;
|
25 | nextEventOfType<T extends TypedEvent>(type: T['type']): Observable<T>;
|
26 | waitForOperationCompleted(nonce: number): Promise<boolean>;
|
27 | get isEnabled(): boolean;
|
28 | }
|
29 |
|
30 | /**
|
31 | * An event emitted when the service worker has checked the version of the app on the server and it
|
32 | * didn't find a new version that it doesn't have already downloaded.
|
33 | *
|
34 | * @see {@link guide/service-worker-communications Service worker communication guide}
|
35 | *
|
36 | * @publicApi
|
37 | */
|
38 | declare interface NoNewVersionDetectedEvent {
|
39 | type: 'NO_NEW_VERSION_DETECTED';
|
40 | version: {
|
41 | hash: string;
|
42 | appData?: Object;
|
43 | };
|
44 | }
|
45 |
|
46 |
|
47 |
|
48 |
|
49 | export declare class ServiceWorkerModule {
|
50 | |
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 | static register(script: string, opts?: SwRegistrationOptions): ModuleWithProviders<ServiceWorkerModule>;
|
57 | static ɵfac: i0.ɵɵFactoryDeclaration<ServiceWorkerModule, never>;
|
58 | static ɵmod: i0.ɵɵNgModuleDeclaration<ServiceWorkerModule, never, never, never>;
|
59 | static ɵinj: i0.ɵɵInjectorDeclaration<ServiceWorkerModule>;
|
60 | }
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 | export declare class SwPush {
|
142 | private sw;
|
143 | |
144 |
|
145 |
|
146 | readonly messages: Observable<object>;
|
147 | |
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 | readonly notificationClicks: Observable<{
|
159 | action: string;
|
160 | notification: NotificationOptions & {
|
161 | title: string;
|
162 | };
|
163 | }>;
|
164 | |
165 |
|
166 |
|
167 |
|
168 |
|
169 | readonly subscription: Observable<PushSubscription | null>;
|
170 | |
171 |
|
172 |
|
173 |
|
174 | get isEnabled(): boolean;
|
175 | private pushManager;
|
176 | private subscriptionChanges;
|
177 | constructor(sw: NgswCommChannel);
|
178 | /**
|
179 | * Subscribes to Web Push Notifications,
|
180 | * after requesting and receiving user permission.
|
181 | *
|
182 | * @param options An object containing the `serverPublicKey` string.
|
183 | * @returns A Promise that resolves to the new subscription object.
|
184 | */
|
185 | requestSubscription(options: {
|
186 | serverPublicKey: string;
|
187 | }): Promise<PushSubscription>;
|
188 | /**
|
189 | * Unsubscribes from Service Worker push notifications.
|
190 | *
|
191 | * @returns A Promise that is resolved when the operation succeeds, or is rejected if there is no
|
192 | * active subscription or the unsubscribe operation fails.
|
193 | */
|
194 | unsubscribe(): Promise<void>;
|
195 | private decodeBase64;
|
196 | static ɵfac: i0.ɵɵFactoryDeclaration<SwPush, never>;
|
197 | static ɵprov: i0.ɵɵInjectableDeclaration<SwPush>;
|
198 | }
|
199 |
|
200 | /**
|
201 | * Token that can be used to provide options for `ServiceWorkerModule` outside of
|
202 | * `ServiceWorkerModule.register()`.
|
203 | *
|
204 | * You can use this token to define a provider that generates the registration options at runtime,
|
205 | * for example via a function call:
|
206 | *
|
207 | * {@example service-worker/registration-options/module.ts region="registration-options"
|
208 | * header="app.module.ts"}
|
209 | *
|
210 | * @publicApi
|
211 | */
|
212 | export declare abstract class SwRegistrationOptions {
|
213 | |
214 |
|
215 |
|
216 |
|
217 |
|
218 |
|
219 | enabled?: boolean;
|
220 | |
221 |
|
222 |
|
223 |
|
224 |
|
225 | scope?: string;
|
226 | |
227 |
|
228 |
|
229 |
|
230 |
|
231 |
|
232 |
|
233 |
|
234 |
|
235 |
|
236 |
|
237 |
|
238 |
|
239 |
|
240 |
|
241 |
|
242 |
|
243 |
|
244 |
|
245 |
|
246 |
|
247 |
|
248 |
|
249 |
|
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 | registrationStrategy?: string | (() => Observable<unknown>);
|
256 | }
|
257 |
|
258 | /**
|
259 | * Subscribe to update notifications from the Service Worker, trigger update
|
260 | * checks, and forcibly activate updates.
|
261 | *
|
262 | * @see {@link guide/service-worker-communications Service worker communication guide}
|
263 | *
|
264 | * @publicApi
|
265 | */
|
266 | export declare class SwUpdate {
|
267 | private sw;
|
268 | /**
|
269 | * Emits a `VersionDetectedEvent` event whenever a new version is detected on the server.
|
270 | *
|
271 | * Emits a `VersionInstallationFailedEvent` event whenever checking for or downloading a new
|
272 | * version fails.
|
273 | *
|
274 | * Emits a `VersionReadyEvent` event whenever a new version has been downloaded and is ready for
|
275 | * activation.
|
276 | */
|
277 | readonly versionUpdates: Observable<VersionEvent>;
|
278 | /**
|
279 | * Emits an `UpdateAvailableEvent` event whenever a new app version is available.
|
280 | *
|
281 | * @deprecated Use {@link versionUpdates} instead.
|
282 | *
|
283 | * The of behavior `available` can be rebuild by filtering for the `VersionReadyEvent`:
|
284 | * ```
|
285 | * import {filter, map} from 'rxjs/operators';
|
286 | * // ...
|
287 | * const updatesAvailable = swUpdate.versionUpdates.pipe(
|
288 | * filter((evt): evt is VersionReadyEvent => evt.type === 'VERSION_READY'),
|
289 | * map(evt => ({
|
290 | * type: 'UPDATE_AVAILABLE',
|
291 | * current: evt.currentVersion,
|
292 | * available: evt.latestVersion,
|
293 | * })));
|
294 | * ```
|
295 | */
|
296 | readonly available: Observable<UpdateAvailableEvent>;
|
297 | /**
|
298 | * Emits an `UpdateActivatedEvent` event whenever the app has been updated to a new version.
|
299 | *
|
300 | * @deprecated Use the return value of {@link SwUpdate#activateUpdate} instead.
|
301 | *
|
302 | */
|
303 | readonly activated: Observable<UpdateActivatedEvent>;
|
304 | /**
|
305 | * Emits an `UnrecoverableStateEvent` event whenever the version of the app used by the service
|
306 | * worker to serve this client is in a broken state that cannot be recovered from without a full
|
307 | * page reload.
|
308 | */
|
309 | readonly unrecoverable: Observable<UnrecoverableStateEvent>;
|
310 | /**
|
311 | * True if the Service Worker is enabled (supported by the browser and enabled via
|
312 | * `ServiceWorkerModule`).
|
313 | */
|
314 | get isEnabled(): boolean;
|
315 | constructor(sw: NgswCommChannel);
|
316 | /**
|
317 | * Checks for an update and waits until the new version is downloaded from the server and ready
|
318 | * for activation.
|
319 | *
|
320 | * @returns a promise that
|
321 | * - resolves to `true` if a new version was found and is ready to be activated.
|
322 | * - resolves to `false` if no new version was found
|
323 | * - rejects if any error occurs
|
324 | */
|
325 | checkForUpdate(): Promise<boolean>;
|
326 | /**
|
327 | * Updates the current client (i.e. browser tab) to the latest version that is ready for
|
328 | * activation.
|
329 | *
|
330 | * @returns a promise that
|
331 | * - resolves to `true` if an update was activated successfully
|
332 | * - resolves to `false` if no update was available (for example, the client was already on the
|
333 | * latest version).
|
334 | * - rejects if any error occurs
|
335 | */
|
336 | activateUpdate(): Promise<boolean>;
|
337 | static ɵfac: i0.ɵɵFactoryDeclaration<SwUpdate, never>;
|
338 | static ɵprov: i0.ɵɵInjectableDeclaration<SwUpdate>;
|
339 | }
|
340 |
|
341 | declare interface TypedEvent {
|
342 | type: string;
|
343 | }
|
344 |
|
345 | /**
|
346 | * An event emitted when the version of the app used by the service worker to serve this client is
|
347 | * in a broken state that cannot be recovered from and a full page reload is required.
|
348 | *
|
349 | * For example, the service worker may not be able to retrieve a required resource, neither from the
|
350 | * cache nor from the server. This could happen if a new version is deployed to the server and the
|
351 | * service worker cache has been partially cleaned by the browser, removing some files of a previous
|
352 | * app version but not all.
|
353 | *
|
354 | * @see {@link guide/service-worker-communications Service worker communication guide}
|
355 | *
|
356 | * @publicApi
|
357 | */
|
358 | export declare interface UnrecoverableStateEvent {
|
359 | type: 'UNRECOVERABLE_STATE';
|
360 | reason: string;
|
361 | }
|
362 |
|
363 | /**
|
364 | * An event emitted when a new version of the app has been downloaded and activated.
|
365 | *
|
366 | * @see {@link guide/service-worker-communications Service worker communication guide}
|
367 | *
|
368 | * @deprecated
|
369 | * This event is only emitted by the deprecated {@link SwUpdate#activated}.
|
370 | * Use the return value of {@link SwUpdate#activateUpdate} instead.
|
371 | *
|
372 | * @publicApi
|
373 | */
|
374 | export declare interface UpdateActivatedEvent {
|
375 | type: 'UPDATE_ACTIVATED';
|
376 | previous?: {
|
377 | hash: string;
|
378 | appData?: Object;
|
379 | };
|
380 | current: {
|
381 | hash: string;
|
382 | appData?: Object;
|
383 | };
|
384 | }
|
385 |
|
386 | /**
|
387 | * An event emitted when a new version of the app is available.
|
388 | *
|
389 | * @see {@link guide/service-worker-communications Service worker communication guide}
|
390 | *
|
391 | * @deprecated
|
392 | * This event is only emitted by the deprecated {@link SwUpdate#available}.
|
393 | * Use the {@link VersionReadyEvent} instead, which is emitted by {@link SwUpdate#versionUpdates}.
|
394 | * See {@link SwUpdate#available} docs for an example.
|
395 | *
|
396 | * @publicApi
|
397 | */
|
398 | export declare interface UpdateAvailableEvent {
|
399 | type: 'UPDATE_AVAILABLE';
|
400 | current: {
|
401 | hash: string;
|
402 | appData?: Object;
|
403 | };
|
404 | available: {
|
405 | hash: string;
|
406 | appData?: Object;
|
407 | };
|
408 | }
|
409 |
|
410 | /**
|
411 | * An event emitted when the service worker has detected a new version of the app on the server and
|
412 | * is about to start downloading it.
|
413 | *
|
414 | * @see {@link guide/service-worker-communications Service worker communication guide}
|
415 | *
|
416 | * @publicApi
|
417 | */
|
418 | export declare interface VersionDetectedEvent {
|
419 | type: 'VERSION_DETECTED';
|
420 | version: {
|
421 | hash: string;
|
422 | appData?: object;
|
423 | };
|
424 | }
|
425 |
|
426 | /**
|
427 | * A union of all event types that can be emitted by
|
428 | * {@link api/service-worker/SwUpdate#versionUpdates SwUpdate#versionUpdates}.
|
429 | *
|
430 | * @publicApi
|
431 | */
|
432 | export declare type VersionEvent = VersionDetectedEvent | VersionInstallationFailedEvent | VersionReadyEvent | NoNewVersionDetectedEvent;
|
433 |
|
434 | /**
|
435 | * An event emitted when the installation of a new version failed.
|
436 | * It may be used for logging/monitoring purposes.
|
437 | *
|
438 | * @see {@link guide/service-worker-communications Service worker communication guide}
|
439 | *
|
440 | * @publicApi
|
441 | */
|
442 | export declare interface VersionInstallationFailedEvent {
|
443 | type: 'VERSION_INSTALLATION_FAILED';
|
444 | version: {
|
445 | hash: string;
|
446 | appData?: object;
|
447 | };
|
448 | error: string;
|
449 | }
|
450 |
|
451 | /**
|
452 | * An event emitted when a new version of the app is available.
|
453 | *
|
454 | * @see {@link guide/service-worker-communications Service worker communication guide}
|
455 | *
|
456 | * @publicApi
|
457 | */
|
458 | export declare interface VersionReadyEvent {
|
459 | type: 'VERSION_READY';
|
460 | currentVersion: {
|
461 | hash: string;
|
462 | appData?: object;
|
463 | };
|
464 | latestVersion: {
|
465 | hash: string;
|
466 | appData?: object;
|
467 | };
|
468 | }
|
469 |
|
470 | export { }
|
471 |
|
\ | No newline at end of file |