@onekeyfe/react-native-ble-utils 0.1.1 → 0.1.3
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/android/src/main/java/so/onekey/lib/ble/utils/BleUtilsModule.kt +44 -1
- package/dist/commonjs/index.js +28 -0
- package/dist/commonjs/index.js.map +1 -1
- package/dist/module/index.js +28 -0
- package/dist/module/index.js.map +1 -1
- package/dist/typescript/commonjs/src/index.d.ts +10 -0
- package/dist/typescript/commonjs/src/index.d.ts.map +1 -1
- package/dist/typescript/module/src/index.d.ts +10 -0
- package/dist/typescript/module/src/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +36 -0
|
@@ -32,7 +32,7 @@ class BleUtilsModule(private val reactContext: ReactApplicationContext) :
|
|
|
32
32
|
private fun getBluetoothManager(): BluetoothManager? {
|
|
33
33
|
if (bluetoothManager == null) {
|
|
34
34
|
bluetoothManager =
|
|
35
|
-
reactContext.getSystemService(Context.BLUETOOTH_SERVICE)
|
|
35
|
+
reactContext.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager?
|
|
36
36
|
}
|
|
37
37
|
return bluetoothManager
|
|
38
38
|
}
|
|
@@ -124,6 +124,49 @@ class BleUtilsModule(private val reactContext: ReactApplicationContext) :
|
|
|
124
124
|
callback.invoke(state)
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
+
@SuppressLint("MissingPermission")
|
|
128
|
+
@ReactMethod
|
|
129
|
+
fun pairDevice(macAddress: String, callback: Callback) {
|
|
130
|
+
val adapter = getBluetoothAdapter()
|
|
131
|
+
if (adapter == null) {
|
|
132
|
+
callback.invoke("Bluetooth not supported", null)
|
|
133
|
+
return
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
try {
|
|
137
|
+
val device = adapter.getRemoteDevice(macAddress)
|
|
138
|
+
|
|
139
|
+
var bonded = false
|
|
140
|
+
var bonding = false
|
|
141
|
+
|
|
142
|
+
when (device.bondState) {
|
|
143
|
+
BluetoothDevice.BOND_BONDED -> {
|
|
144
|
+
bonded = true
|
|
145
|
+
bonding = false
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
BluetoothDevice.BOND_BONDING -> {
|
|
149
|
+
bonded = false
|
|
150
|
+
bonding = true
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
BluetoothDevice.BOND_NONE -> {
|
|
154
|
+
val started = device.createBond()
|
|
155
|
+
bonded = false
|
|
156
|
+
bonding = started
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
val map: WritableMap = Arguments.createMap()
|
|
161
|
+
map.putBoolean("bonded", bonded)
|
|
162
|
+
map.putBoolean("bonding", bonding)
|
|
163
|
+
callback.invoke(null, map)
|
|
164
|
+
} catch (e: Exception) {
|
|
165
|
+
Log.e(LOG_TAG, "pairDevice error: ${e.message}")
|
|
166
|
+
callback.invoke(e.message, null)
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
127
170
|
@SuppressLint("MissingPermission")
|
|
128
171
|
@ReactMethod
|
|
129
172
|
fun getBondedPeripherals(callback: Callback) {
|
package/dist/commonjs/index.js
CHANGED
|
@@ -22,6 +22,34 @@ class BleUtils {
|
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
/**
|
|
26
|
+
* [Android only]
|
|
27
|
+
* @param macAddress
|
|
28
|
+
* @returns
|
|
29
|
+
*/
|
|
30
|
+
pairDevice(macAddress) {
|
|
31
|
+
if (_reactNative.Platform.OS !== 'android') return Promise.resolve({
|
|
32
|
+
bonded: true,
|
|
33
|
+
bonding: false
|
|
34
|
+
});
|
|
35
|
+
return new Promise((fulfill, reject) => {
|
|
36
|
+
BleUtilsModule.pairDevice(macAddress, (error, result) => {
|
|
37
|
+
if (error) {
|
|
38
|
+
reject(error);
|
|
39
|
+
} else {
|
|
40
|
+
if (result) {
|
|
41
|
+
fulfill(result);
|
|
42
|
+
} else {
|
|
43
|
+
fulfill({
|
|
44
|
+
bonded: false,
|
|
45
|
+
bonding: false
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
25
53
|
/**
|
|
26
54
|
*
|
|
27
55
|
* @param serviceUUIDs [optional] not used on android, optional on ios.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","BleUtilsModule","NativeModules","BleUtils","UiEventEmitter","constructor","Platform","OS","NativeEventEmitter","checkState","Promise","fulfill","_","state","
|
|
1
|
+
{"version":3,"names":["_reactNative","require","BleUtilsModule","NativeModules","BleUtils","UiEventEmitter","constructor","Platform","OS","NativeEventEmitter","checkState","Promise","fulfill","_","state","pairDevice","macAddress","resolve","bonded","bonding","reject","error","result","getConnectedPeripherals","serviceUUIDs","getBondedPeripherals","onDeviceBondState","callback","addListener","removeAllListeners","_default","exports","default"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAGA,MAAM;EAAEC;AAAe,CAAC,GAAGC,0BAAa;AAMxC,MAAMC,QAAQ,CAAC;EACbC,cAAc,GAA8B,IAAI;EAEhDC,WAAWA,CAAA,EAAG;IACZ,IAAIC,qBAAQ,CAACC,EAAE,KAAK,SAAS,EAAE;IAC/B,IAAI,CAACH,cAAc,GAAG,IAAII,+BAAkB,CAACP,cAAc,CAAC;EAC9D;EAEAQ,UAAUA,CAAA,EAAG;IACX,OAAO,IAAIC,OAAO,CAAW,CAACC,OAAO,EAAEC,CAAC,KAAK;MAC3CX,cAAc,CAACQ,UAAU,CAAEI,KAAe,IAAK;QAC7CF,OAAO,CAACE,KAAK,CAAC;MAChB,CAAC,CAAC;IACJ,CAAC,CAAC;EACJ;;EAEA;AACF;AACA;AACA;AACA;EACEC,UAAUA,CAACC,UAAkB,EAA6B;IACxD,IAAIT,qBAAQ,CAACC,EAAE,KAAK,SAAS,EAC3B,OAAOG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ACU,MAAM,CAAC;UACjB,CAAC,MAAM;YACLV,OAAO,CAAC,EAAE,CAAC;UACb;QACF;MACF,CACF,CAAC;IACH,CAAC,CAAC;EACJ;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;EACEc,iBAAiBA,CAACC,QAA0C,EAAE;IAC5D,IAAIpB,qBAAQ,CAACC,EAAE,KAAK,SAAS,EAAE;IAC/B,IAAI,CAACH,cAAc,EAAEuB,WAAW,CAAC,mBAAmB,EAAED,QAAQ,CAAC;IAC/D,OAAO,MAAM;MACX,IAAI,CAACtB,cAAc,EAAEwB,kBAAkB,CAAC,mBAAmB,CAAC;IAC9D,CAAC;EACH;AACF;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEc,IAAI5B,QAAQ,CAAC,CAAC","ignoreList":[]}
|
package/dist/module/index.js
CHANGED
|
@@ -18,6 +18,34 @@ class BleUtils {
|
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* [Android only]
|
|
23
|
+
* @param macAddress
|
|
24
|
+
* @returns
|
|
25
|
+
*/
|
|
26
|
+
pairDevice(macAddress) {
|
|
27
|
+
if (Platform.OS !== 'android') return Promise.resolve({
|
|
28
|
+
bonded: true,
|
|
29
|
+
bonding: false
|
|
30
|
+
});
|
|
31
|
+
return new Promise((fulfill, reject) => {
|
|
32
|
+
BleUtilsModule.pairDevice(macAddress, (error, result) => {
|
|
33
|
+
if (error) {
|
|
34
|
+
reject(error);
|
|
35
|
+
} else {
|
|
36
|
+
if (result) {
|
|
37
|
+
fulfill(result);
|
|
38
|
+
} else {
|
|
39
|
+
fulfill({
|
|
40
|
+
bonded: false,
|
|
41
|
+
bonding: false
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
21
49
|
/**
|
|
22
50
|
*
|
|
23
51
|
* @param serviceUUIDs [optional] not used on android, optional on ios.
|
package/dist/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NativeEventEmitter","NativeModules","Platform","BleUtilsModule","BleUtils","UiEventEmitter","constructor","OS","checkState","Promise","fulfill","_","state","
|
|
1
|
+
{"version":3,"names":["NativeEventEmitter","NativeModules","Platform","BleUtilsModule","BleUtils","UiEventEmitter","constructor","OS","checkState","Promise","fulfill","_","state","pairDevice","macAddress","resolve","bonded","bonding","reject","error","result","getConnectedPeripherals","serviceUUIDs","getBondedPeripherals","onDeviceBondState","callback","addListener","removeAllListeners"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,SAASA,kBAAkB,EAAEC,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AAG1E,MAAM;EAAEC;AAAe,CAAC,GAAGF,aAAa;AAMxC,MAAMG,QAAQ,CAAC;EACbC,cAAc,GAA8B,IAAI;EAEhDC,WAAWA,CAAA,EAAG;IACZ,IAAIJ,QAAQ,CAACK,EAAE,KAAK,SAAS,EAAE;IAC/B,IAAI,CAACF,cAAc,GAAG,IAAIL,kBAAkB,CAACG,cAAc,CAAC;EAC9D;EAEAK,UAAUA,CAAA,EAAG;IACX,OAAO,IAAIC,OAAO,CAAW,CAACC,OAAO,EAAEC,CAAC,KAAK;MAC3CR,cAAc,CAACK,UAAU,CAAEI,KAAe,IAAK;QAC7CF,OAAO,CAACE,KAAK,CAAC;MAChB,CAAC,CAAC;IACJ,CAAC,CAAC;EACJ;;EAEA;AACF;AACA;AACA;AACA;EACEC,UAAUA,CAACC,UAAkB,EAA6B;IACxD,IAAIZ,QAAQ,CAACK,EAAE,KAAK,SAAS,EAC3B,OAAOE,OAAO,CAACM,OAAO,CAAC;MACrBC,MAAM,EAAE,IAAI;MACZC,OAAO,EAAE;IACX,CAAC,CAAC;IACJ,OAAO,IAAIR,OAAO,CAAmB,CAACC,OAAO,EAAEQ,MAAM,KAAK;MACxDf,cAAc,CAACU,UAAU,CACvBC,UAAU,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AIvB,QAAQ,CAACK,EAAE,KAAK,SAAS,EAAE;IAC/B,IAAI,CAACF,cAAc,EAAEqB,WAAW,CAAC,mBAAmB,EAAED,QAAQ,CAAC;IAC/D,OAAO,MAAM;MACX,IAAI,CAACpB,cAAc,EAAEsB,kBAAkB,CAAC,mBAAmB,CAAC;IAC9D,CAAC;EACH;AACF;AAEA,eAAe,IAAIvB,QAAQ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
import { NativeEventEmitter } from 'react-native';
|
|
2
2
|
import type { BleState, Peripheral, BondState, AdvertisingData } from './type';
|
|
3
|
+
type PairDeviceResult = {
|
|
4
|
+
bonded: boolean;
|
|
5
|
+
bonding: boolean;
|
|
6
|
+
};
|
|
3
7
|
declare class BleUtils {
|
|
4
8
|
UiEventEmitter: NativeEventEmitter | null;
|
|
5
9
|
constructor();
|
|
6
10
|
checkState(): Promise<BleState>;
|
|
11
|
+
/**
|
|
12
|
+
* [Android only]
|
|
13
|
+
* @param macAddress
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
pairDevice(macAddress: string): Promise<PairDeviceResult>;
|
|
7
17
|
/**
|
|
8
18
|
*
|
|
9
19
|
* @param serviceUUIDs [optional] not used on android, optional on ios.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAA2B,MAAM,cAAc,CAAC;AAC3E,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAA2B,MAAM,cAAc,CAAC;AAC3E,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAG/E,KAAK,gBAAgB,GAAG;IACtB,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,cAAM,QAAQ;IACZ,cAAc,EAAE,kBAAkB,GAAG,IAAI,CAAQ;;IAOjD,UAAU;IAQV;;;;OAIG;IACH,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IA2BzD;;;;OAIG;IACH,uBAAuB,CAAC,YAAY,GAAE,MAAM,EAAO;IAmBnD;;;OAGG;IACH,oBAAoB;IAkBpB;;;;;;OAMG;IACH,iBAAiB,CAAC,QAAQ,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,IAAI;CAO7D;;AAED,wBAA8B;AAC9B,YAAY,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
import { NativeEventEmitter } from 'react-native';
|
|
2
2
|
import type { BleState, Peripheral, BondState, AdvertisingData } from './type';
|
|
3
|
+
type PairDeviceResult = {
|
|
4
|
+
bonded: boolean;
|
|
5
|
+
bonding: boolean;
|
|
6
|
+
};
|
|
3
7
|
declare class BleUtils {
|
|
4
8
|
UiEventEmitter: NativeEventEmitter | null;
|
|
5
9
|
constructor();
|
|
6
10
|
checkState(): Promise<BleState>;
|
|
11
|
+
/**
|
|
12
|
+
* [Android only]
|
|
13
|
+
* @param macAddress
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
pairDevice(macAddress: string): Promise<PairDeviceResult>;
|
|
7
17
|
/**
|
|
8
18
|
*
|
|
9
19
|
* @param serviceUUIDs [optional] not used on android, optional on ios.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAA2B,MAAM,cAAc,CAAC;AAC3E,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAA2B,MAAM,cAAc,CAAC;AAC3E,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAG/E,KAAK,gBAAgB,GAAG;IACtB,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,cAAM,QAAQ;IACZ,cAAc,EAAE,kBAAkB,GAAG,IAAI,CAAQ;;IAOjD,UAAU;IAQV;;;;OAIG;IACH,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IA2BzD;;;;OAIG;IACH,uBAAuB,CAAC,YAAY,GAAE,MAAM,EAAO;IAmBnD;;;OAGG;IACH,oBAAoB;IAkBpB;;;;;;OAMG;IACH,iBAAiB,CAAC,QAAQ,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,IAAI;CAO7D;;AAED,wBAA8B;AAC9B,YAAY,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,eAAe,EAAE,CAAC"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -2,6 +2,10 @@ import { NativeEventEmitter, NativeModules, Platform } from 'react-native';
|
|
|
2
2
|
import type { BleState, Peripheral, BondState, AdvertisingData } from './type';
|
|
3
3
|
|
|
4
4
|
const { BleUtilsModule } = NativeModules;
|
|
5
|
+
type PairDeviceResult = {
|
|
6
|
+
bonded: boolean;
|
|
7
|
+
bonding: boolean;
|
|
8
|
+
};
|
|
5
9
|
|
|
6
10
|
class BleUtils {
|
|
7
11
|
UiEventEmitter: NativeEventEmitter | null = null;
|
|
@@ -19,6 +23,38 @@ class BleUtils {
|
|
|
19
23
|
});
|
|
20
24
|
}
|
|
21
25
|
|
|
26
|
+
/**
|
|
27
|
+
* [Android only]
|
|
28
|
+
* @param macAddress
|
|
29
|
+
* @returns
|
|
30
|
+
*/
|
|
31
|
+
pairDevice(macAddress: string): Promise<PairDeviceResult> {
|
|
32
|
+
if (Platform.OS !== 'android')
|
|
33
|
+
return Promise.resolve({
|
|
34
|
+
bonded: true,
|
|
35
|
+
bonding: false,
|
|
36
|
+
});
|
|
37
|
+
return new Promise<PairDeviceResult>((fulfill, reject) => {
|
|
38
|
+
BleUtilsModule.pairDevice(
|
|
39
|
+
macAddress,
|
|
40
|
+
(error: string | null, result: PairDeviceResult | null) => {
|
|
41
|
+
if (error) {
|
|
42
|
+
reject(error);
|
|
43
|
+
} else {
|
|
44
|
+
if (result) {
|
|
45
|
+
fulfill(result);
|
|
46
|
+
} else {
|
|
47
|
+
fulfill({
|
|
48
|
+
bonded: false,
|
|
49
|
+
bonding: false,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
22
58
|
/**
|
|
23
59
|
*
|
|
24
60
|
* @param serviceUUIDs [optional] not used on android, optional on ios.
|