提交 c1ba45f3 编写于 作者: W wusongqing

update docs against 7313+7533+7872+8055

Signed-off-by: Nwusongqing <wusongqing@huawei.com>
上级 6ce0b0f9
...@@ -9,7 +9,7 @@ System applications can call the APIs to do the following: ...@@ -9,7 +9,7 @@ System applications can call the APIs to do the following:
- Authenticate or deauthenticate a device. - Authenticate or deauthenticate a device.
- Query the trusted device list. - Query the trusted device list.
- Query local device information, including the device name, type, and ID. - Query local device information, including the device name, type, and ID.
- Publish device information for discovery purposes.
> **NOTE** > **NOTE**
> >
> - The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. > - The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
...@@ -31,23 +31,24 @@ Creates a **DeviceManager** instance. ...@@ -31,23 +31,24 @@ Creates a **DeviceManager** instance.
**System capability**: SystemCapability.DistributedHardware.DeviceManager **System capability**: SystemCapability.DistributedHardware.DeviceManager
- **Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---------- | ---------------------------------------- | ---- | ------------------------------------ | | ---------- | ---------------------------------------- | ---- | ------------------------------------ |
| bundleName | string | Yes | Bundle name of an application. | | bundleName | string | Yes | Bundle name of an application. |
| callback | AsyncCallback&lt;[DeviceManager](#devicemanager)&gt; | Yes | Callback used to return the **DeviceManager** instance created.| | callback | AsyncCallback&lt;[DeviceManager](#devicemanager)&gt; | Yes | Callback used to return the **DeviceManager** instance created.|
- Example **Example**
```
deviceManager.createDeviceManager("ohos.samples.jshelloworld", (err, data) => { ```
if (err) { deviceManager.createDeviceManager("ohos.samples.jshelloworld", (err, data) => {
console.info("createDeviceManager err:" + JSON.stringify(err)); if (err) {
return; console.info("createDeviceManager err:" + JSON.stringify(err));
} return;
console.info("createDeviceManager success"); }
let dmInstance = data; console.info("createDeviceManager success");
}); let dmInstance = data;
``` });
```
## DeviceInfo ## DeviceInfo
...@@ -61,7 +62,7 @@ Defines device information. ...@@ -61,7 +62,7 @@ Defines device information.
| deviceName | string | Yes | Device name. | | deviceName | string | Yes | Device name. |
| deviceType | [DeviceType](#devicetype) | Yes | Device type. | | deviceType | [DeviceType](#devicetype) | Yes | Device type. |
| networkId<sup>8+</sup> | string | Yes | Network ID of the device. | | networkId<sup>8+</sup> | string | Yes | Network ID of the device. |
| range<sup>9+</sup> | number | Yes | Distance between the device (discovered device) and the device that initiates device discovery. |
## DeviceType ## DeviceType
...@@ -184,6 +185,18 @@ Defines authentication information. ...@@ -184,6 +185,18 @@ Defines authentication information.
| token | number | Yes | Authentication token. | | token | number | Yes | Authentication token. |
| extraInfo | {[key:string] : any} | No | Extended field.| | extraInfo | {[key:string] : any} | No | Extended field.|
## PublishInfo
Defines published device information.
**System capability**: SystemCapability.DistributedHardware.DeviceManager
| Name | Type | Mandatory | Description |
| ------------- | --------------------------------- | ---- | ----------------- |
| publishId | number | Yes | ID used to identify a publication period.|
| mode | [DiscoverMode ](#discovermode) | Yes | Device discovery mode. |
| freq | [ExchangeFreq](#exchangefreq) | Yes | Frequency of device discovery. |
| ranging | boolean | Yes | Whether the device supports distance reporting. |
## DeviceManager ## DeviceManager
...@@ -198,10 +211,11 @@ Releases this **DeviceManager** instance when it is no longer used. ...@@ -198,10 +211,11 @@ Releases this **DeviceManager** instance when it is no longer used.
**System capability**: SystemCapability.DistributedHardware.DeviceManager **System capability**: SystemCapability.DistributedHardware.DeviceManager
- Example **Example**
```js
dmInstance.release(); ```js
``` dmInstance.release();
```
### getTrustedDeviceListSync ### getTrustedDeviceListSync
...@@ -212,15 +226,17 @@ Obtains all trusted devices synchronously. ...@@ -212,15 +226,17 @@ Obtains all trusted devices synchronously.
**System capability**: SystemCapability.DistributedHardware.DeviceManager **System capability**: SystemCapability.DistributedHardware.DeviceManager
- Return value **Return value**
| Name | Description |
| -------------------------------------- | --------- |
| Array&lt;[DeviceInfo](#deviceinfo)&gt; | List of trusted devices obtained.|
- Example | Name | Description |
```js | -------------------------------------- | --------- |
var deviceInfoList = dmInstance.getTrustedDeviceListSync(); | Array&lt;[DeviceInfo](#deviceinfo)&gt; | List of trusted devices obtained.|
```
**Example**
```js
var deviceInfoList = dmInstance.getTrustedDeviceListSync();
```
### getTrustedDeviceList<sup>8+</sup> ### getTrustedDeviceList<sup>8+</sup>
...@@ -231,12 +247,12 @@ Obtains all trusted devices. This API uses an asynchronous callback to return th ...@@ -231,12 +247,12 @@ Obtains all trusted devices. This API uses an asynchronous callback to return th
**System capability**: SystemCapability.DistributedHardware.DeviceManager **System capability**: SystemCapability.DistributedHardware.DeviceManager
- **Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | --------------------- | | -------- | ---------------------------------------- | ---- | --------------------- |
| callback | AsyncCallback&lt;Array&lt;[DeviceInfo](#deviceinfo)&gt;&gt; | Yes | Callback used to return the list of trusted devices.| | callback | AsyncCallback&lt;Array&lt;[DeviceInfo](#deviceinfo)&gt;&gt; | Yes | Callback used to return the list of trusted devices.|
- Example **Example**
```js ```js
dmInstance.getTrustedDeviceList((err, data) => { dmInstance.getTrustedDeviceList((err, data) => {
console.log("getTrustedDeviceList err: " + JSON.stringify(err)); console.log("getTrustedDeviceList err: " + JSON.stringify(err));
...@@ -253,12 +269,12 @@ Obtains all trusted devices. This API uses a promise to return the result. ...@@ -253,12 +269,12 @@ Obtains all trusted devices. This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedHardware.DeviceManager **System capability**: SystemCapability.DistributedHardware.DeviceManager
- Return value **Return value**
| Type | Description | | Type | Description |
| ---------------------------------------- | --------------------- | | ---------------------------------------- | --------------------- |
| Promise&lt;Array&lt;[DeviceInfo](#deviceinfo)&gt;&gt; | Promise used to return the list of trusted devices.| | Promise&lt;Array&lt;[DeviceInfo](#deviceinfo)&gt;&gt; | Promise used to return the list of trusted devices.|
- Example **Example**
```js ```js
dmInstance.getTrustedDeviceList().then((data) => { dmInstance.getTrustedDeviceList().then((data) => {
console.log('get trusted device info: ' + JSON.stringify(data)); console.log('get trusted device info: ' + JSON.stringify(data));
...@@ -275,12 +291,12 @@ Obtains local device information synchronously. ...@@ -275,12 +291,12 @@ Obtains local device information synchronously.
**System capability**: SystemCapability.DistributedHardware.DeviceManager **System capability**: SystemCapability.DistributedHardware.DeviceManager
- Return value **Return value**
| Name | Description | | Name | Description |
| -------------------------------------- | --------- | | -------------------------------------- | --------- |
| Array&lt;[DeviceInfo](#deviceinfo)&gt; | List of local devices obtained.| | Array&lt;[DeviceInfo](#deviceinfo)&gt; | List of local devices obtained.|
- Example **Example**
```js ```js
var deviceInfo = dmInstance.getLocalDeviceInfoSync(); var deviceInfo = dmInstance.getLocalDeviceInfoSync();
``` ```
...@@ -294,12 +310,12 @@ Obtains local device information. This API uses an asynchronous callback to retu ...@@ -294,12 +310,12 @@ Obtains local device information. This API uses an asynchronous callback to retu
**System capability**: SystemCapability.DistributedHardware.DeviceManager **System capability**: SystemCapability.DistributedHardware.DeviceManager
- **Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | --------- | | -------- | ---------------------------------------- | ---- | --------- |
| callback | AsyncCallback&lt;[DeviceInfo](#deviceinfo)&gt; | Yes | Callback used to return the local device information.| | callback | AsyncCallback&lt;[DeviceInfo](#deviceinfo)&gt; | Yes | Callback used to return the local device information.|
- Example **Example**
```js ```js
dmInstance.getLocalDeviceInfo((err, data) => { dmInstance.getLocalDeviceInfo((err, data) => {
console.log("getLocalDeviceInfo err: " + JSON.stringify(err)); console.log("getLocalDeviceInfo err: " + JSON.stringify(err));
...@@ -316,12 +332,12 @@ Obtains local device information. This API uses a promise to return the result. ...@@ -316,12 +332,12 @@ Obtains local device information. This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedHardware.DeviceManager **System capability**: SystemCapability.DistributedHardware.DeviceManager
- Return value **Return value**
| Type | Description | | Type | Description |
| ---------------------------------------- | --------------------- | | ---------------------------------------- | --------------------- |
| Promise&lt;[DeviceInfo](#deviceinfo)&gt; | Promise used to return the local device information.| | Promise&lt;[DeviceInfo](#deviceinfo)&gt; | Promise used to return the local device information.|
- Example **Example**
```js ```js
dmInstance.getLocalDeviceInfo().then((data) => { dmInstance.getLocalDeviceInfo().then((data) => {
console.log('get local device info: ' + JSON.stringify(data)); console.log('get local device info: ' + JSON.stringify(data));
...@@ -338,12 +354,12 @@ Starts to discover peripheral devices. ...@@ -338,12 +354,12 @@ Starts to discover peripheral devices.
**System capability**: SystemCapability.DistributedHardware.DeviceManager **System capability**: SystemCapability.DistributedHardware.DeviceManager
- **Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------------- | ------------------------------- | ---- | ----- | | ------------- | ------------------------------- | ---- | ----- |
| subscribeInfo | [SubscribeInfo](#subscribeinfo) | Yes | Subscription information.| | subscribeInfo | [SubscribeInfo](#subscribeinfo) | Yes | Subscription information.|
- Example **Example**
```js ```js
// Automatically generate a unique subscription ID. // Automatically generate a unique subscription ID.
var subscribeId = Math.floor(Math.random() * 10000 + 1000); var subscribeId = Math.floor(Math.random() * 10000 + 1000);
...@@ -359,6 +375,45 @@ Starts to discover peripheral devices. ...@@ -359,6 +375,45 @@ Starts to discover peripheral devices.
dmInstance.startDeviceDiscovery(subscribeInfo); // The deviceFound callback is invoked to notify the application when a device is discovered. dmInstance.startDeviceDiscovery(subscribeInfo); // The deviceFound callback is invoked to notify the application when a device is discovered.
``` ```
### startDeviceDiscovery9+</sup>
startDeviceDiscovery(subscribeInfo: SubscribeInfo, filterOptions: string): void
Starts to discover peripheral devices and filters discovered devices.
**System capability**: SystemCapability.DistributedHardware.DeviceManager
**Parameters**
| Name | Type | Mandatory | Description |
| ------------- | ------------------------------- | ---- | ----- |
| subscribeInfo | [SubscribeInfo](#subscribeinfo) | Yes | Subscription information.|
| filterOptions | string | No | Options for filtering discovered devices.|
**Example**
```js
// Automatically generate a unique subscription ID.
var subscribeId = Math.floor(Math.random() * 10000 + 1000);
var subscribeInfo = {
"subscribeId": subscribeId,
"mode": 0xAA, // Active discovery
"medium": 0, // Automatic. Multiple media can be used for device discovery.
"freq": 2, // High frequency
"isSameAccount": false,
"isWakeRemote": false,
"capability": 1
};
var filterOptions = {
"filter_op": "OR", // Optional. The default value is OR.
"filters": [
{
"type": "range",
"value": 50 // Filter discovered devices based on the distance (in cm).
}
]
};
dmInstance.startDeviceDiscovery(subscribeInfo, JSON.stringify(filterOptions)); // The deviceFound callback is invoked to notify the application when a device is discovered.
```
### stopDeviceDiscovery ### stopDeviceDiscovery
stopDeviceDiscovery(subscribeId: number): void stopDeviceDiscovery(subscribeId: number): void
...@@ -367,17 +422,63 @@ Stops device discovery. ...@@ -367,17 +422,63 @@ Stops device discovery.
**System capability**: SystemCapability.DistributedHardware.DeviceManager **System capability**: SystemCapability.DistributedHardware.DeviceManager
- **Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ----------- | ------ | ---- | ----- | | ----------- | ------ | ---- | ----- |
| subscribeId | number | Yes | Subscription ID.| | subscribeId | number | Yes | Subscription ID.|
- Example **Example**
```js ```js
// The subscribeId input must be the same as that automatically generated in startDeviceDiscovery. // The subscribeId input must be the same as that automatically generated in startDeviceDiscovery.
dmInstance.stopDeviceDiscovery(subscribeId); dmInstance.stopDeviceDiscovery(subscribeId);
``` ```
### publishDeviceDiscovery9+</sup>
publishDeviceDiscovery(publishInfo: PublishInfo): void
Publishes device information for discovery purposes.
**System capability**: SystemCapability.DistributedHardware.DeviceManager
**Parameters**
| Name | Type | Mandatory| Description |
| ------------- | ------------------------------- | ---- | ----- |
| publishInfo | [PublishInfo](#publishinfo) | Yes | Device information to publish.|
**Example**
```js
// Automatically generate a unique subscription ID.
var publishId = Math.floor(Math.random() * 10000 + 1000);
var publishInfo = {
"publishId": publishId,
"mode": 0xAA, // Active discovery
"freq": 2, // High frequency
"ranging": 1 // The device supports reporting the distance to the discovery initiator.
};
dmInstance.publishDeviceDiscovery(publishInfo); // A callback is invoked to notify the application when the device information is published.
```
### unPublishDeviceDiscovery
unPublishDeviceDiscovery(publishId: number): void
Stops publishing device information.
**System capability**: SystemCapability.DistributedHardware.DeviceManager
**Parameters**
| Name | Type| Mandatory| Description |
| ----------- | -------- | ---- | ----- |
| publishId | number | Yes | Publish ID.|
**Example**
```js
// The publishId input must be the same as that automatically generated in publishDeviceDiscovery.
dmInstance.unPublishDeviceDiscovery(publishId);
```
### authenticateDevice ### authenticateDevice
authenticateDevice(deviceInfo: DeviceInfo, authParam: AuthParam, callback: AsyncCallback<{deviceId: string, pinToken ?: number}>): void authenticateDevice(deviceInfo: DeviceInfo, authParam: AuthParam, callback: AsyncCallback<{deviceId: string, pinToken ?: number}>): void
...@@ -386,14 +487,14 @@ Authenticates a device. ...@@ -386,14 +487,14 @@ Authenticates a device.
**System capability**: SystemCapability.DistributedHardware.DeviceManager **System capability**: SystemCapability.DistributedHardware.DeviceManager
- **Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---------- | ---------------------------------------- | ---- | ------- | | ---------- | ---------------------------------------- | ---- | ------- |
| deviceInfo | [DeviceInfo](#deviceinfo) | Yes | Device information. | | deviceInfo | [DeviceInfo](#deviceinfo) | Yes | Device information. |
| authParam | [AuthParam](#authparam) | Yes | Authentication parameter. | | authParam | [AuthParam](#authparam) | Yes | Authentication parameter. |
| callback | AsyncCallback<{ deviceId: string, pinToken ?: number }> | Yes | Callback used to return the authentication result.| | callback | AsyncCallback<{ deviceId: string, pinToken ?: number }> | Yes | Callback used to return the authentication result.|
- Example **Example**
```js ```js
// Information about the device to authenticate. The information can be obtained from the device discovery result. // Information about the device to authenticate. The information can be obtained from the device discovery result.
var deviceInfo ={ var deviceInfo ={
...@@ -423,12 +524,13 @@ Deauthenticates a device. ...@@ -423,12 +524,13 @@ Deauthenticates a device.
**System capability**: SystemCapability.DistributedHardware.DeviceManager **System capability**: SystemCapability.DistributedHardware.DeviceManager
- **Parameters** **Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------------------------- | ---- | ----- | | Name | Type | Mandatory | Description |
| deviceInfo | [DeviceInfo](#deviceinfo) | Yes | Device information.| | ---------- | ------------------------- | ---- | ----- |
| deviceInfo | [DeviceInfo](#deviceinfo) | Yes | Device information.|
- Example **Example**
```js ```js
dmInstance.unAuthenticateDevice(deviceInfo); dmInstance.unAuthenticateDevice(deviceInfo);
``` ```
...@@ -442,13 +544,13 @@ Verifies authentication information. ...@@ -442,13 +544,13 @@ Verifies authentication information.
**System capability**: SystemCapability.DistributedHardware.DeviceManager **System capability**: SystemCapability.DistributedHardware.DeviceManager
- **Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ------- | | -------- | ---------------------------------------- | ---- | ------- |
| authInfo | [AuthInfo](#authinfo) | Yes | Authentication information. | | authInfo | [AuthInfo](#authinfo) | Yes | Authentication information. |
| authInfo | AsyncCallback<{ deviceId: string, level: number }> | Yes | Callback used to return the verification result.| | authInfo | AsyncCallback<{ deviceId: string, level: number }> | Yes | Callback used to return the verification result.|
- Example **Example**
```js ```js
let authInfo = { let authInfo = {
"authType": 1, "authType": 1,
...@@ -473,13 +575,13 @@ Subscribes to changes in the device state. ...@@ -473,13 +575,13 @@ Subscribes to changes in the device state.
**System capability**: SystemCapability.DistributedHardware.DeviceManager **System capability**: SystemCapability.DistributedHardware.DeviceManager
- **Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ------------------------------ | | -------- | ---------------------------------------- | ---- | ------------------------------ |
| type | string | Yes | Event type. The value **'deviceStateChange'** indicates a device state change event.| | type | string | Yes | Event type. The value **'deviceStateChange'** indicates a device state change event.|
| callback | Callback&lt;{ action: [DeviceStateChangeAction](#devicestatechangeaction), device: [DeviceInfo](#deviceinfo) }&gt; | Yes | Callback invoked to return the device information and state. | | callback | Callback&lt;{ action: [DeviceStateChangeAction](#devicestatechangeaction), device: [DeviceInfo](#deviceinfo) }&gt; | Yes | Callback invoked to return the device information and state. |
- Example **Example**
```js ```js
dmInstance.on('deviceStateChange', (data) => { dmInstance.on('deviceStateChange', (data) => {
console.info("deviceStateChange on:" + JSON.stringify(data)); console.info("deviceStateChange on:" + JSON.stringify(data));
...@@ -496,19 +598,20 @@ Unsubscribes from changes in the device state. ...@@ -496,19 +598,20 @@ Unsubscribes from changes in the device state.
**System capability**: SystemCapability.DistributedHardware.DeviceManager **System capability**: SystemCapability.DistributedHardware.DeviceManager
- **Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | --------------------------- | | -------- | ---------------------------------------- | ---- | --------------------------- |
| type | string | Yes | Event type. The value **'deviceStateChange'** indicates a device state change event. | | type | string | Yes | Event type. The value **'deviceStateChange'** indicates a device state change event. |
| callback | Callback&lt;{ action: [DeviceStateChangeAction](#devicestatechangeaction), device: [DeviceInfo](#deviceinfo) }&gt; | Yes | Callback invoked to return the device information and state.| | callback | Callback&lt;{ action: [DeviceStateChangeAction](#devicestatechangeaction), device: [DeviceInfo](#deviceinfo) }&gt; | Yes | Callback invoked to return the device information and state.|
- Example **Example**
```js
dmInstance.off('deviceStateChange', (data) => { ```js
console.info('deviceStateChange' + JSON.stringify(data)); dmInstance.off('deviceStateChange', (data) => {
} console.info('deviceStateChange' + JSON.stringify(data));
); }
``` );
```
### on('deviceFound') ### on('deviceFound')
...@@ -519,13 +622,13 @@ Subscribes to device discovery events. ...@@ -519,13 +622,13 @@ Subscribes to device discovery events.
**System capability**: SystemCapability.DistributedHardware.DeviceManager **System capability**: SystemCapability.DistributedHardware.DeviceManager
- **Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | -------------------------- | | -------- | ---------------------------------------- | ---- | -------------------------- |
| type | string | Yes | Event type. The value **'deviceFound'** indicates an event reported when a device is discovered.| | type | string | Yes | Event type. The value **'deviceFound'** indicates an event reported when a device is discovered.|
| callback | Callback&lt;{ subscribeId: number, device: DeviceInfo }&gt; | Yes | Callback used for device discovery. | | callback | Callback&lt;{ subscribeId: number, device: DeviceInfo }&gt; | Yes | Callback used for device discovery. |
- Example **Example**
```js ```js
dmInstance.on('deviceFound', (data) => { dmInstance.on('deviceFound', (data) => {
console.info("deviceFound:" + JSON.stringify(data)); console.info("deviceFound:" + JSON.stringify(data));
...@@ -541,13 +644,13 @@ Unsubscribes from device discovery events. ...@@ -541,13 +644,13 @@ Unsubscribes from device discovery events.
**System capability**: SystemCapability.DistributedHardware.DeviceManager **System capability**: SystemCapability.DistributedHardware.DeviceManager
- **Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | --------------------------- | | -------- | ---------------------------------------- | ---- | --------------------------- |
| type | string | Yes | Event type. The value **'deviceFound'** indicates an event reported when a device is discovered. | | type | string | Yes | Event type. The value **'deviceFound'** indicates an event reported when a device is discovered. |
| callback | Callback&lt;{ subscribeId: number, device: [DeviceInfo](#deviceinfo) }&gt; | Yes | Callback used for device discovery, which is invoked to return the device information and state.| | callback | Callback&lt;{ subscribeId: number, device: [DeviceInfo](#deviceinfo) }&gt; | Yes | Callback invoked to return the device information and state.|
- Example **Example**
```js ```js
dmInstance.off('deviceFound', (data) => { dmInstance.off('deviceFound', (data) => {
console.info('deviceFound' + JSON.stringify(data)); console.info('deviceFound' + JSON.stringify(data));
...@@ -563,13 +666,13 @@ Subscribes to device discovery failures. ...@@ -563,13 +666,13 @@ Subscribes to device discovery failures.
**System capability**: SystemCapability.DistributedHardware.DeviceManager **System capability**: SystemCapability.DistributedHardware.DeviceManager
- **Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ------------------------------ | | -------- | ---------------------------------------- | ---- | ------------------------------ |
| type | string | Yes | Event type. The event **'discoverFail'** indicates an event reported when device discovery fails.| | type | string | Yes | Event type. The event **'discoverFail'** indicates an event reported when device discovery fails.|
| callback | Callback&lt;{ subscribeId: number, reason: number }&gt; | Yes | Callback used for the device discovery failure. | | callback | Callback&lt;{ subscribeId: number, reason: number }&gt; | Yes | Callback used for the device discovery failure. |
- Example **Example**
```js ```js
dmInstance.on('discoverFail', (data) => { dmInstance.on('discoverFail', (data) => {
this.log("discoverFail on:" + JSON.stringify(data)); this.log("discoverFail on:" + JSON.stringify(data));
...@@ -585,13 +688,13 @@ Unsubscribes from device discovery failures. ...@@ -585,13 +688,13 @@ Unsubscribes from device discovery failures.
**System capability**: SystemCapability.DistributedHardware.DeviceManager **System capability**: SystemCapability.DistributedHardware.DeviceManager
- **Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ----------------- | | -------- | ---------------------------------------- | ---- | ----------------- |
| type | string | Yes | Event type. The event **'discoverFail'** indicates an event reported when device discovery fails. | | type | string | Yes | Event type. The event **'discoverFail'** indicates an event reported when device discovery fails. |
| callback | Callback&lt;{ subscribeId: number, reason: number }&gt; | Yes | Callback used for the device discovery failure.| | callback | Callback&lt;{ subscribeId: number, reason: number }&gt; | Yes | Callback used for the device discovery failure.|
- Example **Example**
```js ```js
dmInstance.off('deviceFound', (data) => { dmInstance.off('deviceFound', (data) => {
console.info('deviceFound' + JSON.stringify(data)); console.info('deviceFound' + JSON.stringify(data));
...@@ -599,6 +702,93 @@ Unsubscribes from device discovery failures. ...@@ -599,6 +702,93 @@ Unsubscribes from device discovery failures.
); );
``` ```
### on('publishSuccess')
on(type: 'publishSuccess', callback: Callback&lt;{ publishId: number }&gt;): void
Subscribes to device information publication success events.
**System capability**: SystemCapability.DistributedHardware.DeviceManager
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------------------------- | ---- | -------------------------- |
| type | string | Yes | Event type. The value **'publishSuccess'** indicates an event reported when device information is published.|
| callback | Callback&lt;{ publishId: number }&gt; | Yes | Callback invoked to return the publish ID. |
**Example**
```js
dmInstance.on('publishSuccess', (data) => {
console.info("publishSuccess:" + JSON.stringify(data));
}
);
```
### off('publishSuccess')
off(type: 'publishSuccess', callback?: Callback&lt;{ publishId: number }&gt;): void
Unsubscribes from device information publication success events.
**System capability**: SystemCapability.DistributedHardware.DeviceManager
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------------------------- | ---- | --------------------------- |
| type | string | Yes | Event type. The value **'publishSuccess'** indicates an event reported when device information is published. |
| callback | Callback&lt;{ publishId: number }&gt; | Yes | Callback used to return the publish ID.|
**Example**
```js
dmInstance.off('publishSuccess', (data) => {
console.info('publishSuccess' + JSON.stringify(data));
}
);
```
### on('publishFail')
on(type: 'publishFail', callback: Callback&lt;{ publishId: number, reason: number }&gt;): void
Subscribes to device information publication failures.
**System capability**: SystemCapability.DistributedHardware.DeviceManager
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------------------------- | ---- | ------------------------------ |
| type | string | Yes | Event type. The event **'publishFail'** indicates an event reported when publishing device information fails.|
| callback | Callback&lt;{ publishId: number, reason: number }&gt; | Yes | Callback used for the publication failure. |
**Example**
```js
dmInstance.on('publishFail', (data) => {
this.log("publishFail on:" + JSON.stringify(data));
}
);
```
### off('publishFail')
off(type: 'publishFail', callback?: Callback&lt;{ publishId: number, reason: number }&gt;): void
Unsubscribes from device information publication failures.
**System capability**: SystemCapability.DistributedHardware.DeviceManager
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------------------------- | ---- | ----------------- |
| type | string | Yes | Event type. The event **'publishFail'** indicates an event reported when publishing device information fails. |
| callback | Callback&lt;{ publishId: number, reason: number }&gt; | Yes | Callback used for the device discovery failure.|
**Example**
```js
dmInstance.off('publishFail', (data) => {
console.info('publishFail' + JSON.stringify(data));
}
);
```
### on('serviceDie') ### on('serviceDie')
...@@ -608,13 +798,13 @@ Subscribes to dead events of the **DeviceManager** service. ...@@ -608,13 +798,13 @@ Subscribes to dead events of the **DeviceManager** service.
**System capability**: SystemCapability.DistributedHardware.DeviceManager **System capability**: SystemCapability.DistributedHardware.DeviceManager
- **Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ----------------------- | ---- | ---------------------------------------- | | -------- | ----------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **'serviceDie'** indicates an event reported when the **DeviceManager** service is terminated unexpectedly.| | type | string | Yes | Event type. The value **'serviceDie'** indicates an event reported when the **DeviceManager** service is terminated unexpectedly.|
| callback | () =&gt; void | Yes | Callback invoked when a dead event of the **DeviceManager** service occurs. | | callback | () =&gt; void | Yes | Callback invoked when a dead event of the **DeviceManager** service occurs. |
- Example **Example**
```js ```js
dmInstance.on("serviceDie", () => { dmInstance.on("serviceDie", () => {
console.info("serviceDie on"); console.info("serviceDie on");
...@@ -631,13 +821,13 @@ Unsubscribes from dead events of the **DeviceManager** service. ...@@ -631,13 +821,13 @@ Unsubscribes from dead events of the **DeviceManager** service.
**System capability**: SystemCapability.DistributedHardware.DeviceManager **System capability**: SystemCapability.DistributedHardware.DeviceManager
- **Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ----------------------- | ---- | ---------------------------------------- | | -------- | ----------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **'serviceDie'** indicates an event reported when the **DeviceManager** service is terminated unexpectedly.| | type | string | Yes | Event type. The value **'serviceDie'** indicates an event reported when the **DeviceManager** service is terminated unexpectedly.|
| callback | () =&gt; void | No | Callback used to return the dead event of the **DeviceManager** service. | | callback | () =&gt; void | No | Callback used to return the dead event of the **DeviceManager** service. |
- Example **Example**
```js ```js
dmInstance.off("serviceDie", () => { dmInstance.off("serviceDie", () => {
console.info("serviceDie off"); console.info("serviceDie off");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册