-
Notifications
You must be signed in to change notification settings - Fork 115
/
ContextHelper.ts
40 lines (35 loc) · 1.54 KB
/
ContextHelper.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
import { ServiceWorkerManager } from '../managers/ServiceWorkerManager';
import { SubscriptionManager, SubscriptionManagerConfig } from '../managers/SubscriptionManager';
import { ContextSWInterface } from "../models/ContextSW";
import { AppConfig } from '../models/AppConfig';
import Path from '../models/Path';
export class ContextHelper {
public static getServiceWorkerManager(context: ContextSWInterface): ServiceWorkerManager {
const config: AppConfig = context.appConfig;
const serviceWorkerManagerConfig = {
workerPath: new Path(`OneSignalSDKWorker.js`),
registrationOptions: { scope: '/' }
};
if (config.userConfig) {
if (config.userConfig.path) {
serviceWorkerManagerConfig.workerPath =
new Path(`${config.userConfig.path}${config.userConfig.serviceWorkerPath}`);
}
if (config.userConfig.serviceWorkerParam) {
serviceWorkerManagerConfig.registrationOptions = config.userConfig.serviceWorkerParam;
}
}
return new ServiceWorkerManager(context, serviceWorkerManagerConfig);
}
public static getSubscriptionManager(context: ContextSWInterface): SubscriptionManager {
const config: AppConfig = context.appConfig;
const subscriptionManagerConfig: SubscriptionManagerConfig = {
safariWebId: config.safariWebId,
appId: config.appId,
vapidPublicKey: config.vapidPublicKey,
onesignalVapidPublicKey: config.onesignalVapidPublicKey,
};
return new SubscriptionManager(context, subscriptionManagerConfig);
}
}
export default ContextHelper;