1 | import { ɵgetAllInstancesOf, ɵisMessagingSupportedFactory, ɵgetDefaultInstanceOf, VERSION, ɵAngularFireSchedulers, ɵzoneWrap } from '@angular/fire';
|
2 | import { timer, from } from 'rxjs';
|
3 | import { concatMap, distinct } from 'rxjs/operators';
|
4 | import * as i0 from '@angular/core';
|
5 | import { InjectionToken, Optional, APP_INITIALIZER, NgModule, NgZone, Injector } from '@angular/core';
|
6 | import { FirebaseApp, FirebaseApps } from '@angular/fire/app';
|
7 | import { registerVersion } from 'firebase/app';
|
8 | import { deleteToken as deleteToken$1, getMessaging as getMessaging$1, getToken as getToken$1, onMessage as onMessage$1 } from 'firebase/messaging';
|
9 | export * from 'firebase/messaging';
|
10 |
|
11 | class Messaging {
|
12 | constructor(messaging) {
|
13 | return messaging;
|
14 | }
|
15 | }
|
16 | const MESSAGING_PROVIDER_NAME = 'messaging';
|
17 | class MessagingInstances {
|
18 | constructor() {
|
19 | return ɵgetAllInstancesOf(MESSAGING_PROVIDER_NAME);
|
20 | }
|
21 | }
|
22 | const messagingInstance$ = timer(0, 300).pipe(concatMap(() => from(ɵgetAllInstancesOf(MESSAGING_PROVIDER_NAME))), distinct());
|
23 |
|
24 | const PROVIDED_MESSAGING_INSTANCES = new InjectionToken('angularfire2.messaging-instances');
|
25 | function defaultMessagingInstanceFactory(provided, defaultApp) {
|
26 | if (!ɵisMessagingSupportedFactory.sync()) {
|
27 | return null;
|
28 | }
|
29 | const defaultMessaging = ɵgetDefaultInstanceOf(MESSAGING_PROVIDER_NAME, provided, defaultApp);
|
30 | return defaultMessaging && new Messaging(defaultMessaging);
|
31 | }
|
32 | function messagingInstanceFactory(fn) {
|
33 | return (zone, injector) => {
|
34 | if (!ɵisMessagingSupportedFactory.sync()) {
|
35 | return null;
|
36 | }
|
37 | const messaging = zone.runOutsideAngular(() => fn(injector));
|
38 | return new Messaging(messaging);
|
39 | };
|
40 | }
|
41 | const MESSAGING_INSTANCES_PROVIDER = {
|
42 | provide: MessagingInstances,
|
43 | deps: [
|
44 | [new Optional(), PROVIDED_MESSAGING_INSTANCES],
|
45 | ]
|
46 | };
|
47 | const DEFAULT_MESSAGING_INSTANCE_PROVIDER = {
|
48 | provide: Messaging,
|
49 | useFactory: defaultMessagingInstanceFactory,
|
50 | deps: [
|
51 | [new Optional(), PROVIDED_MESSAGING_INSTANCES],
|
52 | FirebaseApp,
|
53 | ]
|
54 | };
|
55 | class MessagingModule {
|
56 | constructor() {
|
57 | registerVersion('angularfire', VERSION.full, 'fcm');
|
58 | }
|
59 | }
|
60 | MessagingModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0, type: MessagingModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
61 | MessagingModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0, type: MessagingModule });
|
62 | MessagingModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0, type: MessagingModule, providers: [
|
63 | DEFAULT_MESSAGING_INSTANCE_PROVIDER,
|
64 | MESSAGING_INSTANCES_PROVIDER,
|
65 | {
|
66 | provide: APP_INITIALIZER,
|
67 | useValue: ɵisMessagingSupportedFactory.async,
|
68 | multi: true,
|
69 | },
|
70 | ] });
|
71 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0, type: MessagingModule, decorators: [{
|
72 | type: NgModule,
|
73 | args: [{
|
74 | providers: [
|
75 | DEFAULT_MESSAGING_INSTANCE_PROVIDER,
|
76 | MESSAGING_INSTANCES_PROVIDER,
|
77 | {
|
78 | provide: APP_INITIALIZER,
|
79 | useValue: ɵisMessagingSupportedFactory.async,
|
80 | multi: true,
|
81 | },
|
82 | ]
|
83 | }]
|
84 | }], ctorParameters: function () { return []; } });
|
85 | function provideMessaging(fn, ...deps) {
|
86 | return {
|
87 | ngModule: MessagingModule,
|
88 | providers: [{
|
89 | provide: PROVIDED_MESSAGING_INSTANCES,
|
90 | useFactory: messagingInstanceFactory(fn),
|
91 | multi: true,
|
92 | deps: [
|
93 | NgZone,
|
94 | Injector,
|
95 | ɵAngularFireSchedulers,
|
96 | FirebaseApps,
|
97 | ...deps,
|
98 | ],
|
99 | }]
|
100 | };
|
101 | }
|
102 |
|
103 | const isSupported = ɵisMessagingSupportedFactory.async;
|
104 |
|
105 |
|
106 | const deleteToken = ɵzoneWrap(deleteToken$1, true);
|
107 | const getMessaging = ɵzoneWrap(getMessaging$1, true);
|
108 | const getToken = ɵzoneWrap(getToken$1, true);
|
109 | const onMessage = ɵzoneWrap(onMessage$1, false);
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 | export { Messaging, MessagingInstances, MessagingModule, deleteToken, getMessaging, getToken, isSupported, messagingInstance$, onMessage, provideMessaging };
|
116 |
|