-
Notifications
You must be signed in to change notification settings - Fork 48
/
index.ts
196 lines (174 loc) · 6.25 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
import { NativeModules, Platform } from 'react-native';
import {
IBEACON,
EDDYSTONE,
SECURE_PROFILE,
scanMode,
scanPeriod,
activityCheckConfiguration,
forceScanConfiguration,
monitoringEnabled,
monitoringSyncInterval,
} from './configurations';
import type { AuthorizationStatus, BeaconType, ConfigType, KontaktType, RegionType } from './types';
// If the native module (i.e. Java module) is prefixed with "RCT",
// the NativeModules name does not include "RCT".
export const KontaktModule = NativeModules.KontaktBeacons;
/**
* Methods shared in android and iOS
*/
export const configure = (
/**
* beacon scanning configuration
*/
params: ConfigType | undefined | null = null
): Promise<void> => KontaktModule.configure(params);
let Kontakt = {};
/**
* Android
*/
if (Platform.OS === 'android') {
const connect = (
apiKey: string | undefined | null = null,
beaconTypes: Array<BeaconType> | undefined | null = null
): Promise<void> => KontaktModule.connect(apiKey, beaconTypes);
/**
* @deprecated
* 'init' was renamed to 'connect' - please use 'connect'
*/
const init = (
apiKey: string | undefined | null = null,
beaconTypes: Array<BeaconType> | undefined | null = null
): Promise<void> => KontaktModule.connect(apiKey, beaconTypes);
const disconnect: () => Promise<void> = KontaktModule.disconnect;
const isConnected: () => Promise<boolean> = KontaktModule.isConnected;
const startScanning: () => Promise<void> = KontaktModule.startScanning;
const stopScanning: () => Promise<void> = KontaktModule.stopScanning;
const restartScanning: () => Promise<void> = KontaktModule.restartScanning;
const isScanning: () => Promise<boolean> = KontaktModule.isScanning;
const setBeaconRegion = (region: RegionType | null = null): void =>
KontaktModule.setBeaconRegion(region);
const setBeaconRegions = (regionsArray: Array<RegionType> | undefined | null = null): void =>
KontaktModule.setBeaconRegions(regionsArray);
const getBeaconRegions: () => Promise<Array<RegionType>> = KontaktModule.getBeaconRegions;
const setEddystoneNamespace = (namespace: any) => KontaktModule.setEddystoneNamespace(namespace);
const DEFAULT_KONTAKT_BEACON_PROXIMITY_UUID: string =
KontaktModule.DEFAULT_KONTAKT_BEACON_PROXIMITY_UUID;
const DEFAULT_KONTAKT_NAMESPACE_ID: string = KontaktModule.DEFAULT_KONTAKT_NAMESPACE_ID;
const ANY_MINOR: number = KontaktModule.ANY_MINOR;
const ANY_MAJOR: number = KontaktModule.ANY_MAJOR;
Kontakt = {
configure,
connect,
disconnect,
isConnected,
startScanning,
stopScanning,
restartScanning,
isScanning,
setBeaconRegion,
setBeaconRegions,
getBeaconRegions,
setEddystoneNamespace,
// Constants
IBEACON,
EDDYSTONE,
SECURE_PROFILE,
DEFAULT_KONTAKT_BEACON_PROXIMITY_UUID,
DEFAULT_KONTAKT_NAMESPACE_ID,
ANY_MAJOR,
ANY_MINOR,
// Configurations
scanMode,
scanPeriod,
activityCheckConfiguration,
forceScanConfiguration,
monitoringEnabled,
monitoringSyncInterval,
init, // @deprecated
};
}
/**
* iOS
*/
if (Platform.OS === 'ios') {
const init = (
/**
* Optional Kontakt.io API key
*
* May not be provided for scanning and ranging.
* Necessary for reading out beacon config.
*/
apiKey: string | undefined | null = null
): Promise<void> => KontaktModule.init(apiKey);
const startDiscovery = (
config:
| {
/**
* scanning interval in milliseconds
*/
interval: number;
}
| undefined
): Promise<void> => KontaktModule.startDiscovery(config);
const stopDiscovery: () => Promise<void> = KontaktModule.stopDiscovery;
const restartDiscovery: () => Promise<void> = KontaktModule.restartDiscovery;
const isDiscovering: () => Promise<boolean> = KontaktModule.isDiscovering;
const getAuthorizationStatus: () => Promise<AuthorizationStatus> =
KontaktModule.getAuthorizationStatus;
const requestWhenInUseAuthorization: () => Promise<void> =
KontaktModule.requestWhenInUseAuthorization;
const requestAlwaysAuthorization: () => Promise<void> = KontaktModule.requestAlwaysAuthorization;
const startRangingBeaconsInRegion = (region: RegionType): Promise<void> =>
KontaktModule.startRangingBeaconsInRegion(region);
const stopRangingBeaconsInRegion = (region: RegionType): Promise<void> =>
KontaktModule.stopRangingBeaconsInRegion(region);
const stopRangingBeaconsInAllRegions = (): Promise<void> =>
KontaktModule.stopRangingBeaconsInAllRegions;
const getRangedRegions: () => Promise<Array<RegionType>> = KontaktModule.getRangedRegions;
const startMonitoringForRegion = (region: RegionType): Promise<void> =>
KontaktModule.startMonitoringForRegion(region);
const stopMonitoringForRegion = (region: RegionType): Promise<void> =>
KontaktModule.stopMonitoringForRegion(region);
const stopMonitoringForAllRegions: () => Promise<void> =
KontaktModule.stopMonitoringForAllRegions;
const getMonitoredRegions: () => Promise<Array<RegionType>> = KontaktModule.getMonitoredRegions;
const requestStateForRegion = (region: RegionType): Promise<void> =>
KontaktModule.requestStateForRegion(region);
const startEddystoneDiscovery = (namespace: any): Promise<void> =>
KontaktModule.startEddystoneDiscovery(namespace);
const stopEddystoneDiscoveryInRegion = (region: RegionType): Promise<void> =>
KontaktModule.stopEddystoneDiscoveryInRegion(region);
const stopEddystoneDiscoveryInAllRegions: () => Promise<void> =
KontaktModule.stopEddystoneDiscoveryInAllRegions;
Kontakt = {
init,
configure,
// authorization
getAuthorizationStatus,
requestWhenInUseAuthorization,
requestAlwaysAuthorization,
// discovery
startDiscovery,
stopDiscovery,
restartDiscovery,
isDiscovering,
// ranging
startRangingBeaconsInRegion,
stopRangingBeaconsInRegion,
stopRangingBeaconsInAllRegions,
getRangedRegions,
// monitoring
startMonitoringForRegion,
stopMonitoringForRegion,
stopMonitoringForAllRegions,
getMonitoredRegions,
requestStateForRegion,
// eddystone
startEddystoneDiscovery,
stopEddystoneDiscoveryInRegion,
stopEddystoneDiscoveryInAllRegions,
};
}
export * from './types';
export default Kontakt as KontaktType;