forked from Driversnote-Dev/react-native-kontaktio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.ts
249 lines (217 loc) · 6.73 KB
/
types.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
197
198
199
200
201
202
203
204
205
206
207
208
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
239
240
241
242
243
244
245
246
247
248
249
import { NativeModules } from 'react-native';
import {
IBEACON,
EDDYSTONE,
SECURE_PROFILE,
scanMode,
scanPeriod,
activityCheckConfiguration,
forceScanConfiguration,
monitoringEnabled,
monitoringSyncInterval,
} from './configurations';
export type AuthorizationStatus =
| 'denied'
| 'authorizedWhenInUse'
| 'authorizedAlways'
| 'notDetermined'
| 'restricted';
export type IBeaconMinimum = {
major: number;
minor: number;
};
export type IBeaconBase = {
uuid: string;
major: number;
minor: number;
uniqueId?: string;
};
export type Proximity = 'IMMEDIATE' | 'NEAR' | 'FAR' | 'UNKNOWN';
/**
* Beacon response while scanning on Android
*/
export type IBeaconAndroid = {
// IBeaconBase
major: number;
minor: number;
uuid: string;
// BeaconAndroid
name: string;
uniqueId: string;
firmwareVersion: string;
address: string;
rssi: number;
proximity: Proximity;
accuracy: string;
// Distance in meters
batteryPower: number;
// Percentage as int
txPower: number;
isShuffled: string;
};
export type SecureProfileAndroid = {
name?: string;
uniqueId: string;
firmwareRevision: string;
macAddress: string;
rssi: number;
batteryLevel: number;
isShuffled: boolean;
txPower: number;
telemetry?: any;
};
/**
* Beacon response while ranging or monitoring on iOS
*/
export type IBeaconIos = {
// IBeaconBase
major: number;
minor: number;
uuid: string;
//
rssi: number;
proximity: Proximity;
accuracy: string; // Distance in meters (if Kontakt.io Beacon)
};
/**
* Beacon response while discovering
*/
export type IBeaconIosDiscovery = {
name?: string;
// 'Kontakt' by default for Kontakt.io beacons
uniqueId: string;
firmwareVersion: string;
/**
* percentage as integer (same as 'batteryPower' for Android)
*/
batteryLevel: number;
batteryPowered: boolean;
/**
* same as 'txPower' for Android
*/
transmissionPower: number;
hasConfigurationProfile: boolean;
shuffled: boolean;
locked: boolean;
model: string;
peripheral: string;
rssi: number;
updatedAt: number;
};
export type IBeaconIosDiscoveryWithMajorMinor = IBeaconIosDiscovery & {
major?: number;
minor?: number;
};
export type IBeaconWithUniqueId = IBeaconAndroid | IBeaconIosDiscoveryWithMajorMinor;
export type IBeacon = IBeaconAndroid | IBeaconIos | IBeaconIosDiscovery;
export type BeaconType = typeof IBEACON | typeof EDDYSTONE | typeof SECURE_PROFILE;
export type RegionBase = {
uuid: string;
identifier: string;
major?: number;
minor?: number;
uniqueId?: string;
};
export type RegionAndroid = RegionBase & { secureUuid?: string };
export type RegionIos = RegionBase;
export type RegionType = RegionAndroid | RegionIos;
/**
* beacon scanning configuration
*/
export type ConfigType = {
scanMode?: typeof scanMode.LOW_POWER | typeof scanMode.BALANCED | typeof scanMode.LOW_LATENCY;
scanPeriod?:
| typeof scanPeriod.MONITORING
| typeof scanPeriod.RANGING
| ReturnType<typeof scanPeriod.create>;
activityCheckConfiguration?:
| typeof activityCheckConfiguration.DISABLED
| typeof activityCheckConfiguration.MINIMAL
| typeof activityCheckConfiguration.DEFAULT
| ReturnType<typeof activityCheckConfiguration.create>;
forceScanConfiguration?:
| typeof activityCheckConfiguration.DISABLED
| typeof activityCheckConfiguration.MINIMAL
| ReturnType<typeof forceScanConfiguration.create>;
dropEmptyRanges?: boolean;
invalidationAge?: number;
monitoringEnabled?: typeof monitoringEnabled.TRUE | typeof monitoringEnabled.FALSE;
monitoringSyncInterval?: typeof monitoringSyncInterval.DEFAULT;
};
type KontaktBaseType = {
configure: (config: ConfigType | undefined) => Promise<void>;
};
export type KontaktAndroidType = KontaktBaseType & {
/**
* Connect to the Kontaktio beacon service. Has to be called to initialize beacon scanning etc.
*
* To retrieve `uniqueId` and other meta info (e.g. `batteryPower`, `firmwareVersion` etc.),
* add `SECURE_PROFILE` to the `beaconTypes` argument.
* Listen for "profile*" events (i.e. `profileDidAppear` etc.).
*/
connect: (
/**
* Kontakt.io API key
*/
key?: string,
/**
* which beacon types to scan for
*/
beaconTypes?: Array<BeaconType> | undefined
) => Promise<void>;
disconnect: () => Promise<void>;
isConnected: () => Promise<boolean>;
startScanning: () => Promise<void>;
stopScanning: () => Promise<void>;
restartScanning: () => Promise<void>;
isScanning: () => Promise<boolean>;
setBeaconRegion: (region: RegionType) => void;
setBeaconRegions: (regions: Array<RegionType>) => void;
getBeaconRegions: () => Promise<Array<RegionType>>;
setEddystoneNamespace: (namespace: any) => void;
// Constants
IBEACON: typeof IBEACON;
EDDYSTONE: typeof EDDYSTONE;
SECURE_PROFILE: typeof SECURE_PROFILE;
DEFAULT_KONTAKT_BEACON_PROXIMITY_UUID: string;
DEFAULT_KONTAKT_NAMESPACE_ID: string;
ANY_MAJOR: number;
ANY_MINOR: number;
// Configurations
scanMode: typeof scanMode;
scanPeriod: typeof scanPeriod;
activityCheckConfiguration: typeof activityCheckConfiguration;
forceScanConfiguration: typeof forceScanConfiguration;
monitoringEnabled: typeof monitoringEnabled;
monitoringSyncInterval: typeof monitoringSyncInterval;
/**
* @deprecated Please use 'connect' instead
*/
init?: (apiKey: string | undefined, beaconTypes: Array<BeaconType> | undefined) => Promise<void>;
};
export type KontaktiOSType = KontaktBaseType & {
init: (apiKey?: string | undefined) => Promise<void>;
isDiscovering: () => Promise<boolean>;
startDiscovery: (config?: { interval: number }) => Promise<void>;
stopDiscovery: () => Promise<void>;
restartDiscovery: () => Promise<void>;
getAuthorizationStatus: () => Promise<string>;
requestWhenInUseAuthorization: () => Promise<void>;
requestAlwaysAuthorization: () => Promise<void>;
startRangingBeaconsInRegion: (region: RegionType) => Promise<void>;
stopRangingBeaconsInRegion: (region: RegionType) => Promise<void>;
stopRangingBeaconsInAllRegions: () => Promise<void>;
getRangedRegions: () => Promise<Array<RegionType>>;
startMonitoringForRegion: (region: RegionType) => Promise<void>;
stopMonitoringForRegion: (region: RegionType) => Promise<void>;
stopMonitoringForAllRegions: () => Promise<void>;
getMonitoredRegions: () => Promise<Array<RegionType>>;
requestStateForRegion: (region: RegionType) => Promise<void>;
startEddystoneDiscovery: (namespace: any) => Promise<void>;
stopEddystoneDiscoveryInRegion: (region: RegionType) => Promise<void>;
stopEddystoneDiscoveryInAllRegions: () => Promise<void>;
};
export const KontaktModule = NativeModules.KontaktBeacons;
export type KontaktType = KontaktAndroidType & KontaktiOSType;
declare const module: KontaktType;
export default module;