@rodrigo7/react-native-beacons-manager 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.flowconfig +21 -0
- package/.nvmrc +1 -0
- package/.prettierignore +4 -0
- package/.prettierrc +12 -0
- package/.vscode/settings.json +24 -0
- package/LICENSE +21 -0
- package/README.md +246 -0
- package/ReactNativeBeaconsManager.podspec +13 -0
- package/android/.project +17 -0
- package/android/.settings/org.eclipse.buildship.core.prefs +2 -0
- package/android/build.gradle +108 -0
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +6 -0
- package/android/gradle/wrapper/gradle.properties +2 -0
- package/android/gradlew +160 -0
- package/android/gradlew.bat +90 -0
- package/android/src/main/AndroidManifest.xml +8 -0
- package/android/src/main/java/com/mackentoch/beaconsandroid/BeaconsAndroidModule.java +457 -0
- package/android/src/main/java/com/mackentoch/beaconsandroid/BeaconsAndroidPackage.java +29 -0
- package/index.js +10 -0
- package/ios/RNiBeacon/RNiBeacon/ESSBeaconScanner.h +41 -0
- package/ios/RNiBeacon/RNiBeacon/ESSBeaconScanner.m +204 -0
- package/ios/RNiBeacon/RNiBeacon/ESSEddystone.h +117 -0
- package/ios/RNiBeacon/RNiBeacon/ESSEddystone.m +352 -0
- package/ios/RNiBeacon/RNiBeacon/ESSTimer.h +72 -0
- package/ios/RNiBeacon/RNiBeacon/ESSTimer.m +107 -0
- package/ios/RNiBeacon/RNiBeacon/RNiBeacon.h +16 -0
- package/ios/RNiBeacon/RNiBeacon/RNiBeacon.m +467 -0
- package/ios/RNiBeacon/RNiBeacon.xcodeproj/project.pbxproj +290 -0
- package/jsconfig.json +9 -0
- package/lib/next/module.types.js +169 -0
- package/lib/next/new.module.android.js +451 -0
- package/lib/next/new.module.ios.js +176 -0
- package/package.json +65 -0
- package/typings/index.d.ts +174 -0
- package/typings.json +7 -0
- package/yarn-error.log +4182 -0
|
@@ -0,0 +1,451 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
// #region imports
|
|
4
|
+
const RN = require('react-native');
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
type BeaconRegion,
|
|
8
|
+
type BeaconsManagerANDROID,
|
|
9
|
+
type Parser,
|
|
10
|
+
} from './module.types';
|
|
11
|
+
import {
|
|
12
|
+
PARSER_IBEACON,
|
|
13
|
+
PARSER_ESTIMOTE,
|
|
14
|
+
PARSER_ALTBEACON,
|
|
15
|
+
PARSER_EDDYSTONE_TLM,
|
|
16
|
+
PARSER_EDDYSTONE_UID,
|
|
17
|
+
PARSER_EDDYSTONE_URL,
|
|
18
|
+
transmissionSupport,
|
|
19
|
+
} from './module.types';
|
|
20
|
+
// #endregion
|
|
21
|
+
|
|
22
|
+
// #region instanciation and constants
|
|
23
|
+
const BeaconsManager: BeaconsManagerANDROID =
|
|
24
|
+
RN.NativeModules.BeaconsAndroidModule;
|
|
25
|
+
const BeaconsEventEmitter = RN.DeviceEventEmitter;
|
|
26
|
+
|
|
27
|
+
const ARMA_RSSI_FILTER = BeaconsManager && BeaconsManager.ARMA_RSSI_FILTER || undefined;
|
|
28
|
+
const RUNNING_AVG_RSSI_FILTER = BeaconsManager && BeaconsManager.RUNNING_AVG_RSSI_FILTER || undefined;
|
|
29
|
+
// #endregion
|
|
30
|
+
|
|
31
|
+
function setHardwareEqualityEnforced(flag: boolean): void {
|
|
32
|
+
BeaconsManager.setHardwareEqualityEnforced(flag);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// #region iBeacon
|
|
36
|
+
/**
|
|
37
|
+
* set beacon layout for iBeacon
|
|
38
|
+
*
|
|
39
|
+
*/
|
|
40
|
+
function detectIBeacons(): Promise<any> {
|
|
41
|
+
return new Promise((resolve, reject) => {
|
|
42
|
+
BeaconsManager.addParser(PARSER_IBEACON, resolve, reject);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* same as detectIBeacons (intoduced in v1.1.0)
|
|
48
|
+
* adds iBeacon parser to detect them
|
|
49
|
+
*
|
|
50
|
+
*/
|
|
51
|
+
function addIBeaconsDetection(): Promise<any> {
|
|
52
|
+
return new Promise((resolve, reject) => {
|
|
53
|
+
BeaconsManager.addParser(PARSER_IBEACON, resolve, reject);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* removes iBeacon parser to stop detecting them
|
|
59
|
+
*
|
|
60
|
+
*/
|
|
61
|
+
function removeIBeaconsDetection(): Promise<any> {
|
|
62
|
+
return new Promise((resolve, reject) => {
|
|
63
|
+
BeaconsManager.removeParser(PARSER_IBEACON, resolve, reject);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
// #enregion
|
|
67
|
+
|
|
68
|
+
// #region altBeacon
|
|
69
|
+
/**
|
|
70
|
+
* set beacon layout for alBeacon
|
|
71
|
+
*
|
|
72
|
+
*/
|
|
73
|
+
function detectAltBeacons(): Promise<any> {
|
|
74
|
+
return new Promise((resolve, reject) => {
|
|
75
|
+
BeaconsManager.addParser(PARSER_ALTBEACON, resolve, reject);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function addAltBeaconsDetection(): Promise<any> {
|
|
80
|
+
return new Promise((resolve, reject) => {
|
|
81
|
+
BeaconsManager.addParser(PARSER_ALTBEACON, resolve, reject);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function removeAltBeaconsDetection(): Promise<any> {
|
|
86
|
+
return new Promise((resolve, reject) => {
|
|
87
|
+
BeaconsManager.removeParser(PARSER_ALTBEACON, resolve, reject);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
// #endregion
|
|
91
|
+
|
|
92
|
+
// #region estimote
|
|
93
|
+
/**
|
|
94
|
+
* set beacon layout for estimote
|
|
95
|
+
*
|
|
96
|
+
*/
|
|
97
|
+
function detectEstimotes(): Promise<any> {
|
|
98
|
+
return new Promise((resolve, reject) => {
|
|
99
|
+
BeaconsManager.addParser(PARSER_ESTIMOTE, resolve, reject);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function addEstimotesDetection(): Promise<any> {
|
|
104
|
+
return new Promise((resolve, reject) => {
|
|
105
|
+
BeaconsManager.addParser(PARSER_ESTIMOTE, resolve, reject);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function removeEstimotesDetection(): Promise<any> {
|
|
110
|
+
return new Promise((resolve, reject) => {
|
|
111
|
+
BeaconsManager.removeParser(PARSER_ESTIMOTE, resolve, reject);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
// #endregion
|
|
115
|
+
|
|
116
|
+
// #region eddystone UID
|
|
117
|
+
/**
|
|
118
|
+
* set beacon layout for eddystone UID
|
|
119
|
+
*
|
|
120
|
+
*/
|
|
121
|
+
function detectEddystoneUID(): Promise<any> {
|
|
122
|
+
return new Promise((resolve, reject) => {
|
|
123
|
+
BeaconsManager.addParser(PARSER_EDDYSTONE_UID, resolve, reject);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* same as detectEddystoneUID (intoduced in v1.1.0)
|
|
129
|
+
* adds EddystoneUID parser to detect them
|
|
130
|
+
*
|
|
131
|
+
*/
|
|
132
|
+
function addEddystoneUIDDetection(): Promise<any> {
|
|
133
|
+
return new Promise((resolve, reject) => {
|
|
134
|
+
BeaconsManager.addParser(PARSER_EDDYSTONE_UID, resolve, reject);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* removes EddystoneUID parser to stop detecting them
|
|
140
|
+
*
|
|
141
|
+
*/
|
|
142
|
+
function removeEddystoneUIDDetection(): Promise<any> {
|
|
143
|
+
return new Promise((resolve, reject) => {
|
|
144
|
+
BeaconsManager.removeParser(PARSER_EDDYSTONE_UID, resolve, reject);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
// #endregion
|
|
148
|
+
|
|
149
|
+
// #region eddystone URL
|
|
150
|
+
/**
|
|
151
|
+
* set beacon layout for eddystone URL
|
|
152
|
+
*
|
|
153
|
+
*/
|
|
154
|
+
function detectEddystoneURL(): Promise<any> {
|
|
155
|
+
return new Promise((resolve, reject) => {
|
|
156
|
+
BeaconsManager.addParser(PARSER_EDDYSTONE_URL, resolve, reject);
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function addEddystoneURLDetection(): Promise<any> {
|
|
161
|
+
return new Promise((resolve, reject) => {
|
|
162
|
+
BeaconsManager.addParser(PARSER_EDDYSTONE_URL, resolve, reject);
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function removeEddystoneURLDetection(): Promise<any> {
|
|
167
|
+
return new Promise((resolve, reject) => {
|
|
168
|
+
BeaconsManager.removeParser(PARSER_EDDYSTONE_URL, resolve, reject);
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
// #endregion
|
|
172
|
+
|
|
173
|
+
// #region eddystone TLM
|
|
174
|
+
/**
|
|
175
|
+
* set beacon layout for eddystone TLM
|
|
176
|
+
*
|
|
177
|
+
*/
|
|
178
|
+
function detectEddystoneTLM(): Promise<any> {
|
|
179
|
+
return new Promise((resolve, reject) => {
|
|
180
|
+
BeaconsManager.addParser(PARSER_EDDYSTONE_TLM, resolve, reject);
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function addEddystoneTLMDetection(): Promise<any> {
|
|
185
|
+
return new Promise((resolve, reject) => {
|
|
186
|
+
BeaconsManager.addParser(PARSER_EDDYSTONE_TLM, resolve, reject);
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function removeEddystoneTLMDetection(): Promise<any> {
|
|
191
|
+
return new Promise((resolve, reject) => {
|
|
192
|
+
BeaconsManager.removeParser(PARSER_EDDYSTONE_TLM, resolve, reject);
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
// #endregion
|
|
196
|
+
|
|
197
|
+
// #region custom beacon (set your parser)
|
|
198
|
+
/**
|
|
199
|
+
* set beacon for custom layout
|
|
200
|
+
*
|
|
201
|
+
*/
|
|
202
|
+
function detectCustomBeaconLayout(parser: number): Promise<any> {
|
|
203
|
+
return new Promise((resolve, reject) => {
|
|
204
|
+
BeaconsManager.addParser(parser, resolve, reject);
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function addCustomBeaconLayoutDetection(parser: number): Promise<any> {
|
|
209
|
+
return new Promise((resolve, reject) => {
|
|
210
|
+
BeaconsManager.addParser(parser, resolve, reject);
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function removeCustomBeaconLayoutDetection(parser: number): Promise<any> {
|
|
215
|
+
return new Promise((resolve, reject) => {
|
|
216
|
+
BeaconsManager.removeParser(parser, resolve, reject);
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
// #endregion
|
|
220
|
+
|
|
221
|
+
// #region add remove multiple parsers in a row
|
|
222
|
+
function addParsersListToDetection(parsers: Array<Parser>) {
|
|
223
|
+
return new Promise((resolve, reject) => {
|
|
224
|
+
BeaconsManager.addParsersListToDetection(parsers, resolve, reject);
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function removeParsersListToDetection(parsers: Array<Parser>) {
|
|
229
|
+
return new Promise((resolve, reject) => {
|
|
230
|
+
BeaconsManager.removeParsersListToDetection(parsers, resolve, reject);
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
// #endregion
|
|
234
|
+
|
|
235
|
+
function setBackgroundScanPeriod(period: number): void {
|
|
236
|
+
BeaconsManager.setBackgroundScanPeriod(period);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function setBackgroundBetweenScanPeriod(period: number): void {
|
|
240
|
+
BeaconsManager.setBackgroundBetweenScanPeriod(period);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function setForegroundScanPeriod(period: number): void {
|
|
244
|
+
BeaconsManager.setForegroundScanPeriod(period);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function setRssiFilter(filterType: number, avgModifier: number): void {
|
|
248
|
+
BeaconsManager.setRssiFilter(filterType, avgModifier);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function getRangedRegions(): Promise<any> {
|
|
252
|
+
return new Promise((resolve, reject) => {
|
|
253
|
+
BeaconsManager.getRangedRegions(resolve);
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* get monitored regions
|
|
259
|
+
*
|
|
260
|
+
* @returns {Promise<Array<BeaconRegion>>} promise resolve to an array of monitored regions
|
|
261
|
+
*/
|
|
262
|
+
function getMonitoredRegions(): Promise<Array<BeaconRegion>> {
|
|
263
|
+
return new Promise((resolve, reject) => {
|
|
264
|
+
BeaconsManager.getMonitoredRegions(resolve);
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* check if beacon support transmission
|
|
270
|
+
*
|
|
271
|
+
* @returns {Promise<number>} promise resolve to an integer
|
|
272
|
+
*/
|
|
273
|
+
function checkTransmissionSupported(): Promise<number> {
|
|
274
|
+
return new Promise((resolve, reject) => {
|
|
275
|
+
BeaconsManager.checkTransmissionSupported(status =>
|
|
276
|
+
resolve(transmissionSupport[status]),
|
|
277
|
+
);
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* start monitoring for a region
|
|
283
|
+
*
|
|
284
|
+
* @param {Object: BeaconRegion} region region to monitor (identifier + uuid -> major and minor are optional)
|
|
285
|
+
* @returns {Promise<any>} promise resolves to void or error
|
|
286
|
+
*/
|
|
287
|
+
function startMonitoringForRegion(region: BeaconRegion): Promise<any> {
|
|
288
|
+
return new Promise((resolve, reject) => {
|
|
289
|
+
// NOTE: major and minor are optional values: if user don't assign them we have to send a null value (not undefined):
|
|
290
|
+
BeaconsManager.startMonitoring(
|
|
291
|
+
region.identifier,
|
|
292
|
+
region.uuid,
|
|
293
|
+
region.minor ? region.minor : -1,
|
|
294
|
+
region.major ? region.major : -1,
|
|
295
|
+
resolve,
|
|
296
|
+
reject,
|
|
297
|
+
);
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* stops monittorings for a region
|
|
303
|
+
*
|
|
304
|
+
* @param {BeaconRegion} region region (see BeaconRegion type)
|
|
305
|
+
* @returns {Promise<any>} promise resolves to void or error
|
|
306
|
+
*/
|
|
307
|
+
function stopMonitoringForRegion(region: BeaconRegion): Promise<any> {
|
|
308
|
+
return new Promise((resolve, reject) => {
|
|
309
|
+
BeaconsManager.stopMonitoring(
|
|
310
|
+
region.identifier,
|
|
311
|
+
region.uuid,
|
|
312
|
+
region.minor ? region.minor : -1,
|
|
313
|
+
region.major ? region.major : -1,
|
|
314
|
+
resolve,
|
|
315
|
+
reject,
|
|
316
|
+
);
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* start ranging a region (with optional UUID)
|
|
322
|
+
*
|
|
323
|
+
* @param {String | BeaconRegion} regionId if string or region: BeaconRegion object
|
|
324
|
+
* @param {String} [beaconsUUID] optional UUID
|
|
325
|
+
* @returns {Promise<any>} promise resolves to void or error
|
|
326
|
+
*/
|
|
327
|
+
function startRangingBeaconsInRegion(
|
|
328
|
+
region: BeaconRegion | string,
|
|
329
|
+
beaconsUUID?: string,
|
|
330
|
+
): Promise<any> {
|
|
331
|
+
if (typeof region === 'object') {
|
|
332
|
+
return new Promise((resolve, reject) => {
|
|
333
|
+
BeaconsManager.startRanging(
|
|
334
|
+
// $FlowIgnore
|
|
335
|
+
region.identifier,
|
|
336
|
+
// $FlowIgnore
|
|
337
|
+
region.uuid,
|
|
338
|
+
resolve,
|
|
339
|
+
reject,
|
|
340
|
+
);
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
return new Promise((resolve, reject) => {
|
|
344
|
+
BeaconsManager.startRanging(region, beaconsUUID, resolve, reject);
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Stops the range scan for beacons
|
|
350
|
+
*
|
|
351
|
+
* @param {String | BeaconRegion} regionId if string or region: BeaconRegion object
|
|
352
|
+
* @param {string} beaconsUUID optional UUID within the specified region
|
|
353
|
+
* @returns {Promise<any>} promise: resolves to void when successful
|
|
354
|
+
*/
|
|
355
|
+
function stopRangingBeaconsInRegion(
|
|
356
|
+
region: BeaconRegion | string,
|
|
357
|
+
beaconsUUID?: string,
|
|
358
|
+
): Promise<any> {
|
|
359
|
+
if (typeof region === 'object') {
|
|
360
|
+
return new Promise((resolve, reject) => {
|
|
361
|
+
BeaconsManager.stopRanging(
|
|
362
|
+
// $FlowIgnore
|
|
363
|
+
region.identifier,
|
|
364
|
+
// $FlowIgnore
|
|
365
|
+
region.uuid,
|
|
366
|
+
resolve,
|
|
367
|
+
reject,
|
|
368
|
+
);
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
return new Promise((resolve, reject) => {
|
|
372
|
+
// $FlowIgnore
|
|
373
|
+
BeaconsManager.stopRanging(region, beaconsUUID, resolve, reject);
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* Retrieves the state of a region asynchronously.
|
|
379
|
+
*
|
|
380
|
+
* @param {BeaconRegion} region region (identifier + uuid -> major and minor are optional)
|
|
381
|
+
*/
|
|
382
|
+
function requestStateForRegion(region: BeaconRegion): void {
|
|
383
|
+
BeaconsManager.requestStateForRegion(
|
|
384
|
+
region.identifier,
|
|
385
|
+
region.uuid,
|
|
386
|
+
region.minor ? region.minor : -1,
|
|
387
|
+
region.major ? region.major : -1,
|
|
388
|
+
);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
module.exports = {
|
|
392
|
+
// parsers constants
|
|
393
|
+
PARSER_IBEACON,
|
|
394
|
+
PARSER_ESTIMOTE,
|
|
395
|
+
PARSER_ALTBEACON,
|
|
396
|
+
PARSER_EDDYSTONE_TLM,
|
|
397
|
+
PARSER_EDDYSTONE_UID,
|
|
398
|
+
PARSER_EDDYSTONE_URL,
|
|
399
|
+
|
|
400
|
+
BeaconsEventEmitter,
|
|
401
|
+
setHardwareEqualityEnforced,
|
|
402
|
+
// iBeacons:
|
|
403
|
+
detectIBeacons,
|
|
404
|
+
addIBeaconsDetection,
|
|
405
|
+
removeIBeaconsDetection,
|
|
406
|
+
// alt beacons:
|
|
407
|
+
detectAltBeacons,
|
|
408
|
+
addAltBeaconsDetection,
|
|
409
|
+
removeAltBeaconsDetection,
|
|
410
|
+
// Estimotes beacon:
|
|
411
|
+
detectEstimotes,
|
|
412
|
+
addEstimotesDetection,
|
|
413
|
+
removeEstimotesDetection,
|
|
414
|
+
// Eddystone UID beacons:
|
|
415
|
+
detectEddystoneUID,
|
|
416
|
+
addEddystoneUIDDetection,
|
|
417
|
+
removeEddystoneUIDDetection,
|
|
418
|
+
// Eddystone TLM beacons:
|
|
419
|
+
detectEddystoneTLM,
|
|
420
|
+
addEddystoneTLMDetection,
|
|
421
|
+
removeEddystoneTLMDetection,
|
|
422
|
+
// Eddystone URL beacons:
|
|
423
|
+
detectEddystoneURL,
|
|
424
|
+
addEddystoneURLDetection,
|
|
425
|
+
removeEddystoneURLDetection,
|
|
426
|
+
// custom layout beacons (NOTE: create 'valid UUID' with websites like, for instance, this one: https://openuuid.net):
|
|
427
|
+
detectCustomBeaconLayout,
|
|
428
|
+
addCustomBeaconLayoutDetection,
|
|
429
|
+
removeCustomBeaconLayoutDetection,
|
|
430
|
+
|
|
431
|
+
addParsersListToDetection,
|
|
432
|
+
removeParsersListToDetection,
|
|
433
|
+
|
|
434
|
+
setBackgroundScanPeriod,
|
|
435
|
+
setBackgroundBetweenScanPeriod,
|
|
436
|
+
setForegroundScanPeriod,
|
|
437
|
+
setRssiFilter,
|
|
438
|
+
checkTransmissionSupported,
|
|
439
|
+
getRangedRegions,
|
|
440
|
+
ARMA_RSSI_FILTER,
|
|
441
|
+
RUNNING_AVG_RSSI_FILTER,
|
|
442
|
+
|
|
443
|
+
getMonitoredRegions,
|
|
444
|
+
|
|
445
|
+
// common with iOS:
|
|
446
|
+
startMonitoringForRegion,
|
|
447
|
+
startRangingBeaconsInRegion,
|
|
448
|
+
stopMonitoringForRegion,
|
|
449
|
+
stopRangingBeaconsInRegion,
|
|
450
|
+
requestStateForRegion,
|
|
451
|
+
};
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
const RN = require('react-native');
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
type BeaconRegion,
|
|
7
|
+
type AuthorizationStatus,
|
|
8
|
+
type BeaconsManagerIOS,
|
|
9
|
+
} from './module.types';
|
|
10
|
+
|
|
11
|
+
const BeaconsManager: BeaconsManagerIOS = RN.NativeModules.RNiBeacon;
|
|
12
|
+
const BeaconsEventEmitter = BeaconsManager && new RN.NativeEventEmitter(BeaconsManager) || undefined;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* request always authorization (mandatory when ranging beacons but energy drain)
|
|
16
|
+
* IMPORTANT: To be effective your info.plist file should have 'Privacy - Location Always Usage Description' key defined
|
|
17
|
+
*/
|
|
18
|
+
function requestAlwaysAuthorization(): void {
|
|
19
|
+
BeaconsManager.requestAlwaysAuthorization();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* request when app in use authorization (bare minimum for beacons)
|
|
24
|
+
* IMPORTANT: To be effective your info.plist file should have 'Privacy - Location When In Use Usage Description' key defined (hopefully 'react-native init' should have set it for you)
|
|
25
|
+
*/
|
|
26
|
+
function requestWhenInUseAuthorization(): void {
|
|
27
|
+
BeaconsManager.requestWhenInUseAuthorization();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* set background location updates to ensure monitoring when app is killed or in background mode
|
|
32
|
+
*
|
|
33
|
+
* @param {boolean} [allow=false] allow or disallow background modes
|
|
34
|
+
*/
|
|
35
|
+
function allowsBackgroundLocationUpdates(allow: boolean = false): void {
|
|
36
|
+
BeaconsManager.allowsBackgroundLocationUpdates(allow);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* get authorization status
|
|
41
|
+
*
|
|
42
|
+
* @returns {() => AuthorizationStatus} instant callback (not async)
|
|
43
|
+
*/
|
|
44
|
+
function getAuthorizationStatus(
|
|
45
|
+
callback: (status: AuthorizationStatus) => any,
|
|
46
|
+
): any {
|
|
47
|
+
return BeaconsManager.getAuthorizationStatus(callback);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* get monitored regions
|
|
52
|
+
*
|
|
53
|
+
* @returns {Promise<Array<BeaconRegion>>} promise resolve to an array of monitored regions
|
|
54
|
+
*/
|
|
55
|
+
function getMonitoredRegions(): Promise<Array<BeaconRegion>> {
|
|
56
|
+
return new Promise((resolve, reject) => {
|
|
57
|
+
BeaconsManager.getMonitoredRegions(resolve);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* call is needed for monitoring beacons and gets the initial position of the device.
|
|
63
|
+
*
|
|
64
|
+
*/
|
|
65
|
+
function startUpdatingLocation(): void {
|
|
66
|
+
BeaconsManager.startUpdatingLocation();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* This method should be called when you don't need to receive location-based information and want to save battery power.
|
|
71
|
+
*
|
|
72
|
+
*/
|
|
73
|
+
function stopUpdatingLocation(): void {
|
|
74
|
+
BeaconsManager.stopUpdatingLocation();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function shouldDropEmptyRanges(drop: boolean): void {
|
|
78
|
+
BeaconsManager.shouldDropEmptyRanges(drop);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* start monitoring for a region
|
|
83
|
+
*
|
|
84
|
+
* @param {BeaconRegion} region region to monitor (identifier + uuid -> major and minor are optional)
|
|
85
|
+
* @returns {Promise<any>} promise resolves to void or error
|
|
86
|
+
*/
|
|
87
|
+
function startMonitoringForRegion(region: BeaconRegion): Promise<any> {
|
|
88
|
+
return new Promise((resolve, reject) => {
|
|
89
|
+
try {
|
|
90
|
+
BeaconsManager.startMonitoringForRegion(region);
|
|
91
|
+
resolve();
|
|
92
|
+
} catch (error) {
|
|
93
|
+
reject(error);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* stop monitoring for a region
|
|
100
|
+
*
|
|
101
|
+
* @param {BeaconRegion} region region (identifier + uuid -> major and minor are optional)
|
|
102
|
+
* @returns {Promise<any>} promise resolves to void or error
|
|
103
|
+
*/
|
|
104
|
+
function stopMonitoringForRegion(region: BeaconRegion): Promise<any> {
|
|
105
|
+
return new Promise((resolve, reject) => {
|
|
106
|
+
try {
|
|
107
|
+
BeaconsManager.stopMonitoringForRegion(region);
|
|
108
|
+
resolve();
|
|
109
|
+
} catch (error) {
|
|
110
|
+
reject(error);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* start ranging for a region
|
|
117
|
+
*
|
|
118
|
+
* @param {BeaconRegion} region region to scan (identifier + uuid -> major and minor are optional)
|
|
119
|
+
* @returns {Promise<any>} promise resolves to void or error
|
|
120
|
+
*/
|
|
121
|
+
function startRangingBeaconsInRegion(region: BeaconRegion): Promise<any> {
|
|
122
|
+
return new Promise((resolve, reject) => {
|
|
123
|
+
try {
|
|
124
|
+
BeaconsManager.startRangingBeaconsInRegion(region);
|
|
125
|
+
resolve();
|
|
126
|
+
} catch (error) {
|
|
127
|
+
reject(error);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* stop ranging for a region
|
|
134
|
+
*
|
|
135
|
+
* @param {BeaconRegion} region region (identifier + uuid -> major and minor are optional)
|
|
136
|
+
* @returns {Promise<any>} promise: resolves to void when successful
|
|
137
|
+
*/
|
|
138
|
+
function stopRangingBeaconsInRegion(region: BeaconRegion): Promise<any> {
|
|
139
|
+
return new Promise((resolve, reject) => {
|
|
140
|
+
try {
|
|
141
|
+
BeaconsManager.stopRangingBeaconsInRegion(region);
|
|
142
|
+
resolve();
|
|
143
|
+
} catch (error) {
|
|
144
|
+
reject(error);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Retrieves the state of a region asynchronously.
|
|
151
|
+
*
|
|
152
|
+
* @param {BeaconRegion} region region (identifier + uuid -> major and minor are optional)
|
|
153
|
+
*/
|
|
154
|
+
function requestStateForRegion(region: BeaconRegion): void {
|
|
155
|
+
BeaconsManager.requestStateForRegion(region);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
module.exports = {
|
|
159
|
+
BeaconsEventEmitter,
|
|
160
|
+
|
|
161
|
+
requestAlwaysAuthorization,
|
|
162
|
+
requestWhenInUseAuthorization,
|
|
163
|
+
allowsBackgroundLocationUpdates,
|
|
164
|
+
getAuthorizationStatus,
|
|
165
|
+
getMonitoredRegions,
|
|
166
|
+
startUpdatingLocation,
|
|
167
|
+
stopUpdatingLocation,
|
|
168
|
+
shouldDropEmptyRanges,
|
|
169
|
+
|
|
170
|
+
// common with android:
|
|
171
|
+
startMonitoringForRegion,
|
|
172
|
+
startRangingBeaconsInRegion,
|
|
173
|
+
stopMonitoringForRegion,
|
|
174
|
+
stopRangingBeaconsInRegion,
|
|
175
|
+
requestStateForRegion,
|
|
176
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rodrigo7/react-native-beacons-manager",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "React-Native library for detecting beacons (iOS and Android)",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"react-native",
|
|
7
|
+
"react-component",
|
|
8
|
+
"ios",
|
|
9
|
+
"ibeacon",
|
|
10
|
+
"beacon",
|
|
11
|
+
"beacons",
|
|
12
|
+
"android",
|
|
13
|
+
"ibeacons",
|
|
14
|
+
"altbeacon",
|
|
15
|
+
"estimote",
|
|
16
|
+
"eddystone",
|
|
17
|
+
"altbeacons"
|
|
18
|
+
],
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/rodrigo-nexudus/react-native-beacons-manager.git"
|
|
22
|
+
},
|
|
23
|
+
"typescript": {
|
|
24
|
+
"definition": "typings/index.d.ts"
|
|
25
|
+
},
|
|
26
|
+
"types": "typings/index.d.ts",
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "https://github.com/rodrigo-nexudus/react-native-beacons-manager/issues"
|
|
29
|
+
},
|
|
30
|
+
"homepage": "https://github.com/rodrigo-nexudus/react-native-beacons-manager#readme",
|
|
31
|
+
"main": "index.js",
|
|
32
|
+
"directories": {
|
|
33
|
+
"example": "examples",
|
|
34
|
+
"lib": "lib"
|
|
35
|
+
},
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=8.9.0",
|
|
38
|
+
"npm": ">=5.3.0",
|
|
39
|
+
"yarn": ">=1.5.1"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
43
|
+
"flow": "node_modules/.bin/flow",
|
|
44
|
+
"flow-typed": "node_modules/.bin/flow-typed"
|
|
45
|
+
},
|
|
46
|
+
"author": "Rodrigo Figueira",
|
|
47
|
+
"license": "MIT",
|
|
48
|
+
"nativePackage": true,
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"babel-cli": "^6.24.1",
|
|
51
|
+
"babel-eslint": "^7.2.3",
|
|
52
|
+
"eslint": "^4.4.1",
|
|
53
|
+
"eslint-plugin-flowtype": "^2.35.0",
|
|
54
|
+
"eslint-plugin-react": "^7.2.0",
|
|
55
|
+
"eslint-plugin-react-native": "^3.0.1",
|
|
56
|
+
"flow-bin": "^0.85.0",
|
|
57
|
+
"prop-types": "^15.5.10",
|
|
58
|
+
"react": "^15.4.2",
|
|
59
|
+
"react-native": "^0.61.5"
|
|
60
|
+
},
|
|
61
|
+
"peerDependencies": {
|
|
62
|
+
"react": ">=15.4.2",
|
|
63
|
+
"react-native": ">=0.41.2"
|
|
64
|
+
}
|
|
65
|
+
}
|