From 5022cae28b47b282fc79f91e77d987964a3b1db9 Mon Sep 17 00:00:00 2001 From: Annie_wang Date: Wed, 6 Sep 2023 15:45:17 +0800 Subject: [PATCH] update docs Signed-off-by: Annie_wang --- .../reference/apis/js-apis-bluetooth-ble.md | 74 +++++++++++++++++-- 1 file changed, 67 insertions(+), 7 deletions(-) diff --git a/en/application-dev/reference/apis/js-apis-bluetooth-ble.md b/en/application-dev/reference/apis/js-apis-bluetooth-ble.md index 03c7b7eded..3fc7322594 100644 --- a/en/application-dev/reference/apis/js-apis-bluetooth-ble.md +++ b/en/application-dev/reference/apis/js-apis-bluetooth-ble.md @@ -744,7 +744,7 @@ Subscribes to characteristic write request events. | Name | Type | Mandatory | Description | | -------- | ---------------------------------------- | ---- | -------------------------------------- | -| type | string | Yes | Event type. The value **characteristicWrite** indicates a characteristic write request event.| +| type | string | Yes | Event type. The value is **characteristicWrite**, which indicates a characteristic write request event.| | callback | Callback<[CharacteristicWriteRequest](#characteristicwriterequest)> | Yes | Callback invoked to return a characteristic write request from the GATT client. | **Example** @@ -983,6 +983,66 @@ gattServer.off('connectionStateChange'); ``` +### on('BLEMtuChange') + +on(type: 'BLEMtuChange', callback: Callback<number>): void + +Subscribes to MTU status changes for the server. + +**Required permissions**: ohos.permission.ACCESS_BLUETOOTH + +**System capability**: SystemCapability.Communication.Bluetooth.Core + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | ---------------------------------------- | ---- | ---------------------------------------- | +| type | string | Yes | Type of event to subscribe to. The value is **BLEMtuChange**, which indicates the MTU status changes. If this parameter is not set correctly, the callback cannot be registered.| +| callback | Callback<number> | Yes | Callback invoked to return the number of MTU bytes.| + +**Example** + +```js +try { + let gattServer = ble.createGattServer(); + gattServer.on('BLEMtuChange', (mtu) => { + console.info('BLEMtuChange, mtu: ' + mtu); + }); +} catch (err) { + console.error('errCode: ' + err.code + ', errMessage: ' + err.message); +} +``` + + +### off('BLEMtuChange') + +off(type: 'BLEMtuChange', callback?: Callback<number>): void + +Unsubscribes from MTU status changes for the server. + +**Required permissions**: ohos.permission.ACCESS_BLUETOOTH + +**System capability**: SystemCapability.Communication.Bluetooth.Core + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | ---------------------------------------- | ---- | ---------------------------------------- | +| type | string | Yes | Type of event to unsubscribe from. The value is **BLEMtuChange**, which indicates the MTU status changes. If this parameter is not set correctly, the callback cannot be unregistered.| +| callback | Callback<number> | No | Callback for the MTU status changes. If this parameter is not set, this API unsubscribes from all callbacks corresponding to **type**.| + +**Example** + +```js +try { + let gattServer = ble.createGattServer(); + gattServer.off('BLEMtuChange'); +} catch (err) { + console.error('errCode: ' + err.code + ', errMessage: ' + err.message); +} +``` + + ## GattClientDevice Implements the GATT client. Before using an API of this class, you must create a **GattClientDevice** instance using **createGattClientDevice(deviceId: string)**. @@ -2179,7 +2239,7 @@ try { on(type: 'BLEMtuChange', callback: Callback<number>): void -Subscribes to MTU status changes. +Subscribes to MTU status changes for the client. **Required permissions**: ohos.permission.ACCESS_BLUETOOTH @@ -2189,8 +2249,8 @@ Subscribes to MTU status changes. | Name | Type | Mandatory | Description | | -------- | ---------------------------------------- | ---- | ---------------------------------------- | -| type | string | Yes | Event type. The value is **BLEMtuChange**, which indicates a MTU status change event.| -| callback | Callback<number> | Yes | Callback invoked to return the MTU status, which can be connected or disconnected.| +| type | string | Yes | Type of event to subscribe to. The value is **BLEMtuChange**, which indicates the MTU status changes. If this parameter is not set correctly, the callback cannot be registered.| +| callback | Callback<number> | Yes | Callback invoked to return the number of MTU bytes.| **Example** @@ -2210,7 +2270,7 @@ try { off(type: 'BLEMtuChange', callback?: Callback<number>): void -Unsubscribes from MTU status changes. +Unsubscribes from MTU status changes for the client. **Required permissions**: ohos.permission.ACCESS_BLUETOOTH @@ -2220,8 +2280,8 @@ Unsubscribes from MTU status changes. | Name | Type | Mandatory | Description | | -------- | ---------------------------------------- | ---- | ---------------------------------------- | -| type | string | Yes | Event type. The value is **BLEMtuChange**, which indicates a MTU status change event.| -| callback | Callback<number> | No | Callback for MTU status changes. If this parameter is not set, this API unsubscribes from all callbacks corresponding to **type**.| +| type | string | Yes | Type of event to unsubscribe from. The value is **BLEMtuChange**, which indicates the MTU status changes. If this parameter is not set correctly, the callback cannot be unregistered.| +| callback | Callback<number> | No | Callback for the MTU status changes. If this parameter is not set, this API unsubscribes from all callbacks corresponding to **type**.| **Example** -- GitLab