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