This repository has been archived by the owner on Apr 2, 2018. It is now read-only.
/
index.ts
152 lines (125 loc) · 3.86 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
export * from '@ionic/cloud';
import { Observable } from 'rxjs';
import { Injectable, ModuleWithProviders, NgModule, OpaqueToken } from '@angular/core';
import {
Auth as _Auth,
FacebookAuth as _FacebookAuth,
GoogleAuth as _GoogleAuth,
Client as _Client,
CloudSettings,
Config as _Config,
Deploy as _Deploy,
DIContainer as _DIContainer,
EventHandler,
IEventEmitter,
IAuth,
IClient,
IConfig,
IDeploy,
IFacebookAuth,
IGoogleAuth,
IPush as _IPush,
IPushMessage,
IUser,
Insights as _Insights,
Push as _Push,
PushNotificationEvent,
User as _User,
} from '@ionic/cloud';
export class Rx {
constructor(protected emitter: IEventEmitter) {}
}
export class PushRx extends Rx {
notification(): Observable<IPushMessage> {
return Observable.fromEventPattern<IPushMessage>((h: EventHandler) => {
return this.emitter.on('push:notification', (data: PushNotificationEvent) => {
return h(data.message);
});
}, (_: Function) => {
// https://github.com/ReactiveX/rxjs/issues/1900
// this.emitter.off(signal);
});
}
}
export interface IPush extends _IPush {
rx: PushRx;
}
@Injectable()
export class FacebookAuth extends _FacebookAuth {}
@Injectable()
export class GoogleAuth extends _GoogleAuth {}
@Injectable()
export class Auth extends _Auth {}
@Injectable()
export class Client extends _Client {}
@Injectable()
export class Config extends _Config {}
@Injectable()
export class Deploy extends _Deploy {}
@Injectable()
export class DIContainer extends _DIContainer {}
@Injectable()
export class Insights extends _Insights {}
@Injectable()
export class Push extends _Push implements IPush {
/**
* Observables for the push service.
*/
public rx: PushRx;
}
@Injectable()
export class User extends _User {}
export const CloudSettingsToken = new OpaqueToken('CloudSettings');
export function provideContainer(settings: CloudSettings): DIContainer {
let container = new DIContainer();
container.config.register(settings);
container.core.init();
container.cordova.bootstrap();
return container;
}
export function provideConfig(container: DIContainer): IConfig {
return container.config;
}
export function provideAuth(container: DIContainer): IAuth {
return container.auth;
}
export function provideClient(container: DIContainer): IClient {
return container.client;
}
export function provideDeploy(container: DIContainer): IDeploy {
return container.deploy;
}
export function provideUser(container: DIContainer): IUser {
return container.singleUserService.current();
}
export function providePush(container: DIContainer): IPush {
let push = container.push as IPush;
push.rx = new PushRx(container.eventEmitter);
return push;
}
export function provideFacebookAuth(container: DIContainer): IFacebookAuth {
return container.facebookAuth;
}
export function provideGoogleAuth(container: DIContainer): IGoogleAuth {
return container.googleAuth;
}
@NgModule()
export class CloudModule {
static forRoot(settings: CloudSettings): ModuleWithProviders {
return {
ngModule: CloudModule,
providers: [
{ provide: CloudSettingsToken, useValue: settings },
{ provide: DIContainer, useFactory: provideContainer, deps: [ CloudSettingsToken ] },
{ provide: Auth, useFactory: provideAuth, deps: [ DIContainer ] },
{ provide: Client, useFactory: provideClient, deps: [ DIContainer ] },
{ provide: Config, useFactory: provideConfig, deps: [ DIContainer ] },
{ provide: Deploy, useFactory: provideDeploy, deps: [ DIContainer ] },
{ provide: Push, useFactory: providePush, deps: [ DIContainer ] },
{ provide: User, useFactory: provideUser, deps: [ DIContainer ] },
{ provide: FacebookAuth, useFactory: provideFacebookAuth, deps: [ DIContainer ]},
{ provide: GoogleAuth, useFactory: provideGoogleAuth, deps: [ DIContainer ]}
]
};
}
}