@bud-fe/h5-native-bridge 1.0.4

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.
@@ -0,0 +1,172 @@
1
+ export interface PluginContext {
2
+ bridge: NativeBridgeCore;
3
+ }
4
+ export interface BridgePlugin {
5
+ name: string;
6
+ version: string;
7
+ install: (context: PluginContext) => void;
8
+ }
9
+ export interface BridgeOptions {
10
+ debug?: boolean;
11
+ timeout?: number;
12
+ plugins?: BridgePlugin[];
13
+ errorHandler?: (error: Error, source: string) => void;
14
+ }
15
+ export interface NativeResponse<T = any> {
16
+ code: number;
17
+ message: string;
18
+ data?: T;
19
+ }
20
+ export interface CallbacksBase<T = any> {
21
+ success?: (data: T) => void;
22
+ fail?: (error: Error) => void;
23
+ complete?: () => void;
24
+ }
25
+ export interface CallNativeOptions {
26
+ action: string;
27
+ params?: Record<string, any>;
28
+ timeout?: number;
29
+ retryCount?: number;
30
+ retryDelay?: number;
31
+ }
32
+ export interface PluginMethods {
33
+ }
34
+ type NativeEventHandler = (event: {
35
+ type: string;
36
+ data: any;
37
+ }) => void;
38
+ /**
39
+ * NativeBridge核心类
40
+ * 提供基础的通信能力和插件系统
41
+ */
42
+ export declare class NativeBridgeCore {
43
+ private static instance;
44
+ private callbackMap;
45
+ private callbackId;
46
+ private isReady;
47
+ private readyCallbacks;
48
+ private debugMode;
49
+ private defaultTimeout;
50
+ private plugins;
51
+ private pendingCalls;
52
+ private errorHandler?;
53
+ private eventListeners;
54
+ private nativeEventHandlers;
55
+ readonly VERSION = "1.0.0";
56
+ readonly API_VERSION = "1";
57
+ /**
58
+ * 私有构造函数(单例模式)
59
+ */
60
+ private constructor();
61
+ /**
62
+ * 获取NativeBridge单例
63
+ */
64
+ static getInstance(options?: BridgeOptions): NativeBridgeCore;
65
+ /**
66
+ * 注册原生事件监听
67
+ */
68
+ onNativeEvent(eventType: string, handler: NativeEventHandler): void;
69
+ /**
70
+ * 取消原生事件监听
71
+ */
72
+ offNativeEvent(eventType: string, handler: NativeEventHandler): void;
73
+ /**
74
+ * 供原生调用,分发事件
75
+ */
76
+ dispatchNativeEvent(eventType: string, data: any): void;
77
+ private methodRegistry;
78
+ registerMethod<T extends keyof PluginMethods>(name: T, method: PluginMethods[T]): void;
79
+ /**
80
+ * 安装插件
81
+ */
82
+ use(plugin: BridgePlugin): NativeBridgeCore;
83
+ /**
84
+ * 检查插件是否已安装
85
+ */
86
+ hasPlugin(name: string): boolean;
87
+ /**
88
+ * 获取已安装的插件
89
+ */
90
+ getPlugin(name: string): BridgePlugin | undefined;
91
+ /**
92
+ * 设置桥接环境
93
+ */
94
+ private setupBridge;
95
+ destroy(): void;
96
+ /**
97
+ * 检测是否在App环境中
98
+ */
99
+ private checkIsInApp;
100
+ /**
101
+ * 等待桥接准备就绪
102
+ */
103
+ ready(callback: () => void): void;
104
+ /**
105
+ * 调用原生方法
106
+ */
107
+ callNative<T = any>(options: CallNativeOptions, callbacks?: CallbacksBase<T>): string;
108
+ /**
109
+ * 同步调用原生方法
110
+ *
111
+ * 该方法通过不同的桥接方式(iOS WKWebView、Android WebView或iframe)与原生应用通信,
112
+ * 发送指定的操作指令和参数,并返回处理结果
113
+ *
114
+ * @param action - 要执行的原生操作名称
115
+ * @param params - 传递给原生方法的参数对象
116
+ * @returns 处理后的原生返回数据
117
+ * @throws 当发送消息到原生App失败时抛出错误
118
+ */
119
+ callNativeSync(action: string, params: any, callbacks: CallbacksBase): any;
120
+ /**
121
+ * 发送消息到原生
122
+ */
123
+ private sendToNative;
124
+ /**
125
+ * 处理原生回调
126
+ */
127
+ handleNativeCallback(callbackId: string, type: "success" | "fail", data: any): void;
128
+ /**
129
+ * 模拟原生调用(仅用于开发测试)
130
+ */
131
+ private mockNativeCall;
132
+ /**
133
+ * 释放回调
134
+ */
135
+ releaseCallback(callbackId: string): void;
136
+ /**
137
+ * 设置调试模式
138
+ */
139
+ setDebug(debug: boolean): void;
140
+ /**
141
+ * 设置全局错误处理器
142
+ */
143
+ setErrorHandler(handler: (error: Error, source: string) => void): void;
144
+ /**
145
+ * 获取已安装插件列表
146
+ */
147
+ getInstalledPlugins(): string[];
148
+ /**
149
+ * 获取当前调试模式状态
150
+ * @returns 是否开启调试模式
151
+ */
152
+ isDebugMode(): boolean;
153
+ /**
154
+ * 日志记录 - 信息
155
+ */
156
+ log(message: string, ...args: any[]): void;
157
+ /**
158
+ * 日志记录 - 警告
159
+ */
160
+ warn(message: string, ...args: any[]): void;
161
+ /**
162
+ * 日志记录 - 错误
163
+ */
164
+ error(source: string, error: Error): void;
165
+ /**
166
+ * 获取回调映射表
167
+ */
168
+ getCallBackMap(): Map<string, CallbacksBase<any>>;
169
+ }
170
+ export declare const createNativeBridge: (options?: BridgeOptions) => NativeBridgeCore;
171
+ declare const _default: NativeBridgeCore;
172
+ export default _default;
@@ -0,0 +1,19 @@
1
+ export { NativeBridgeCore, createNativeBridge } from './core';
2
+ export { default as locationPlugin } from './plugins/location';
3
+ export { default as devicePlugin } from './plugins/device';
4
+ export { default as mediaPlugin } from './plugins/media';
5
+ export { default as navigatePlugin } from './plugins/navigate';
6
+ export { default as userinfoPlugin } from './plugins/userInfo';
7
+ export { default as toastPlugin } from './plugins/toast';
8
+ export { default as bluetoothPlugin } from './plugins/bluetooth';
9
+ export { default as storagePlugin } from './plugins/storage';
10
+ export { default as authenticationPlugin } from './plugins/authentication';
11
+ export { default as requestPlugin } from './plugins/request';
12
+ export { default as wifiPlugin } from './plugins/wifi';
13
+ export type { BridgePlugin, BridgeOptions, PluginContext, CallbacksBase, NativeResponse, CallNativeOptions, PluginMethods, } from './core';
14
+ export type { LocationInfo, GetLocationOptions, } from './plugins/location';
15
+ export type { DeviceInfo, DeviceInfoOptions, GetWifiOptions, WifiListAsyncResult, } from './plugins/device';
16
+ export type { MediaInfo, MediaInfoOptions, } from './plugins/media';
17
+ export type { NavigateInfo } from './plugins/navigate';
18
+ declare const nativeBridge: import('./core').NativeBridgeCore;
19
+ export default nativeBridge;
@@ -0,0 +1,30 @@
1
+ import { BridgePlugin, PluginContext, CallbacksBase } from '../core';
2
+
3
+ export interface AuthenticationResult {
4
+ photoStatus: number;
5
+ }
6
+ declare module "../core" {
7
+ interface PluginMethods {
8
+ exclusiveLiveCheck: (options?: CallbacksBase) => Promise<AuthenticationResult>;
9
+ }
10
+ interface NativeBridgeCore extends PluginMethods {
11
+ }
12
+ }
13
+ declare class AuthenticationPlugin implements BridgePlugin {
14
+ private context?;
15
+ readonly name = "authentication";
16
+ readonly version = "1.0.0";
17
+ install(context: PluginContext): void;
18
+ /**
19
+ * 执行实人认证
20
+ * @param options - 认证选项,包含成功、失败和完成的回调函数
21
+ * @property options.success - 认证成功时的回调函数,接收认证结果
22
+ * @property options.fail - 认证失败时的回调函数,接收错误信息
23
+ * @property options.complete - 认证完成时的回调函数(无论成功或失败)
24
+ * @returns Promise<AuthenticationResult> - 返回认证结果的Promise对象
25
+ * @throws {BridgeError} - 如果插件未正确初始化,抛出BridgeError异常
26
+ */
27
+ exclusiveLiveCheck(options?: CallbacksBase): Promise<AuthenticationResult>;
28
+ }
29
+ declare const _default: AuthenticationPlugin;
30
+ export default _default;
@@ -0,0 +1,399 @@
1
+ import { BridgePlugin, PluginContext, CallbacksBase } from '../core';
2
+
3
+ export interface OpenBluetoothOptions extends CallbacksBase {
4
+ /**不传的话默认是true,表示是否在离开当前页面时自动断开蓝牙(仅对android有效)。 */
5
+ autoClose?: boolean;
6
+ }
7
+ export interface CloseBluetoothOptions extends CallbacksBase {
8
+ }
9
+ export interface OpenBluetoothResponse {
10
+ /** 是否支持BLE蓝牙 */
11
+ isSupportBLE?: number;
12
+ }
13
+ export interface StartBluetoothDevicesDiscoveryOptions extends CallbacksBase {
14
+ allowDuplicatesKey?: boolean;
15
+ interval?: number;
16
+ services?: string[];
17
+ }
18
+ export interface BLEDeviceOptions extends CallbacksBase {
19
+ deviceId: string;
20
+ }
21
+ export interface GetBLEDeviceOptions extends CallbacksBase {
22
+ success?: (data: BLEDeviceResponse) => void;
23
+ /**
24
+ * Android 上为设备 MAC 地址。
25
+ iOS 上为设备 UUID。
26
+ */
27
+ deviceId: string;
28
+ serviceId: string;
29
+ }
30
+ export interface BLEDeviceResponse {
31
+ /** 设备特征值列表 */
32
+ characteristics: Characteristic[];
33
+ }
34
+ export interface Characteristic {
35
+ characteristicId: string;
36
+ serviceId: string;
37
+ value: string;
38
+ properties: Properties;
39
+ }
40
+ export interface Properties {
41
+ read: boolean;
42
+ write: boolean;
43
+ notify: boolean;
44
+ indicate: boolean;
45
+ }
46
+ export interface BLEDeviceServicesOptions extends CallbacksBase {
47
+ success?: (data: BLEDeviceServicesResponse) => void;
48
+ deviceId: string;
49
+ }
50
+ export interface BLEDeviceServicesResponse {
51
+ services: Services[];
52
+ }
53
+ export interface Services {
54
+ serviceId: string;
55
+ isPrimary: string;
56
+ }
57
+ export interface WriteBLECharacteristicValueOptions extends CallbacksBase {
58
+ deviceId: string;
59
+ serviceId: string;
60
+ characteristicId: string;
61
+ value: string;
62
+ }
63
+ export interface ReadBLECharacteristicValueOptions extends CallbacksBase {
64
+ success?: (data: ReadBLECharacteristicValueResponse) => void;
65
+ deviceId: string;
66
+ serviceId: string;
67
+ characteristicId: string;
68
+ }
69
+ export interface ReadBLECharacteristicValueResponse {
70
+ /** 设备特征值列表 */
71
+ characteristicId?: string;
72
+ serviceId?: string;
73
+ value?: string;
74
+ }
75
+ declare module "../core" {
76
+ interface PluginMethods {
77
+ openBluetoothAdapter: (options?: OpenBluetoothOptions) => void;
78
+ closeBluetoothAdapter: (options?: CloseBluetoothOptions) => void;
79
+ startBluetoothDevicesDiscovery: (options?: StartBluetoothDevicesDiscoveryOptions) => void;
80
+ stopBluetoothDevicesDiscovery: (options?: CallbacksBase) => void;
81
+ onBluetoothDeviceFound: (callback: (devices: any[]) => void) => void;
82
+ offBluetoothDeviceFound: () => void;
83
+ connectBLEDevice: (options: BLEDeviceOptions) => void;
84
+ disconnectBLEDevice: (options: BLEDeviceOptions) => void;
85
+ getBLEDeviceCharacteristics: (options: GetBLEDeviceOptions) => void;
86
+ getBLEDeviceServices: (options: BLEDeviceServicesOptions) => void;
87
+ writeBLECharacteristicValue: (options: WriteBLECharacteristicValueOptions) => void;
88
+ readBLECharacteristicValue: (options: ReadBLECharacteristicValueOptions) => void;
89
+ onBLECharacteristicValueChange: (callback: (data: {
90
+ serviceId: string;
91
+ characteristicId: string;
92
+ deviceId: string;
93
+ value: string;
94
+ }) => void) => void;
95
+ offBLECharacteristicValueChange: () => void;
96
+ onBLEConnectionStateChanged: (callback: (data: {
97
+ deviceId: string;
98
+ connected: boolean;
99
+ }) => void) => void;
100
+ offBLEConnectionStateChanged: () => void;
101
+ }
102
+ interface NativeBridgeCore extends PluginMethods {
103
+ }
104
+ }
105
+ declare class BluetoothPlugin implements BridgePlugin {
106
+ readonly name = "bluetooth";
107
+ readonly version = "1.0.0";
108
+ private context?;
109
+ install(context: PluginContext): void;
110
+ /**
111
+ * 取消监听蓝牙低功耗连接状态变化事件
112
+ *
113
+ * @description 该方法用于移除之前注册的蓝牙低功耗连接状态变化监听器。
114
+ * 当不再需要监听连接状态变化时,应调用此方法以避免内存泄漏。
115
+ *
116
+ * @param callback - 可选的回调函数,当成功取消监听后会被调用
117
+ * @returns void
118
+ *
119
+ * @throws {BridgeError} 当插件未正确初始化时抛出错误
120
+ *
121
+ * @example
122
+ */
123
+ offBLEConnectionStateChanged(callback?: () => void): void;
124
+ /**
125
+ * 监听BLE设备连接状态变化
126
+ *
127
+ * @description 注册一个回调函数来监听蓝牙低功耗(BLE)设备的连接状态变化事件。
128
+ * 当设备连接或断开时,会触发相应的回调函数。
129
+ *
130
+ * @param callback - 连接状态变化时的回调函数
131
+ * @param callback.data - 回调函数的参数对象
132
+ * @param callback.data.deviceId - 设备ID,用于标识具体的BLE设备
133
+ * @param callback.data.connected - 连接状态,true表示已连接,false表示已断开
134
+ *
135
+ * @throws {BridgeError} 当插件未正确初始化时抛出错误
136
+ *
137
+ * @example
138
+ *
139
+ * @since 1.0.0
140
+ */
141
+ onBLEConnectionStateChanged(callback: (data: {
142
+ deviceId: string;
143
+ connected: boolean;
144
+ }) => void): void;
145
+ /**
146
+ * 取消监听低功耗蓝牙设备的特征值变化事件
147
+ *
148
+ * @description 此方法用于移除之前通过onBLECharacteristicValueChange注册的事件监听器。
149
+ * 当不再需要监听BLE特征值变化时,应调用此方法以避免内存泄漏和不必要的回调执行。
150
+ *
151
+ * @param {Function} [callback] - 可选的回调函数,在成功取消监听后执行
152
+ * @returns {void} 无返回值
153
+ *
154
+ * @throws {BridgeError} 当插件未正确初始化时抛出错误
155
+ *
156
+ * @example
157
+ */
158
+ offBLECharacteristicValueChange(callback?: () => void): void;
159
+ /**
160
+ * 监听 BLE 特征值变化事件
161
+ *
162
+ * 当蓝牙低功耗设备的特征值发生变化时,会触发此回调函数。
163
+ * 在调用此方法前,需要确保插件已正确初始化。
164
+ *
165
+ * @param callback - 特征值变化时的回调函数
166
+ * @param callback.data - 特征值变化的数据对象
167
+ * @param callback.data.serviceId - 服务 ID,标识 BLE 服务
168
+ * @param callback.data.characteristicId - 特征 ID,标识 BLE 特征
169
+ * @param callback.data.deviceId - 设备 ID,标识 BLE 设备
170
+ * @param callback.data.value - 特征值,变化后的特征值内容
171
+ *
172
+ * @throws {BridgeError} 当插件未正确初始化时抛出错误
173
+ *
174
+ * @example
175
+ */
176
+ onBLECharacteristicValueChange(callback: (data: {
177
+ serviceId: string;
178
+ characteristicId: string;
179
+ deviceId: string;
180
+ value: string;
181
+ }) => void): void;
182
+ /**
183
+ * 读取低功耗蓝牙设备特征值
184
+ *
185
+ * @description 从指定的蓝牙设备特征值中读取数据。该方法需要在插件正确初始化后才能使用。
186
+ *
187
+ * @param {ReadBLECharacteristicValueOptions} options - 读取BLE特征值的配置选项
188
+ * @param {string} options.deviceId - 蓝牙设备ID
189
+ * @param {string} options.serviceId - 蓝牙服务ID
190
+ * @param {string} options.characteristicId - 蓝牙特征值ID
191
+ * @param {function} [options.success] - 成功回调函数,参数为读取到的特征值数据
192
+ * @param {function} [options.fail] - 失败回调函数
193
+ * @param {function} [options.complete] - 完成回调函数(无论成功或失败都会执行)
194
+ *
195
+ * @throws {BridgeError} 当插件未正确初始化时抛出错误
196
+ *
197
+ * @returns {void} 无返回值
198
+ *
199
+ * @example
200
+ */
201
+ readBLECharacteristicValue(options: ReadBLECharacteristicValueOptions): void;
202
+ /**
203
+ * 向低功耗蓝牙设备特征值中写入数据
204
+ *
205
+ * @param options - 写入BLE特征值的配置选项
206
+ * @param options.deviceId - 蓝牙设备 id
207
+ * @param options.serviceId - 蓝牙特征值对应服务的 uuid
208
+ * @param options.characteristicId - 蓝牙特征值的 uuid
209
+ * @param options.value - 蓝牙设备特征值对应的二进制值
210
+ * @param options.success - 接口调用成功的回调函数
211
+ * @param options.fail - 接口调用失败的回调函数
212
+ * @param options.complete - 接口调用结束的回调函数(调用成功、失败都会执行)
213
+ *
214
+ * @throws {BridgeError} 当插件未正确初始化时抛出错误
215
+ *
216
+ * @example
217
+ */
218
+ writeBLECharacteristicValue(options: WriteBLECharacteristicValueOptions): void;
219
+ /**
220
+ * 获取蓝牙低功耗设备的所有服务
221
+ *
222
+ * @description 该方法用于获取已连接的BLE设备的所有可用服务列表。
223
+ * 调用前需要确保设备已经成功连接,否则可能获取失败。
224
+ *
225
+ * @param {BLEDeviceServicesOptions} options - 获取BLE设备服务的配置选项
226
+ * @param {string} options.deviceId - 蓝牙设备标识符,用于指定要获取服务的设备
227
+ * @param {function} [options.success] - 成功回调函数,参数为BLEDeviceServicesResponse类型
228
+ * @param {function} [options.fail] - 失败回调函数,参数为错误信息
229
+ * @param {function} [options.complete] - 完成回调函数,无论成功失败都会调用
230
+ *
231
+ * @throws {BridgeError} 当插件未正确初始化时抛出PLUGIN_NOT_INITIALIZED错误
232
+ *
233
+ * @returns {void} 无返回值,结果通过回调函数返回
234
+ *
235
+ * @example
236
+ */
237
+ getBLEDeviceServices(options: BLEDeviceServicesOptions): void;
238
+ /**
239
+ * 连接蓝牙低功耗设备
240
+ *
241
+ * @description 此方法用于连接指定的蓝牙低功耗(BLE)设备。在调用前需要确保插件已正确初始化,
242
+ * 否则会抛出插件未初始化的错误。连接过程是异步的,通过回调函数返回结果。
243
+ *
244
+ * @param {BLEDeviceOptions} options - 连接BLE设备的配置选项
245
+ * @param {Function} [options.success] - 连接成功时的回调函数
246
+ * @param {Function} [options.fail] - 连接失败时的回调函数
247
+ * @param {Function} [options.complete] - 连接完成时的回调函数(无论成功或失败都会执行)
248
+ *
249
+ * @throws {BridgeError} 当插件未正确初始化时抛出 PLUGIN_NOT_INITIALIZED 错误
250
+ *
251
+ * @returns {void} 无返回值
252
+ *
253
+ * @example
254
+ */
255
+ connectBLEDevice(options: BLEDeviceOptions): void;
256
+ /**
257
+ * 断开蓝牙低功耗设备连接
258
+ *
259
+ * @description 断开与指定蓝牙低功耗设备的连接。此方法会调用原生平台的蓝牙断连功能。
260
+ *
261
+ * @param {BLEDeviceOptions} options - 断开连接的配置选项
262
+ * @param {Function} [options.success] - 成功回调函数
263
+ * @param {Function} [options.fail] - 失败回调函数
264
+ * @param {Function} [options.complete] - 完成回调函数(无论成功或失败都会执行)
265
+ *
266
+ * @throws {BridgeError} 当插件未正确初始化时抛出错误
267
+ *
268
+ * @returns {void}
269
+ *
270
+ * @example
271
+ */
272
+ disconnectBLEDevice(options: BLEDeviceOptions): void;
273
+ /**
274
+ * 获取蓝牙低功耗设备的特征值列表
275
+ *
276
+ * @description 用于获取指定蓝牙低功耗设备的所有特征值信息,包括特征值的UUID、属性等。
277
+ * 该方法需要在蓝牙设备连接成功后调用。
278
+ *
279
+ * @param {GetBLEDeviceOptions} options - 获取设备特征值的配置选项
280
+ * @param {string} options.deviceId - 蓝牙设备ID
281
+ * @param {string} options.serviceId - 蓝牙服务UUID
282
+ * @param {function} [options.success] - 成功回调函数,返回特征值列表数据
283
+ * @param {function} [options.fail] - 失败回调函数
284
+ * @param {function} [options.complete] - 完成回调函数(无论成功或失败都会执行)
285
+ *
286
+ * @throws {BridgeError} 当插件未正确初始化时抛出错误
287
+ *
288
+ * @example
289
+ *
290
+ * @since 1.0.0
291
+ */
292
+ getBLEDeviceCharacteristics(options: GetBLEDeviceOptions): void;
293
+ /**
294
+ * 取消监听蓝牙设备发现事件
295
+ *
296
+ * @description 移除对蓝牙设备发现事件的监听,当不再需要接收蓝牙设备发现通知时调用此方法
297
+ *
298
+ * @param callback - 可选的回调函数,在成功取消监听后执行
299
+ *
300
+ * @throws {BridgeError} 当插件未正确初始化时抛出错误
301
+ *
302
+ * @example
303
+ *
304
+ * @returns {void} 无返回值
305
+ */
306
+ offBluetoothDeviceFound(callback?: () => void): void;
307
+ /**
308
+ * 监听蓝牙设备发现事件
309
+ *
310
+ * 当发现新的蓝牙设备时,会触发回调函数并传入设备列表。
311
+ * 该方法需要在插件正确初始化后调用,否则会抛出异常。
312
+ *
313
+ * @param callback - 设备发现回调函数
314
+ * @param callback.devices - 发现的蓝牙设备列表
315
+ * @throws {BridgeError} 当插件未正确初始化时抛出 PLUGIN_NOT_INITIALIZED 错误
316
+ *
317
+ * @example
318
+ */
319
+ onBluetoothDeviceFound(callback: (devices: any[]) => void): void;
320
+ /**
321
+ * 停止搜索蓝牙设备
322
+ *
323
+ * @description 停止搜索附近的蓝牙外围设备。若已经找到需要连接的蓝牙设备并不需要继续搜索时,建议调用该接口停止蓝牙搜索。
324
+ *
325
+ * @param options - 可选的回调函数配置对象
326
+ * @param options.success - 接口调用成功的回调函数
327
+ * @param options.fail - 接口调用失败的回调函数
328
+ * @param options.complete - 接口调用结束的回调函数(调用成功、失败都会执行)
329
+ *
330
+ * @throws {BridgeError} 当插件未正确初始化时抛出异常
331
+ *
332
+ * @example
333
+ */
334
+ stopBluetoothDevicesDiscovery(options?: CallbacksBase): void;
335
+ /**
336
+ * 开启蓝牙适配器
337
+ *
338
+ * @description 开启本机蓝牙适配器模块,允许设备进行蓝牙操作。调用该方法前需要确保插件已正确初始化。
339
+ *
340
+ * @param {OpenBluetoothOptions} [options={}] - 开启蓝牙适配器的配置选项
341
+ * @param {Function} [options.success] - 接口调用成功的回调函数
342
+ * @param {Function} [options.fail] - 接口调用失败的回调函数
343
+ * @param {Function} [options.complete] - 接口调用结束的回调函数(调用成功、失败都会执行)
344
+ *
345
+ * @throws {BridgeError} 当插件未正确初始化时抛出错误
346
+ *
347
+ * @returns {void}
348
+ *
349
+ * @example
350
+ */
351
+ startBluetoothDevicesDiscovery(options?: StartBluetoothDevicesDiscoveryOptions): void;
352
+ /**
353
+ * 关闭蓝牙适配器
354
+ *
355
+ * @description 关闭本机蓝牙适配器模块,断开所有已建立的连接。调用该方法将会断开所有蓝牙连接,
356
+ * 释放系统资源。建议在不需要使用蓝牙功能时及时调用此方法。
357
+ *
358
+ * @param {CloseBluetoothOptions} [options={}] - 关闭蓝牙适配器的配置选项
359
+ * @param {Function} [options.success] - 接口调用成功的回调函数
360
+ * @param {Function} [options.fail] - 接口调用失败的回调函数
361
+ * @param {Function} [options.complete] - 接口调用结束的回调函数(调用成功、失败都会执行)
362
+ *
363
+ * @throws {BridgeError} 当插件未正确初始化时抛出错误
364
+ *
365
+ * @returns {void}
366
+ *
367
+ * @example
368
+ */
369
+ closeBluetoothAdapter(options?: CloseBluetoothOptions): void;
370
+ /**
371
+ * 开启蓝牙功能
372
+ *
373
+ * 此方法用于启用设备的蓝牙功能。调用前需要确保插件已正确初始化,
374
+ * 否则会抛出相应的错误。方法会通过桥接器调用原生蓝牙开启功能。
375
+ *
376
+ * @param options - 开启蓝牙的配置选项
377
+ * @param options.success - 成功回调函数,当蓝牙成功开启时调用
378
+ * @param options.fail - 失败回调函数,当蓝牙开启失败时调用
379
+ * @param options.complete - 完成回调函数,无论成功或失败都会调用
380
+ *
381
+ * @throws {BridgeError} 当插件未正确初始化时抛出 PLUGIN_NOT_INITIALIZED 错误
382
+ *
383
+ * @returns {void} 无返回值
384
+ *
385
+ * @example
386
+ */
387
+ openBluetoothAdapter(options?: OpenBluetoothOptions): void;
388
+ /**
389
+ * 搜索到新蓝牙时触发
390
+ * 当发现新的蓝牙设备时,会触发回调函数并传入设备列表。
391
+ * 该方法需要在插件正确初始化后调用,否则会抛出异常。
392
+ * @param callback - 新蓝牙搜索到时触发的回调函数
393
+ * @param callback.devices - 发现的蓝牙设备列表
394
+ * @throws {BridgeError} 当插件未正确初始化时抛出 PLUGIN_NOT_INITIALIZED 错误
395
+ */
396
+ getBluetoothDevices(callback: (devices: any[]) => void): void;
397
+ }
398
+ export declare const bluetooth: BluetoothPlugin;
399
+ export default bluetooth;