@react-native-ohos/react-native-ble-plx 3.2.1 → 3.5.1
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/README.OpenSource +2 -2
- package/README.md +1 -1
- package/harmony/rn_bleplx/BuildProfile.ets +9 -0
- package/harmony/rn_bleplx/hvigorfile.ts +5 -1
- package/harmony/rn_bleplx/index.ets +5 -27
- package/harmony/rn_bleplx/oh-package.json5 +1 -1
- package/harmony/rn_bleplx/src/main/cpp/CMakeLists.txt +2 -2
- package/harmony/rn_bleplx/src/main/cpp/generated/{RNOH/generated/turbo_modules/BlePlx.cpp → BlePlx.cpp} +9 -4
- package/harmony/rn_bleplx/src/main/cpp/generated/{RNOH/generated/turbo_modules/BlePlx.h → BlePlx.h} +6 -1
- package/harmony/rn_bleplx/src/main/cpp/generated/{RNOH/generated/BaseReactNativeBlePlxPackage.h → BlePlxRNOHGeneratedPackage.h} +21 -10
- package/harmony/rn_bleplx/src/main/ets/BleDevice.ts +4 -24
- package/harmony/rn_bleplx/src/main/ets/BleModule.ts +26 -37
- package/harmony/rn_bleplx/src/main/ets/BlePlxInterface.ts +4 -24
- package/harmony/rn_bleplx/src/main/ets/BlePlxModule.ts +9 -29
- package/harmony/rn_bleplx/src/main/ets/BlePlxPackage.ts +26 -0
- package/harmony/rn_bleplx/src/main/ets/Characteristic.ts +3 -23
- package/harmony/rn_bleplx/src/main/ets/CommonConstants.ts +4 -24
- package/harmony/rn_bleplx/src/main/ets/Descriptor.ts +3 -23
- package/harmony/rn_bleplx/src/main/ets/Service.ts +3 -23
- package/harmony/rn_bleplx/src/main/ets/common/BleError.ts +3 -23
- package/harmony/rn_bleplx/src/main/ets/common/BleErrorToJsObjectConverter.ts +4 -24
- package/harmony/rn_bleplx/src/main/ets/common/BleEvent.ts +4 -24
- package/harmony/rn_bleplx/src/main/ets/common/BleUtils.ts +3 -23
- package/harmony/rn_bleplx/src/main/ets/common/IdGenerator.ts +3 -23
- package/harmony/rn_bleplx/src/main/ets/common/IdGeneratorKey.ts +3 -23
- package/harmony/rn_bleplx/src/main/ets/common/InstanceIdGenerator.ts +4 -24
- package/harmony/rn_bleplx/src/main/ets/common/Logger.ts +1 -1
- package/harmony/rn_bleplx/src/main/ets/common/PermissionHandler.ts +3 -23
- package/harmony/rn_bleplx/src/main/ets/common/ServiceFactory.ts +3 -23
- package/harmony/rn_bleplx/src/main/ets/generated/components/ts.ts +4 -1
- package/harmony/rn_bleplx/src/main/ets/generated/index.ets +4 -1
- package/harmony/rn_bleplx/src/main/ets/generated/ts.ts +4 -1
- package/harmony/rn_bleplx/src/main/ets/generated/turboModules/BlePlx.ts +9 -4
- package/harmony/rn_bleplx/src/main/ets/generated/turboModules/ts.ts +4 -1
- package/harmony/rn_bleplx/ts.ts +6 -0
- package/harmony/rn_bleplx.har +0 -0
- package/package.json +11 -20
- package/src/BleManager.js +55 -18
- package/src/BleModule.js +14 -4
- package/src/Characteristic.js +18 -4
- package/src/Descriptor.js +2 -1
- package/src/Device.js +19 -11
- package/src/NativeBlePlx.ts +6 -26
- package/src/Service.js +20 -4
- package/src/TypeDefinition.js +5 -0
- package/src/Utils.js +3 -0
- package/src/index.d.ts +17 -4
- package/harmony/rn_bleplx/src/main/cpp/BlePlxPackage.h +0 -36
- package/harmony/rn_bleplx/src/main/cpp/generated/react/renderer/components/react_native_ble_plx/ComponentDescriptors.h +0 -22
- package/harmony/rn_bleplx/src/main/cpp/generated/react/renderer/components/react_native_ble_plx/EventEmitters.cpp +0 -18
- package/harmony/rn_bleplx/src/main/cpp/generated/react/renderer/components/react_native_ble_plx/EventEmitters.h +0 -19
- package/harmony/rn_bleplx/src/main/cpp/generated/react/renderer/components/react_native_ble_plx/Props.cpp +0 -21
- package/harmony/rn_bleplx/src/main/cpp/generated/react/renderer/components/react_native_ble_plx/Props.h +0 -20
- package/harmony/rn_bleplx/src/main/cpp/generated/react/renderer/components/react_native_ble_plx/ShadowNodes.cpp +0 -19
- package/harmony/rn_bleplx/src/main/cpp/generated/react/renderer/components/react_native_ble_plx/ShadowNodes.h +0 -25
- package/harmony/rn_bleplx/src/main/cpp/generated/react/renderer/components/react_native_ble_plx/States.cpp +0 -18
- package/harmony/rn_bleplx/src/main/cpp/generated/react/renderer/components/react_native_ble_plx/States.h +0 -23
- package/harmony/rn_bleplx/src/main/ets/BlePlxPackage.ets +0 -47
- package/harmony/rn_bleplx/ts.ets +0 -26
package/README.OpenSource
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
"Name": "react-native-ble-plx",
|
|
4
4
|
"License": "Apache-2.0 license",
|
|
5
5
|
"License File": "LICENSE",
|
|
6
|
-
"Version Number": "3.
|
|
6
|
+
"Version Number": "3.5.0",
|
|
7
7
|
"Owner" : "xiafeng@huawei.com",
|
|
8
8
|
"Upstream URL": "https://github.com/dotintent/react-native-ble-plx",
|
|
9
9
|
"Description": "React Native BLE library"
|
|
10
10
|
}
|
|
11
|
-
]
|
|
11
|
+
]
|
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# @react-native-ohos/react-native-ble-plx
|
|
2
|
-
This project is based on [react-native-ble-plx](https://github.com/dotintent/react-native-ble-plx
|
|
2
|
+
This project is based on [react-native-ble-plx@3.5.0](https://github.com/dotintent/react-native-ble-plx/tree/v3.5.0)
|
|
3
3
|
## Documentation
|
|
4
4
|
[中文](https://gitee.com/react-native-oh-library/usage-docs/blob/master/zh-cn/react-native-ble-plx.md)
|
|
5
5
|
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved
|
|
2
|
+
// Use of this source code is governed by a Apache-2.0 license that can be
|
|
3
|
+
// found in the LICENSE file.
|
|
4
|
+
|
|
5
|
+
export default class BuildProfile {
|
|
6
|
+
static readonly HAR_VERSION = '3.5.1';
|
|
7
|
+
static readonly BUILD_MODE_NAME = 'debug';
|
|
8
|
+
static readonly DEBUG = true;
|
|
9
|
+
}
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
+
// Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved
|
|
2
|
+
// Use of this source code is governed by a Apache-2.0 license that can be
|
|
3
|
+
// found in the LICENSE file.
|
|
4
|
+
|
|
1
5
|
// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently.
|
|
2
|
-
export { harTasks } from '@ohos/hvigor-ohos-plugin';
|
|
6
|
+
export { harTasks } from '@ohos/hvigor-ohos-plugin';
|
|
@@ -1,27 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
import { BlePlxPackage } from './src/main/ets/BlePlxPackage'
|
|
26
|
-
export * from "./ts"
|
|
27
|
-
export default BlePlxPackage
|
|
1
|
+
// Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved
|
|
2
|
+
// Use of this source code is governed by a Apache-2.0 license that can be
|
|
3
|
+
// found in the LICENSE file.
|
|
4
|
+
|
|
5
|
+
export * from "./ts"
|
|
@@ -2,8 +2,8 @@ cmake_minimum_required(VERSION 3.13)
|
|
|
2
2
|
set(CMAKE_VERBOSE_MAKEFILE on)
|
|
3
3
|
|
|
4
4
|
set(rnoh_ble_plx_generated_dir "${CMAKE_CURRENT_SOURCE_DIR}/generated")
|
|
5
|
-
file(GLOB_RECURSE rnoh_ble_plx_generated_SRC "${rnoh_ble_plx_generated_dir}
|
|
5
|
+
file(GLOB_RECURSE rnoh_ble_plx_generated_SRC "${rnoh_ble_plx_generated_dir}/*.cpp")
|
|
6
6
|
file(GLOB rnoh_ble_plx_SRC CONFIGURE_DEPENDS *.cpp)
|
|
7
7
|
add_library(rnoh_ble_plx SHARED ${rnoh_ble_plx_SRC} ${rnoh_ble_plx_generated_SRC})
|
|
8
8
|
target_include_directories(rnoh_ble_plx PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${rnoh_ble_plx_generated_dir})
|
|
9
|
-
target_link_libraries(rnoh_ble_plx PUBLIC rnoh)
|
|
9
|
+
target_link_libraries(rnoh_ble_plx PUBLIC rnoh)
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* This code was generated by "react-native codegen-
|
|
2
|
+
* This code was generated by "react-native codegen-harmony"
|
|
3
|
+
*
|
|
4
|
+
* Do not edit this file as changes may cause incorrect behavior and will be
|
|
5
|
+
* lost once the code is regenerated.
|
|
6
|
+
*
|
|
7
|
+
* @generatorVersion: 1
|
|
3
8
|
*/
|
|
4
9
|
|
|
5
10
|
#include "BlePlx.h"
|
|
@@ -42,9 +47,9 @@ BlePlx::BlePlx(const ArkTSTurboModule::Context ctx, const std::string name) : Ar
|
|
|
42
47
|
ARK_ASYNC_METHOD_METADATA(writeCharacteristicForDevice, 6),
|
|
43
48
|
ARK_ASYNC_METHOD_METADATA(writeCharacteristicForService, 5),
|
|
44
49
|
ARK_ASYNC_METHOD_METADATA(writeCharacteristic, 4),
|
|
45
|
-
ARK_ASYNC_METHOD_METADATA(monitorCharacteristicForDevice,
|
|
46
|
-
ARK_ASYNC_METHOD_METADATA(monitorCharacteristicForService,
|
|
47
|
-
ARK_ASYNC_METHOD_METADATA(monitorCharacteristic,
|
|
50
|
+
ARK_ASYNC_METHOD_METADATA(monitorCharacteristicForDevice, 5),
|
|
51
|
+
ARK_ASYNC_METHOD_METADATA(monitorCharacteristicForService, 4),
|
|
52
|
+
ARK_ASYNC_METHOD_METADATA(monitorCharacteristic, 3),
|
|
48
53
|
ARK_ASYNC_METHOD_METADATA(readDescriptorForDevice, 5),
|
|
49
54
|
ARK_ASYNC_METHOD_METADATA(readDescriptorForService, 4),
|
|
50
55
|
ARK_ASYNC_METHOD_METADATA(readDescriptorForCharacteristic, 3),
|
package/harmony/rn_bleplx/src/main/cpp/generated/{RNOH/generated/turbo_modules/BlePlx.h → BlePlx.h}
RENAMED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* This code was generated by "react-native codegen-
|
|
2
|
+
* This code was generated by "react-native codegen-harmony"
|
|
3
|
+
*
|
|
4
|
+
* Do not edit this file as changes may cause incorrect behavior and will be
|
|
5
|
+
* lost once the code is regenerated.
|
|
6
|
+
*
|
|
7
|
+
* @generatorVersion: 1
|
|
3
8
|
*/
|
|
4
9
|
|
|
5
10
|
#pragma once
|
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* This code was generated by "react-native codegen-
|
|
2
|
+
* This code was generated by "react-native codegen-harmony"
|
|
3
|
+
*
|
|
4
|
+
* Do not edit this file as changes may cause incorrect behavior and will be
|
|
5
|
+
* lost once the code is regenerated.
|
|
6
|
+
*
|
|
7
|
+
* @generatorVersion: 1
|
|
3
8
|
*/
|
|
4
9
|
|
|
5
10
|
#pragma once
|
|
6
11
|
|
|
7
12
|
#include "RNOH/Package.h"
|
|
8
13
|
#include "RNOH/ArkTSTurboModule.h"
|
|
9
|
-
#include "
|
|
14
|
+
#include "generated/BlePlx.h"
|
|
10
15
|
|
|
11
16
|
namespace rnoh {
|
|
12
17
|
|
|
13
|
-
class
|
|
18
|
+
class BlePlxRNOHGeneratedPackageTurboModuleFactoryDelegate : public TurboModuleFactoryDelegate {
|
|
14
19
|
public:
|
|
15
20
|
SharedTurboModule createTurboModule(Context ctx, const std::string &name) const override {
|
|
16
21
|
if (name == "BlePlx") {
|
|
@@ -20,29 +25,35 @@ class BaseReactNativeBlePlxPackageTurboModuleFactoryDelegate : public TurboModul
|
|
|
20
25
|
};
|
|
21
26
|
};
|
|
22
27
|
|
|
23
|
-
class
|
|
28
|
+
class BlePlxGeneratedEventEmitRequestHandler : public EventEmitRequestHandler {
|
|
24
29
|
public:
|
|
25
30
|
void handleEvent(Context const &ctx) override {
|
|
26
31
|
auto eventEmitter = ctx.shadowViewRegistry->getEventEmitter<facebook::react::EventEmitter>(ctx.tag);
|
|
32
|
+
auto componentName = ctx.shadowViewRegistry->getComponentName(ctx.tag);
|
|
33
|
+
|
|
27
34
|
if (eventEmitter == nullptr) {
|
|
28
35
|
return;
|
|
29
36
|
}
|
|
30
37
|
|
|
38
|
+
std::vector<std::string> supportedComponentNames = {
|
|
39
|
+
};
|
|
40
|
+
|
|
31
41
|
std::vector<std::string> supportedEventNames = {
|
|
32
42
|
};
|
|
33
|
-
|
|
43
|
+
|
|
44
|
+
if (std::find(supportedComponentNames.begin(), supportedComponentNames.end(), componentName) != supportedComponentNames.end() &&
|
|
45
|
+
std::find(supportedEventNames.begin(), supportedEventNames.end(), ctx.eventName) != supportedEventNames.end()) {
|
|
34
46
|
eventEmitter->dispatchEvent(ctx.eventName, ArkJS(ctx.env).getDynamic(ctx.payload));
|
|
35
47
|
}
|
|
36
48
|
}
|
|
37
49
|
};
|
|
38
50
|
|
|
39
|
-
|
|
40
|
-
class BaseReactNativeBlePlxPackage : public Package {
|
|
51
|
+
class BlePlxRNOHGeneratedPackage : public Package {
|
|
41
52
|
public:
|
|
42
|
-
|
|
53
|
+
BlePlxRNOHGeneratedPackage(Package::Context ctx) : Package(ctx){};
|
|
43
54
|
|
|
44
55
|
std::unique_ptr<TurboModuleFactoryDelegate> createTurboModuleFactoryDelegate() override {
|
|
45
|
-
return std::make_unique<
|
|
56
|
+
return std::make_unique<BlePlxRNOHGeneratedPackageTurboModuleFactoryDelegate>();
|
|
46
57
|
}
|
|
47
58
|
|
|
48
59
|
std::vector<facebook::react::ComponentDescriptorProvider> createComponentDescriptorProviders() override {
|
|
@@ -57,7 +68,7 @@ class BaseReactNativeBlePlxPackage : public Package {
|
|
|
57
68
|
|
|
58
69
|
EventEmitRequestHandlers createEventEmitRequestHandlers() override {
|
|
59
70
|
return {
|
|
60
|
-
std::make_shared<
|
|
71
|
+
std::make_shared<BlePlxGeneratedEventEmitRequestHandler>(),
|
|
61
72
|
};
|
|
62
73
|
}
|
|
63
74
|
};
|
|
@@ -1,26 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* Copyright (C) 2023 Huawei Device Co., Ltd.
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
1
|
+
// Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved
|
|
2
|
+
// Use of this source code is governed by a Apache-2.0 license that can be
|
|
3
|
+
// found in the LICENSE file.
|
|
24
4
|
|
|
25
5
|
import { Service } from './Service'
|
|
26
6
|
import { ble } from '@kit.ConnectivityKit';
|
|
@@ -96,4 +76,4 @@ export class BleDevice {
|
|
|
96
76
|
'overflowServiceUUIDs': null
|
|
97
77
|
}
|
|
98
78
|
}
|
|
99
|
-
}
|
|
79
|
+
}
|
|
@@ -1,26 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* Copyright (C) 2023 Huawei Device Co., Ltd.
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
1
|
+
// Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved
|
|
2
|
+
// Use of this source code is governed by a Apache-2.0 license that can be
|
|
3
|
+
// found in the LICENSE file.
|
|
24
4
|
|
|
25
5
|
import ble from '@ohos.bluetooth.ble';
|
|
26
6
|
import access from '@ohos.bluetooth.access';
|
|
@@ -207,11 +187,8 @@ export class BleClientManager {
|
|
|
207
187
|
*/
|
|
208
188
|
public stopDeviceScan(): Promise<void> {
|
|
209
189
|
try {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
ble.off("BLEDeviceFind");
|
|
213
|
-
ble.stopBLEScan();
|
|
214
|
-
}
|
|
190
|
+
ble.off("BLEDeviceFind");
|
|
191
|
+
ble.stopBLEScan();
|
|
215
192
|
return Promise.resolve();
|
|
216
193
|
} catch (err) {
|
|
217
194
|
Logger.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
|
|
@@ -824,8 +801,10 @@ export class BleClientManager {
|
|
|
824
801
|
public monitorCharacteristicForDevice(deviceIdentifier: string,
|
|
825
802
|
serviceUUID: string,
|
|
826
803
|
characteristicUUID: string,
|
|
827
|
-
transactionId: string
|
|
804
|
+
transactionId: string,
|
|
805
|
+
subscriptionType?: string): Promise<void> {
|
|
828
806
|
return new Promise((resolve, reject) => {
|
|
807
|
+
if(subscriptionType === null){subscriptionType = 'notification'};
|
|
829
808
|
let device = this.connectedDevices.get(deviceIdentifier);
|
|
830
809
|
if (!device) {
|
|
831
810
|
let bleError = new BleError(BleErrorCode.DeviceNotFound, 'The device is not connected.', null);
|
|
@@ -846,8 +825,18 @@ export class BleClientManager {
|
|
|
846
825
|
reject(this.errorConverter.toJs(bleError));
|
|
847
826
|
return;
|
|
848
827
|
}
|
|
849
|
-
|
|
850
|
-
|
|
828
|
+
//根据subscriptionType选择不同的操作方法
|
|
829
|
+
let operationPromise;
|
|
830
|
+
switch (subscriptionType){
|
|
831
|
+
case 'indication':
|
|
832
|
+
operationPromise = device.clientDevice.setCharacteristicChangeIndication(characteristic.gattCharacteristic, true);
|
|
833
|
+
break;
|
|
834
|
+
case 'notification':
|
|
835
|
+
default:
|
|
836
|
+
operationPromise = device.clientDevice.setCharacteristicChangeNotification(characteristic.gattCharacteristic, true);
|
|
837
|
+
break;
|
|
838
|
+
}
|
|
839
|
+
operationPromise.then(value => {
|
|
851
840
|
this.dispatchEvent(BleEvent.readEvent, [null, characteristic.asJSObject(), transactionId]);
|
|
852
841
|
resolve();
|
|
853
842
|
}).catch(err => {
|
|
@@ -866,7 +855,8 @@ export class BleClientManager {
|
|
|
866
855
|
*/
|
|
867
856
|
public monitorCharacteristicForService(serviceIdentifier: number,
|
|
868
857
|
characteristicUUID: string,
|
|
869
|
-
transactionId: string
|
|
858
|
+
transactionId: string,
|
|
859
|
+
subscriptionType?: string): Promise<void> {
|
|
870
860
|
let characteristic = this.getCharacteristicOrEmitErrorWithServiceId(serviceIdentifier, characteristicUUID);
|
|
871
861
|
if (characteristic == null) {
|
|
872
862
|
let bleError = new BleError(BleErrorCode.CharacteristicNotFound, 'The characteristic does not exist.', null);
|
|
@@ -874,25 +864,24 @@ export class BleClientManager {
|
|
|
874
864
|
bleError.characteristicUUID = characteristicUUID
|
|
875
865
|
return Promise.reject(this.errorConverter.toJs(bleError));
|
|
876
866
|
}
|
|
877
|
-
|
|
878
867
|
return this.monitorCharacteristicForDevice(characteristic.getDeviceId(), characteristic.getServiceUUID(),
|
|
879
|
-
characteristicUUID, transactionId);
|
|
868
|
+
characteristicUUID, transactionId, subscriptionType);
|
|
880
869
|
}
|
|
881
870
|
|
|
882
871
|
/**
|
|
883
872
|
* @description Setup monitoring of characteristic value.
|
|
884
873
|
*/
|
|
885
874
|
public monitorCharacteristic(characteristicIdentifier: number,
|
|
886
|
-
transactionId: string
|
|
875
|
+
transactionId: string,
|
|
876
|
+
subscriptionType?: string): Promise<void> {
|
|
887
877
|
let characteristic = this.getCharacteristicOrEmitErrorWithCharId(characteristicIdentifier)
|
|
888
878
|
if (characteristic == null) {
|
|
889
879
|
let bleError = new BleError(BleErrorCode.CharacteristicNotFound, 'The characteristic does not exist.', null);
|
|
890
880
|
bleError.characteristicUUID = characteristicIdentifier.toString()
|
|
891
881
|
return Promise.reject(this.errorConverter.toJs(bleError));
|
|
892
882
|
}
|
|
893
|
-
|
|
894
883
|
return this.monitorCharacteristicForDevice(characteristic.getDeviceId(), characteristic.getServiceUUID(),
|
|
895
|
-
characteristic.getUuid(), transactionId);
|
|
884
|
+
characteristic.getUuid(), transactionId, subscriptionType);
|
|
896
885
|
}
|
|
897
886
|
|
|
898
887
|
// Mark: Characteristics operations ---------------------------------------------------------------------------------
|
|
@@ -1,27 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* Copyright (C) 2023 Huawei Device Co., Ltd.
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
1
|
+
// Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved
|
|
2
|
+
// Use of this source code is governed by a Apache-2.0 license that can be
|
|
3
|
+
// found in the LICENSE file.
|
|
24
4
|
|
|
25
5
|
export interface BlePlxInterface {
|
|
26
6
|
dispatchEvent(name: string, value: any);
|
|
27
|
-
}
|
|
7
|
+
}
|
|
@@ -1,26 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* Copyright (C) 2023 Huawei Device Co., Ltd.
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
1
|
+
// Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved
|
|
2
|
+
// Use of this source code is governed by a Apache-2.0 license that can be
|
|
3
|
+
// found in the LICENSE file.
|
|
24
4
|
|
|
25
5
|
import { TurboModule, TurboModuleContext } from '@rnoh/react-native-openharmony/ts';
|
|
26
6
|
import { TM } from './generated/ts';
|
|
@@ -189,17 +169,17 @@ export class BlePlxModule extends TurboModule implements TM.BlePlx.Spec, BlePlxI
|
|
|
189
169
|
}
|
|
190
170
|
|
|
191
171
|
monitorCharacteristicForDevice(deviceId: string, serviceUUID: string, characteristicUUID: string,
|
|
192
|
-
transactionId: string): Promise<void> {
|
|
193
|
-
return this.manager.monitorCharacteristicForDevice(deviceId, serviceUUID, characteristicUUID, transactionId);
|
|
172
|
+
transactionId: string, subscriptionType?: string): Promise<void> {
|
|
173
|
+
return this.manager.monitorCharacteristicForDevice(deviceId, serviceUUID, characteristicUUID, transactionId, subscriptionType);
|
|
194
174
|
}
|
|
195
175
|
|
|
196
176
|
monitorCharacteristicForService(serviceIdentifier: number, characteristicUUID: string,
|
|
197
|
-
transactionId: string): Promise<void> {
|
|
198
|
-
return this.manager.monitorCharacteristicForService(serviceIdentifier, characteristicUUID, transactionId);
|
|
177
|
+
transactionId: string, subscriptionType?: string): Promise<void> {
|
|
178
|
+
return this.manager.monitorCharacteristicForService(serviceIdentifier, characteristicUUID, transactionId, subscriptionType);
|
|
199
179
|
}
|
|
200
180
|
|
|
201
|
-
monitorCharacteristic(characteristicIdentifier: number, transactionId: string): Promise<void> {
|
|
202
|
-
return this.manager.monitorCharacteristic(characteristicIdentifier, transactionId);
|
|
181
|
+
monitorCharacteristic(characteristicIdentifier: number, transactionId: string, subscriptionType?: string): Promise<void> {
|
|
182
|
+
return this.manager.monitorCharacteristic(characteristicIdentifier, transactionId, subscriptionType);
|
|
203
183
|
}
|
|
204
184
|
|
|
205
185
|
readDescriptorForDevice(deviceId: string, serviceUUID: string, characteristicUUID: string, descriptorUUID: string,
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved
|
|
2
|
+
// Use of this source code is governed by a Apache-2.0 license that can be
|
|
3
|
+
// found in the LICENSE file.
|
|
4
|
+
|
|
5
|
+
import { RNPackage, TurboModulesFactory } from '@rnoh/react-native-openharmony/ts';
|
|
6
|
+
import type { TurboModule, TurboModuleContext } from '@rnoh/react-native-openharmony/ts';
|
|
7
|
+
import { BlePlxModule } from './BlePlxModule';
|
|
8
|
+
|
|
9
|
+
class BlePlxModulesFactory extends TurboModulesFactory {
|
|
10
|
+
createTurboModule(name: string): TurboModule | null {
|
|
11
|
+
if (name == 'BlePlx') {
|
|
12
|
+
return new BlePlxModule(this.ctx);
|
|
13
|
+
}
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
hasTurboModule(name: string): boolean {
|
|
18
|
+
return name == 'BlePlx';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export class BlePlxPackage extends RNPackage {
|
|
23
|
+
createTurboModulesFactory(ctx: TurboModuleContext): TurboModulesFactory {
|
|
24
|
+
return new BlePlxModulesFactory(ctx);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -1,26 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* Copyright (C) 2023 Huawei Device Co., Ltd.
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
1
|
+
// Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved
|
|
2
|
+
// Use of this source code is governed by a Apache-2.0 license that can be
|
|
3
|
+
// found in the LICENSE file.
|
|
24
4
|
|
|
25
5
|
import ble from '@ohos.bluetooth.ble';
|
|
26
6
|
import Logger from './common/Logger';
|
|
@@ -1,30 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* Copyright (C) 2023 Huawei Device Co., Ltd.
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
1
|
+
// Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved
|
|
2
|
+
// Use of this source code is governed by a Apache-2.0 license that can be
|
|
3
|
+
// found in the LICENSE file.
|
|
24
4
|
|
|
25
5
|
export default class CommonConstants {
|
|
26
6
|
/**
|
|
27
7
|
* Log tag.
|
|
28
8
|
*/
|
|
29
9
|
static readonly TAG = '[RNOH] BlePlx';
|
|
30
|
-
}
|
|
10
|
+
}
|
|
@@ -1,26 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* Copyright (C) 2023 Huawei Device Co., Ltd.
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
1
|
+
// Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved
|
|
2
|
+
// Use of this source code is governed by a Apache-2.0 license that can be
|
|
3
|
+
// found in the LICENSE file.
|
|
24
4
|
|
|
25
5
|
import ble from '@ohos.bluetooth.ble';
|
|
26
6
|
import Logger from './common/Logger'
|
|
@@ -1,26 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* Copyright (C) 2023 Huawei Device Co., Ltd.
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
1
|
+
// Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved
|
|
2
|
+
// Use of this source code is governed by a Apache-2.0 license that can be
|
|
3
|
+
// found in the LICENSE file.
|
|
24
4
|
|
|
25
5
|
import ble from '@ohos.bluetooth.ble';
|
|
26
6
|
import Logger from './common/Logger';
|
|
@@ -1,26 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* Copyright (C) 2023 Huawei Device Co., Ltd.
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
1
|
+
// Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved
|
|
2
|
+
// Use of this source code is governed by a Apache-2.0 license that can be
|
|
3
|
+
// found in the LICENSE file.
|
|
24
4
|
|
|
25
5
|
export const BleErrorCode = {
|
|
26
6
|
UnknownError: 0,
|