@doubao-apps/ai 0.0.33 → 0.0.34
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.md +1 -32
- package/dist/733.js +7 -15
- package/dist/cli.js +1 -1
- package/dist/manifest.json +3 -11
- package/dist/skills/doubao-apps-dev/SKILL.md +103 -227
- package/dist/skills/doubao-apps-dev/references/examples/common-patterns.md +80 -66
- package/dist/skills/doubao-apps-dev/references/examples/component-basics.md +24 -3
- package/dist/skills/doubao-apps-dev/references/examples/component-recipes.md +71 -0
- package/dist/skills/doubao-apps-dev/references/examples/open-api-recipes.md +203 -0
- package/dist/skills/doubao-apps-dev/references/guides/component-development.md +66 -42
- package/dist/skills/doubao-apps-dev/references/guides/expired-widget.md +113 -0
- package/dist/skills/doubao-apps-dev/references/guides/mcp-ui.md +275 -0
- package/dist/skills/doubao-apps-dev/references/guides/performance-optimization.md +24 -7
- package/dist/skills/doubao-apps-dev/references/reference/components-quick-ref.md +18 -7
- package/dist/skills/doubao-apps-dev/references/reference/framework-api-quick-ref.md +125 -107
- package/dist/skills/doubao-apps-dev/references/reference/open-api/01-/345/237/272/347/241/200.md +136 -0
- package/dist/skills/doubao-apps-dev/references/reference/open-api/02-/347/263/273/347/273/237.md +257 -0
- package/dist/skills/doubao-apps-dev/references/reference/open-api/03-/345/256/232/344/275/215.md +326 -0
- package/dist/skills/doubao-apps-dev/references/reference/open-api/04-/345/255/230/345/202/250.md +284 -0
- package/dist/skills/doubao-apps-dev/references/reference/open-api/05-/350/267/257/347/224/261.md +162 -0
- package/dist/skills/doubao-apps-dev/references/reference/open-api/06-/344/272/244/344/272/222.md +290 -0
- package/dist/skills/doubao-apps-dev/references/reference/open-api/07-/350/276/223/345/205/245.md +63 -0
- package/dist/skills/doubao-apps-dev/references/reference/open-api/08-/347/275/221/347/273/234.md +124 -0
- package/dist/skills/doubao-apps-dev/references/reference/open-api/09-/345/252/222/344/275/223.md +192 -0
- package/dist/skills/doubao-apps-dev/references/reference/open-api/10-/344/270/232/345/212/241/350/203/275/345/212/233.md +431 -0
- package/dist/skills/doubao-apps-dev/references/reference/open-api/11-/347/231/273/345/275/225.md +110 -0
- package/dist/skills/doubao-apps-dev/references/reference/open-api/12-/346/224/257/344/273/230.md +224 -0
- package/dist/skills/doubao-apps-dev/references/reference/open-api/13-/346/225/260/346/215/256/345/210/206/346/236/220.md +43 -0
- package/dist/skills/doubao-apps-dev/references/reference/open-api/14-/350/223/235/347/211/231.md +598 -0
- package/dist/skills/doubao-apps-dev/references/reference/open-api/15-wi-fi.md +210 -0
- package/dist/skills/doubao-apps-dev/references/reference/open-api/16-/345/212/240/351/200/237/345/272/246/350/256/241.md +87 -0
- package/dist/skills/doubao-apps-dev/references/reference/open-api/17-ibeacon.md +97 -0
- package/dist/skills/doubao-apps-dev/references/reference/open-api/18-/347/275/227/347/233/230.md +78 -0
- package/dist/skills/doubao-apps-dev/references/reference/open-api/19-/350/256/276/345/244/207/346/226/271/345/220/221.md +86 -0
- package/dist/skills/doubao-apps-dev/references/reference/open-api/20-/351/231/200/350/236/272/344/273/252.md +87 -0
- package/dist/skills/doubao-apps-dev/references/reference/open-api/21-/350/256/276/345/244/207-/347/275/221/347/273/234.md +102 -0
- package/dist/skills/doubao-apps-dev/references/reference/open-api/22-/347/237/255/344/277/241.md +40 -0
- package/dist/skills/doubao-apps-dev/references/reference/open-api/23-/346/227/240/351/232/234/347/242/215.md +40 -0
- package/dist/skills/doubao-apps-dev/references/reference/open-api/24-/345/237/272/347/241/200/344/277/241/346/201/257.md +86 -0
- package/dist/skills/doubao-apps-dev/references/reference/open-api/25-/347/224/265/346/261/240.md +63 -0
- package/dist/skills/doubao-apps-dev/references/reference/open-api/26-/346/227/245/345/216/206.md +95 -0
- package/dist/skills/doubao-apps-dev/references/reference/open-api/27-/345/211/252/350/264/264/346/235/277.md +64 -0
- package/dist/skills/doubao-apps-dev/references/reference/open-api/28-/350/201/224/347/263/273/344/272/272.md +101 -0
- package/dist/skills/doubao-apps-dev/references/reference/open-api/29-/345/212/240/345/257/206.md +43 -0
- package/dist/skills/doubao-apps-dev/references/reference/open-api/30-/347/224/265/350/257/235.md +36 -0
- package/dist/skills/doubao-apps-dev/references/reference/open-api/31-/346/211/253/347/240/201.md +58 -0
- package/dist/skills/doubao-apps-dev/references/reference/open-api/32-/345/261/217/345/271/225.md +136 -0
- package/dist/skills/doubao-apps-dev/references/reference/open-api/33-/351/234/207/345/212/250.md +62 -0
- package/dist/skills/doubao-apps-dev/references/reference/open-api/34-/346/226/207/344/273/266/347/263/273/347/273/237.md +73 -0
- package/dist/skills/doubao-apps-dev/references/reference/open-api/README.md +34 -0
- package/dist/skills/doubao-apps-dev/references/reference/open-api.md +384 -2
- package/dist/skills/doubao-apps-dev/references/rules/dos-and-donts.md +44 -27
- package/dist/skills/h5-to-doubao/SKILL.md +8 -4
- package/dist/skills/weixin-to-doubao/SKILL.md +8 -4
- package/dist/skills/weixin-to-doubao/assets/migration-checklist-template.md +1 -1
- package/package.json +2 -3
- package/dist/contexts/doubao-apps-dev/AGENTS.md +0 -300
- package/dist/contexts/doubao-apps-dev/CLAUDE.md +0 -31
- package/dist/contexts/doubao-apps-dev/references/examples/common-patterns.md +0 -589
- package/dist/contexts/doubao-apps-dev/references/examples/component-basics.md +0 -526
- package/dist/contexts/doubao-apps-dev/references/guides/best-practices.md +0 -571
- package/dist/contexts/doubao-apps-dev/references/guides/component-development.md +0 -891
- package/dist/contexts/doubao-apps-dev/references/guides/performance-optimization.md +0 -402
- package/dist/contexts/doubao-apps-dev/references/guides/troubleshooting.md +0 -287
- package/dist/contexts/doubao-apps-dev/references/reference/components-quick-ref.md +0 -103
- package/dist/contexts/doubao-apps-dev/references/reference/framework-api-quick-ref.md +0 -550
- package/dist/contexts/doubao-apps-dev/references/reference/open-api/README.md +0 -8
- package/dist/contexts/doubao-apps-dev/references/reference/open-api.md +0 -11
- package/dist/contexts/doubao-apps-dev/references/rules/dos-and-donts.md +0 -467
package/dist/skills/doubao-apps-dev/references/reference/open-api/14-/350/223/235/347/211/231.md
ADDED
|
@@ -0,0 +1,598 @@
|
|
|
1
|
+
# Open API: 蓝牙
|
|
2
|
+
|
|
3
|
+
蓝牙和 BLE 能力;通常先打开适配器,再扫描、连接和读写。
|
|
4
|
+
|
|
5
|
+
[返回目录](./README.md) | [返回速查](../open-api.md)
|
|
6
|
+
|
|
7
|
+
## 速查
|
|
8
|
+
|
|
9
|
+
| API | 说明 |
|
|
10
|
+
| --- | --- |
|
|
11
|
+
| [openBluetoothAdapter](#openbluetoothadapter) | 打开蓝牙适配器。 |
|
|
12
|
+
| [startBluetoothDevicesDiscovery](#startbluetoothdevicesdiscovery) | 开始搜索附近的蓝牙设备。 |
|
|
13
|
+
| [stopBluetoothDevicesDiscovery](#stopbluetoothdevicesdiscovery) | 停止搜索附近的蓝牙设备。 |
|
|
14
|
+
| [getBluetoothAdapterState](#getbluetoothadapterstate) | 获取蓝牙适配器状态。 |
|
|
15
|
+
| [getBluetoothDevices](#getbluetoothdevices) | 获取当前蓝牙模块发现的设备列表。 |
|
|
16
|
+
| [getConnectedBluetoothDevices](#getconnectedbluetoothdevices) | 获取已连接的蓝牙设备列表。 |
|
|
17
|
+
| [makeBluetoothPair](#makebluetoothpair) | 发起蓝牙配对。 |
|
|
18
|
+
| [isBluetoothDevicePaired](#isbluetoothdevicepaired) | 查询蓝牙设备是否已经配对。 |
|
|
19
|
+
| [closeBluetoothAdapter](#closebluetoothadapter) | 关闭蓝牙适配器。 |
|
|
20
|
+
| [createBLEConnection](#createbleconnection) | 创建 BLE 连接。 |
|
|
21
|
+
| [closeBLEConnection](#closebleconnection) | 关闭 BLE 连接。 |
|
|
22
|
+
| [getBLEDeviceServices](#getbledeviceservices) | 获取 BLE 服务列表。 |
|
|
23
|
+
| [getBLEDeviceCharacteristics](#getbledevicecharacteristics) | 获取 BLE 特征值列表。 |
|
|
24
|
+
| [getBLEDeviceRSSI](#getbledevicerssi) | 获取 BLE 设备 RSSI。 |
|
|
25
|
+
| [getBLEMTU](#getblemtu) | 获取 BLE MTU。 |
|
|
26
|
+
| [notifyBLECharacteristicValueChange](#notifyblecharacteristicvaluechange) | 订阅 BLE 特征值变化。 |
|
|
27
|
+
| [readBLECharacteristicValue](#readblecharacteristicvalue) | 读取 BLE 特征值。 |
|
|
28
|
+
| [setBLEMTU](#setblemtu) | 设置 BLE MTU。 |
|
|
29
|
+
| [writeBLECharacteristicValue](#writeblecharacteristicvalue) | 写入 BLE 特征值。 |
|
|
30
|
+
|
|
31
|
+
## API 详情
|
|
32
|
+
|
|
33
|
+
<a id="openbluetoothadapter"></a>
|
|
34
|
+
### openBluetoothAdapter()
|
|
35
|
+
|
|
36
|
+
打开蓝牙适配器。
|
|
37
|
+
|
|
38
|
+
## 代码示例
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
import { openBluetoothAdapter } from '@doubao-apps/framework/api';
|
|
42
|
+
|
|
43
|
+
await openBluetoothAdapter({ mode: 'central' });
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## 入参
|
|
47
|
+
|
|
48
|
+
|参数名|类型|必填|说明|
|
|
49
|
+
|---|---|---|---|
|
|
50
|
+
|mode|`BluetoothAdapterMode`|否|蓝牙模式。|
|
|
51
|
+
|
|
52
|
+
**类型说明**
|
|
53
|
+
|
|
54
|
+
- `BluetoothAdapterMode`: `"central" | "peripheral"`
|
|
55
|
+
|
|
56
|
+
## 返回值
|
|
57
|
+
|
|
58
|
+
返回 `Promise<object>`。
|
|
59
|
+
|
|
60
|
+
<a id="startbluetoothdevicesdiscovery"></a>
|
|
61
|
+
### startBluetoothDevicesDiscovery()
|
|
62
|
+
|
|
63
|
+
开始搜索附近的蓝牙设备。
|
|
64
|
+
|
|
65
|
+
## 代码示例
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
import { openBluetoothAdapter, startBluetoothDevicesDiscovery } from '@doubao-apps/framework/api';
|
|
69
|
+
|
|
70
|
+
await openBluetoothAdapter();
|
|
71
|
+
await startBluetoothDevicesDiscovery({ allowDuplicatesKey: false });
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## 入参
|
|
75
|
+
|
|
76
|
+
|参数名|类型|必填|说明|
|
|
77
|
+
|---|---|---|---|
|
|
78
|
+
|allowDuplicatesKey|`boolean`|否|是否允许重复上报同一设备。|
|
|
79
|
+
|interval|`number`|否|上报设备的间隔,单位毫秒。|
|
|
80
|
+
|powerLevel|`BluetoothPowerLevel`|否|扫描功耗等级。|
|
|
81
|
+
|services|`string[]`|否|按主服务 UUID 过滤搜索范围。|
|
|
82
|
+
|
|
83
|
+
**类型说明**
|
|
84
|
+
|
|
85
|
+
- `BluetoothPowerLevel`: `"low" | "medium" | "high"`
|
|
86
|
+
|
|
87
|
+
## 返回值
|
|
88
|
+
|
|
89
|
+
返回 `Promise<object>`。
|
|
90
|
+
|
|
91
|
+
<a id="stopbluetoothdevicesdiscovery"></a>
|
|
92
|
+
### stopBluetoothDevicesDiscovery()
|
|
93
|
+
|
|
94
|
+
停止搜索附近的蓝牙设备。
|
|
95
|
+
|
|
96
|
+
## 代码示例
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
import { stopBluetoothDevicesDiscovery } from '@doubao-apps/framework/api';
|
|
100
|
+
|
|
101
|
+
await stopBluetoothDevicesDiscovery();
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## 入参
|
|
105
|
+
|
|
106
|
+
无入参。
|
|
107
|
+
|
|
108
|
+
## 返回值
|
|
109
|
+
|
|
110
|
+
返回 `Promise<object>`。
|
|
111
|
+
|
|
112
|
+
<a id="getbluetoothadapterstate"></a>
|
|
113
|
+
### getBluetoothAdapterState()
|
|
114
|
+
|
|
115
|
+
获取蓝牙适配器状态。
|
|
116
|
+
|
|
117
|
+
## 代码示例
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
import { getBluetoothAdapterState } from '@doubao-apps/framework/api';
|
|
121
|
+
|
|
122
|
+
const { available, discovering } = await getBluetoothAdapterState();
|
|
123
|
+
|
|
124
|
+
console.log(available, discovering);
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## 入参
|
|
128
|
+
|
|
129
|
+
无入参。
|
|
130
|
+
|
|
131
|
+
## 返回值
|
|
132
|
+
|
|
133
|
+
返回 `Promise<GetBluetoothAdapterStateResult>`。
|
|
134
|
+
|
|
135
|
+
|字段名|类型|说明|
|
|
136
|
+
|---|---|---|
|
|
137
|
+
|available|`boolean`|蓝牙适配器是否可用。|
|
|
138
|
+
|discovering|`boolean`|是否正在搜索蓝牙设备。|
|
|
139
|
+
|
|
140
|
+
<a id="getbluetoothdevices"></a>
|
|
141
|
+
### getBluetoothDevices()
|
|
142
|
+
|
|
143
|
+
获取当前蓝牙模块发现的设备列表。
|
|
144
|
+
|
|
145
|
+
## 代码示例
|
|
146
|
+
|
|
147
|
+
```typescript
|
|
148
|
+
import { getBluetoothDevices } from '@doubao-apps/framework/api';
|
|
149
|
+
|
|
150
|
+
const { devices } = await getBluetoothDevices();
|
|
151
|
+
|
|
152
|
+
console.log(devices.map((device) => device.name));
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## 入参
|
|
156
|
+
|
|
157
|
+
无入参。
|
|
158
|
+
|
|
159
|
+
## 返回值
|
|
160
|
+
|
|
161
|
+
返回 `Promise<GetBluetoothDevicesResult>`。
|
|
162
|
+
|
|
163
|
+
|字段名|类型|说明|
|
|
164
|
+
|---|---|---|
|
|
165
|
+
|devices|`BluetoothDevice[]`|当前蓝牙模块已发现的设备列表。|
|
|
166
|
+
|devices[].advertisingData|`ArrayBuffer`|广播二进制数据。|
|
|
167
|
+
|devices[].advertisingServiceUuids|`string[]`|广播中的服务 UUID 列表。|
|
|
168
|
+
|devices[].connectable|`boolean`|是否可连接。|
|
|
169
|
+
|devices[].deviceId|`string`|设备 ID。|
|
|
170
|
+
|devices[].localName|`string`|广播中的本地名称。|
|
|
171
|
+
|devices[].name|`string`|设备名称。|
|
|
172
|
+
|devices[].rssi|`number`|RSSI 信号强度,单位 dBm。|
|
|
173
|
+
|devices[].serviceData|`Record<string, unknown>`|广播中的服务数据。|
|
|
174
|
+
|
|
175
|
+
<a id="getconnectedbluetoothdevices"></a>
|
|
176
|
+
### getConnectedBluetoothDevices()
|
|
177
|
+
|
|
178
|
+
获取已连接的蓝牙设备列表。
|
|
179
|
+
|
|
180
|
+
## 代码示例
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
import { getConnectedBluetoothDevices } from '@doubao-apps/framework/api';
|
|
184
|
+
|
|
185
|
+
const { devices } = await getConnectedBluetoothDevices({
|
|
186
|
+
services: ['0000180D-0000-1000-8000-00805F9B34FB']
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
console.log(devices);
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## 入参
|
|
193
|
+
|
|
194
|
+
|参数名|类型|必填|说明|
|
|
195
|
+
|---|---|---|---|
|
|
196
|
+
|services|`string[]`|是|蓝牙主服务 UUID 列表。|
|
|
197
|
+
|
|
198
|
+
## 返回值
|
|
199
|
+
|
|
200
|
+
返回 `Promise<GetConnectedBluetoothDevicesResult>`。
|
|
201
|
+
|
|
202
|
+
|字段名|类型|说明|
|
|
203
|
+
|---|---|---|
|
|
204
|
+
|devices|`ConnectedBluetoothDevice[]`|已连接设备列表。|
|
|
205
|
+
|devices[].deviceId|`string`|设备 ID。|
|
|
206
|
+
|devices[].name|`string`|设备名称。|
|
|
207
|
+
|
|
208
|
+
<a id="makebluetoothpair"></a>
|
|
209
|
+
### makeBluetoothPair()
|
|
210
|
+
|
|
211
|
+
发起蓝牙配对。
|
|
212
|
+
|
|
213
|
+
## 代码示例
|
|
214
|
+
|
|
215
|
+
```typescript
|
|
216
|
+
import { makeBluetoothPair } from '@doubao-apps/framework/api';
|
|
217
|
+
|
|
218
|
+
await makeBluetoothPair({
|
|
219
|
+
deviceId: 'device-id',
|
|
220
|
+
pin: '000000',
|
|
221
|
+
timeout: 10000
|
|
222
|
+
});
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
## 入参
|
|
226
|
+
|
|
227
|
+
|参数名|类型|必填|说明|
|
|
228
|
+
|---|---|---|---|
|
|
229
|
+
|deviceId|`string`|是|蓝牙设备 ID。|
|
|
230
|
+
|pin|`string`|是|配对 PIN 码。|
|
|
231
|
+
|timeout|`number`|否|超时时间,单位毫秒。|
|
|
232
|
+
|
|
233
|
+
## 返回值
|
|
234
|
+
|
|
235
|
+
返回 `Promise<object>`。
|
|
236
|
+
|
|
237
|
+
<a id="isbluetoothdevicepaired"></a>
|
|
238
|
+
### isBluetoothDevicePaired()
|
|
239
|
+
|
|
240
|
+
查询蓝牙设备是否已经配对。
|
|
241
|
+
|
|
242
|
+
## 代码示例
|
|
243
|
+
|
|
244
|
+
```typescript
|
|
245
|
+
import { isBluetoothDevicePaired } from '@doubao-apps/framework/api';
|
|
246
|
+
|
|
247
|
+
await isBluetoothDevicePaired({ deviceId: 'device-id' });
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
## 入参
|
|
251
|
+
|
|
252
|
+
|参数名|类型|必填|说明|
|
|
253
|
+
|---|---|---|---|
|
|
254
|
+
|deviceId|`string`|是|蓝牙设备 ID。|
|
|
255
|
+
|
|
256
|
+
## 返回值
|
|
257
|
+
|
|
258
|
+
返回 `Promise<object>`。
|
|
259
|
+
|
|
260
|
+
<a id="closebluetoothadapter"></a>
|
|
261
|
+
### closeBluetoothAdapter()
|
|
262
|
+
|
|
263
|
+
关闭蓝牙适配器。
|
|
264
|
+
|
|
265
|
+
## 代码示例
|
|
266
|
+
|
|
267
|
+
```typescript
|
|
268
|
+
import { closeBluetoothAdapter } from '@doubao-apps/framework/api';
|
|
269
|
+
|
|
270
|
+
await closeBluetoothAdapter();
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
## 入参
|
|
274
|
+
|
|
275
|
+
无入参。
|
|
276
|
+
|
|
277
|
+
## 返回值
|
|
278
|
+
|
|
279
|
+
返回 `Promise<object>`。
|
|
280
|
+
|
|
281
|
+
<a id="createbleconnection"></a>
|
|
282
|
+
### createBLEConnection()
|
|
283
|
+
|
|
284
|
+
创建 BLE 连接。
|
|
285
|
+
|
|
286
|
+
## 代码示例
|
|
287
|
+
|
|
288
|
+
```typescript
|
|
289
|
+
import { createBLEConnection } from '@doubao-apps/framework/api';
|
|
290
|
+
|
|
291
|
+
await createBLEConnection({
|
|
292
|
+
deviceId: 'device-id',
|
|
293
|
+
timeout: 10000
|
|
294
|
+
});
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
## 入参
|
|
298
|
+
|
|
299
|
+
|参数名|类型|必填|说明|
|
|
300
|
+
|---|---|---|---|
|
|
301
|
+
|deviceId|`string`|是|蓝牙设备 ID。|
|
|
302
|
+
|timeout|`number`|否|超时时间,单位毫秒。|
|
|
303
|
+
|
|
304
|
+
## 返回值
|
|
305
|
+
|
|
306
|
+
返回 `Promise<object>`。
|
|
307
|
+
|
|
308
|
+
<a id="closebleconnection"></a>
|
|
309
|
+
### closeBLEConnection()
|
|
310
|
+
|
|
311
|
+
关闭 BLE 连接。
|
|
312
|
+
|
|
313
|
+
## 代码示例
|
|
314
|
+
|
|
315
|
+
```typescript
|
|
316
|
+
import { closeBLEConnection } from '@doubao-apps/framework/api';
|
|
317
|
+
|
|
318
|
+
await closeBLEConnection({ deviceId: 'device-id' });
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
## 入参
|
|
322
|
+
|
|
323
|
+
|参数名|类型|必填|说明|
|
|
324
|
+
|---|---|---|---|
|
|
325
|
+
|deviceId|`string`|是|蓝牙设备 ID。|
|
|
326
|
+
|
|
327
|
+
## 返回值
|
|
328
|
+
|
|
329
|
+
返回 `Promise<object>`。
|
|
330
|
+
|
|
331
|
+
<a id="getbledeviceservices"></a>
|
|
332
|
+
### getBLEDeviceServices()
|
|
333
|
+
|
|
334
|
+
获取 BLE 服务列表。
|
|
335
|
+
|
|
336
|
+
## 代码示例
|
|
337
|
+
|
|
338
|
+
```typescript
|
|
339
|
+
import { getBLEDeviceServices } from '@doubao-apps/framework/api';
|
|
340
|
+
|
|
341
|
+
const { services } = await getBLEDeviceServices({ deviceId: 'device-id' });
|
|
342
|
+
|
|
343
|
+
console.log(services);
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
## 入参
|
|
347
|
+
|
|
348
|
+
|参数名|类型|必填|说明|
|
|
349
|
+
|---|---|---|---|
|
|
350
|
+
|deviceId|`string`|是|蓝牙设备 ID。|
|
|
351
|
+
|
|
352
|
+
## 返回值
|
|
353
|
+
|
|
354
|
+
返回 `Promise<GetBLEDeviceServicesResult>`。
|
|
355
|
+
|
|
356
|
+
|字段名|类型|说明|
|
|
357
|
+
|---|---|---|
|
|
358
|
+
|services|`BluetoothService[]`|设备服务列表。|
|
|
359
|
+
|services[].isPrimary|`boolean`|是否为主服务。|
|
|
360
|
+
|services[].uuid|`string`|服务 UUID。|
|
|
361
|
+
|
|
362
|
+
<a id="getbledevicecharacteristics"></a>
|
|
363
|
+
### getBLEDeviceCharacteristics()
|
|
364
|
+
|
|
365
|
+
获取 BLE 特征值列表。
|
|
366
|
+
|
|
367
|
+
## 代码示例
|
|
368
|
+
|
|
369
|
+
```typescript
|
|
370
|
+
import { getBLEDeviceCharacteristics } from '@doubao-apps/framework/api';
|
|
371
|
+
|
|
372
|
+
const { characteristics } = await getBLEDeviceCharacteristics({
|
|
373
|
+
deviceId: 'device-id',
|
|
374
|
+
serviceId: 'service-id'
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
console.log(characteristics);
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
## 入参
|
|
381
|
+
|
|
382
|
+
|参数名|类型|必填|说明|
|
|
383
|
+
|---|---|---|---|
|
|
384
|
+
|deviceId|`string`|是|蓝牙设备 ID。|
|
|
385
|
+
|serviceId|`string`|是|服务 ID。|
|
|
386
|
+
|
|
387
|
+
## 返回值
|
|
388
|
+
|
|
389
|
+
返回 `Promise<GetBLEDeviceCharacteristicsResult>`。
|
|
390
|
+
|
|
391
|
+
|字段名|类型|说明|
|
|
392
|
+
|---|---|---|
|
|
393
|
+
|characteristics|`BluetoothCharacteristic[]`|特征值列表。|
|
|
394
|
+
|characteristics[].properties|`BluetoothCharacteristicProperties`|特征值能力。|
|
|
395
|
+
|characteristics[].properties.indicate|`boolean`|是否支持 indicate。|
|
|
396
|
+
|characteristics[].properties.notify|`boolean`|是否支持 notify。|
|
|
397
|
+
|characteristics[].properties.read|`boolean`|是否支持 read。|
|
|
398
|
+
|characteristics[].properties.write|`boolean`|是否支持 write。|
|
|
399
|
+
|characteristics[].properties.writeDefault|`boolean`|是否支持带响应写入。|
|
|
400
|
+
|characteristics[].properties.writeNoResponse|`boolean`|是否支持无响应写入。|
|
|
401
|
+
|characteristics[].uuid|`string`|特征值 UUID。|
|
|
402
|
+
|
|
403
|
+
<a id="getbledevicerssi"></a>
|
|
404
|
+
### getBLEDeviceRSSI()
|
|
405
|
+
|
|
406
|
+
获取 BLE 设备 RSSI。
|
|
407
|
+
|
|
408
|
+
## 代码示例
|
|
409
|
+
|
|
410
|
+
```typescript
|
|
411
|
+
import { getBLEDeviceRSSI } from '@doubao-apps/framework/api';
|
|
412
|
+
|
|
413
|
+
const { rssi } = await getBLEDeviceRSSI({ deviceId: 'device-id' });
|
|
414
|
+
|
|
415
|
+
console.log(rssi);
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
## 入参
|
|
419
|
+
|
|
420
|
+
|参数名|类型|必填|说明|
|
|
421
|
+
|---|---|---|---|
|
|
422
|
+
|deviceId|`string`|是|蓝牙设备 ID。|
|
|
423
|
+
|
|
424
|
+
## 返回值
|
|
425
|
+
|
|
426
|
+
返回 `Promise<GetBLEDeviceRSSIResult>`。
|
|
427
|
+
|
|
428
|
+
|字段名|类型|说明|
|
|
429
|
+
|---|---|---|
|
|
430
|
+
|rssi|`number`|RSSI 信号强度,单位 dBm。|
|
|
431
|
+
|
|
432
|
+
<a id="getblemtu"></a>
|
|
433
|
+
### getBLEMTU()
|
|
434
|
+
|
|
435
|
+
获取 BLE MTU。
|
|
436
|
+
|
|
437
|
+
## 代码示例
|
|
438
|
+
|
|
439
|
+
```typescript
|
|
440
|
+
import { getBLEMTU } from '@doubao-apps/framework/api';
|
|
441
|
+
|
|
442
|
+
const { mtu } = await getBLEMTU({ deviceId: 'device-id' });
|
|
443
|
+
|
|
444
|
+
console.log(mtu);
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
## 入参
|
|
448
|
+
|
|
449
|
+
|参数名|类型|必填|说明|
|
|
450
|
+
|---|---|---|---|
|
|
451
|
+
|deviceId|`string`|是|蓝牙设备 ID。|
|
|
452
|
+
|writeType|`BluetoothWriteType`|否|写入模式。|
|
|
453
|
+
|
|
454
|
+
**类型说明**
|
|
455
|
+
|
|
456
|
+
- `BluetoothWriteType`: `"write" | "writeNoResponse"`
|
|
457
|
+
|
|
458
|
+
## 返回值
|
|
459
|
+
|
|
460
|
+
返回 `Promise<GetBLEMTUResult>`。
|
|
461
|
+
|
|
462
|
+
|字段名|类型|说明|
|
|
463
|
+
|---|---|---|
|
|
464
|
+
|mtu|`number`|当前 MTU。|
|
|
465
|
+
|
|
466
|
+
<a id="notifyblecharacteristicvaluechange"></a>
|
|
467
|
+
### notifyBLECharacteristicValueChange()
|
|
468
|
+
|
|
469
|
+
订阅 BLE 特征值变化。
|
|
470
|
+
|
|
471
|
+
## 代码示例
|
|
472
|
+
|
|
473
|
+
```typescript
|
|
474
|
+
import { notifyBLECharacteristicValueChange } from '@doubao-apps/framework/api';
|
|
475
|
+
|
|
476
|
+
await notifyBLECharacteristicValueChange({
|
|
477
|
+
deviceId: 'device-id',
|
|
478
|
+
serviceId: 'service-id',
|
|
479
|
+
characteristicId: 'characteristic-id',
|
|
480
|
+
state: true
|
|
481
|
+
});
|
|
482
|
+
```
|
|
483
|
+
|
|
484
|
+
## 入参
|
|
485
|
+
|
|
486
|
+
|参数名|类型|必填|说明|
|
|
487
|
+
|---|---|---|---|
|
|
488
|
+
|characteristicId|`string`|是|特征值 ID。|
|
|
489
|
+
|deviceId|`string`|是|蓝牙设备 ID。|
|
|
490
|
+
|serviceId|`string`|是|服务 ID。|
|
|
491
|
+
|state|`boolean`|是|是否启用订阅。|
|
|
492
|
+
|type|`BluetoothNotifyType`|否|订阅类型。|
|
|
493
|
+
|
|
494
|
+
**类型说明**
|
|
495
|
+
|
|
496
|
+
- `BluetoothNotifyType`: `"notification" | "indication"`
|
|
497
|
+
|
|
498
|
+
## 返回值
|
|
499
|
+
|
|
500
|
+
返回 `Promise<object>`。
|
|
501
|
+
|
|
502
|
+
<a id="readblecharacteristicvalue"></a>
|
|
503
|
+
### readBLECharacteristicValue()
|
|
504
|
+
|
|
505
|
+
读取 BLE 特征值。
|
|
506
|
+
|
|
507
|
+
## 代码示例
|
|
508
|
+
|
|
509
|
+
```typescript
|
|
510
|
+
import { readBLECharacteristicValue } from '@doubao-apps/framework/api';
|
|
511
|
+
|
|
512
|
+
await readBLECharacteristicValue({
|
|
513
|
+
deviceId: 'device-id',
|
|
514
|
+
serviceId: 'service-id',
|
|
515
|
+
characteristicId: 'characteristic-id'
|
|
516
|
+
});
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
## 入参
|
|
520
|
+
|
|
521
|
+
|参数名|类型|必填|说明|
|
|
522
|
+
|---|---|---|---|
|
|
523
|
+
|characteristicId|`string`|是|特征值 ID。|
|
|
524
|
+
|deviceId|`string`|是|蓝牙设备 ID。|
|
|
525
|
+
|serviceId|`string`|是|服务 ID。|
|
|
526
|
+
|
|
527
|
+
## 返回值
|
|
528
|
+
|
|
529
|
+
返回 `Promise<object>`。
|
|
530
|
+
|
|
531
|
+
<a id="setblemtu"></a>
|
|
532
|
+
### setBLEMTU()
|
|
533
|
+
|
|
534
|
+
设置 BLE MTU。
|
|
535
|
+
|
|
536
|
+
## 代码示例
|
|
537
|
+
|
|
538
|
+
```typescript
|
|
539
|
+
import { setBLEMTU } from '@doubao-apps/framework/api';
|
|
540
|
+
|
|
541
|
+
const { mtu } = await setBLEMTU({
|
|
542
|
+
deviceId: 'device-id',
|
|
543
|
+
mtu: 512
|
|
544
|
+
});
|
|
545
|
+
|
|
546
|
+
console.log(mtu);
|
|
547
|
+
```
|
|
548
|
+
|
|
549
|
+
## 入参
|
|
550
|
+
|
|
551
|
+
|参数名|类型|必填|说明|
|
|
552
|
+
|---|---|---|---|
|
|
553
|
+
|deviceId|`string`|是|蓝牙设备 ID。|
|
|
554
|
+
|mtu|`number`|是|目标 MTU。|
|
|
555
|
+
|
|
556
|
+
## 返回值
|
|
557
|
+
|
|
558
|
+
返回 `Promise<SetBLEMTUResult>`。
|
|
559
|
+
|
|
560
|
+
|字段名|类型|说明|
|
|
561
|
+
|---|---|---|
|
|
562
|
+
|mtu|`string \| number`|最终协商得到的 MTU。|
|
|
563
|
+
|
|
564
|
+
<a id="writeblecharacteristicvalue"></a>
|
|
565
|
+
### writeBLECharacteristicValue()
|
|
566
|
+
|
|
567
|
+
写入 BLE 特征值。
|
|
568
|
+
|
|
569
|
+
## 代码示例
|
|
570
|
+
|
|
571
|
+
```typescript
|
|
572
|
+
import { writeBLECharacteristicValue } from '@doubao-apps/framework/api';
|
|
573
|
+
|
|
574
|
+
await writeBLECharacteristicValue({
|
|
575
|
+
deviceId: 'device-id',
|
|
576
|
+
serviceId: 'service-id',
|
|
577
|
+
characteristicId: 'characteristic-id',
|
|
578
|
+
value: new Uint8Array([1, 2, 3]).buffer
|
|
579
|
+
});
|
|
580
|
+
```
|
|
581
|
+
|
|
582
|
+
## 入参
|
|
583
|
+
|
|
584
|
+
|参数名|类型|必填|说明|
|
|
585
|
+
|---|---|---|---|
|
|
586
|
+
|characteristicId|`string`|是|特征值 ID。|
|
|
587
|
+
|deviceId|`string`|是|蓝牙设备 ID。|
|
|
588
|
+
|serviceId|`string`|是|服务 ID。|
|
|
589
|
+
|value|`ArrayBuffer`|是|要写入的二进制数据。|
|
|
590
|
+
|writeType|`BluetoothWriteType`|否|写入模式。|
|
|
591
|
+
|
|
592
|
+
**类型说明**
|
|
593
|
+
|
|
594
|
+
- `BluetoothWriteType`: `"write" | "writeNoResponse"`
|
|
595
|
+
|
|
596
|
+
## 返回值
|
|
597
|
+
|
|
598
|
+
返回 `Promise<object>`。
|