-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathindex.js
executable file
·88 lines (70 loc) · 2.63 KB
/
index.js
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
const ReactNative = require('react-native')
const beaconsAndroid = ReactNative.NativeModules.BeaconsAndroidModule
const PARSER_IBEACON = 'm:0-3=4c000215,i:4-19,i:20-21,i:22-23,p:24-24'
const PARSER_ESTIMOTE = 'm:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24'
const tramissionSupport = {
0: 'SUPPORTED',
1: 'NOT_SUPPORTED_MIN_SDK',
2: 'NOT_SUPPORTED_BLE',
3: 'DEPRECATED_NOT_SUPPORTED_MULTIPLE_ADVERTISEMENTS',
4: 'NOT_SUPPORTED_CANNOT_GET_ADVERTISER',
5: 'NOT_SUPPORTED_CANNOT_GET_ADVERTISER_MULTIPLE_ADVERTISEMENTS'
}
const setHardwareEqualityEnforced = (e) => {
beaconsAndroid.setHardwareEqualityEnforced(e)
}
const detectIBeacons = () => {
beaconsAndroid.addParser(PARSER_IBEACON)
}
const detectEstimotes = () => {
beaconsAndroid.addParser(PARSER_ESTIMOTE)
}
const detectCustomBeaconLayout = (parser) => {
beaconsAndroid.addParser(parser)
}
const setBackgroundScanPeriod = (period) => {
beaconsAndroid.setBackgroundScanPeriod(period)
}
const setBackgroundBetweenScanPeriod = (period) => {
beaconsAndroid.setBackgroundBetweenScanPeriod(period)
}
const setForegroundScanPeriod = (period) => {
beaconsAndroid.setForegroundScanPeriod(period)
}
const getRangedRegions = () => new Promise((resolve, reject) => {
beaconsAndroid.getRangedRegions(resolve)
})
const getMonitoredRegions = () => new Promise((resolve, reject) => {
beaconsAndroid.getMonitoredRegions(resolve)
})
const checkTransmissionSupported = () => new Promise((resolve, reject) => {
beaconsAndroid.checkTransmissionSupported(status => resolve(tramissionSupport[status]))
})
const startMonitoringForRegion = (region) => new Promise((resolve, reject) => {
beaconsAndroid.startMonitoring(region.identifier, region.uuid, region.minor, region.major, resolve, reject)
})
const startRangingBeaconsInRegion = (regionId, beaconsUUID) => new Promise((resolve, reject) => {
beaconsAndroid.startRanging(regionId, beaconsUUID, resolve, reject)
})
const stopMonitoringForRegion = (region) => new Promise((resolve, reject) => {
beaconsAndroid.stopMonitoring(region.identifier, region.uuid, region.minor, region.major, resolve, reject)
})
const stopRangingBeaconsInRegion = (regionId, beaconsUUID) => new Promise((resolve, reject) => {
beaconsAndroid.stopRanging(regionId, beaconsUUID, resolve, reject)
})
module.exports = {
setHardwareEqualityEnforced,
detectIBeacons,
detectEstimotes,
detectCustomBeaconLayout,
setBackgroundScanPeriod,
setBackgroundBetweenScanPeriod,
setForegroundScanPeriod,
checkTransmissionSupported,
getRangedRegions,
getMonitoredRegions,
startMonitoringForRegion,
startRangingBeaconsInRegion,
stopMonitoringForRegion,
stopRangingBeaconsInRegion
}