1/* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16/** 17 * @file 18 * @kit ConnectivityKit 19 */ 20 21/** 22 * @typedef StartBLEScanOptions 23 * @syscap SystemCapability.Communication.Bluetooth.Lite 24 * @since 6 25 */ 26export interface StartBLEScanOptions { 27 /** 28 * Time of delay for reporting the scan result 29 * 30 * @syscap SystemCapability.Communication.Bluetooth.Lite 31 * @since 6 32 */ 33 interval: number; 34 /** 35 * StartBLEScanOptions success 36 * 37 * @syscap SystemCapability.Communication.Bluetooth.Lite 38 * @since 6 39 */ 40 success: () => void; 41 /** 42 * StartBLEScanOptions failed 43 * 44 * @syscap SystemCapability.Communication.Bluetooth.Lite 45 * @since 6 46 */ 47 fail: (data: string, code: number) => void; 48 /** 49 * StartBLEScanOptions completed 50 * 51 * @syscap SystemCapability.Communication.Bluetooth.Lite 52 * @since 6 53 */ 54 complete: () => void; 55} 56 57/** 58 * @typedef StopBLEScanOptions 59 * @syscap SystemCapability.Communication.Bluetooth.Lite 60 * @since 6 61 */ 62export interface StopBLEScanOptions { 63 /** 64 * StopBLEScanOptions success 65 * 66 * @syscap SystemCapability.Communication.Bluetooth.Lite 67 * @since 6 68 */ 69 success: () => void; 70 /** 71 * StopBLEScanOptions failed 72 * 73 * @syscap SystemCapability.Communication.Bluetooth.Lite 74 * @since 6 75 */ 76 fail: (data: string, code: number) => void; 77 /** 78 * StopBLEScanOptions completed 79 * 80 * @syscap SystemCapability.Communication.Bluetooth.Lite 81 * @since 6 82 */ 83 complete: () => void; 84} 85 86/** 87 * @typedef BluetoothDevice 88 * @syscap SystemCapability.Communication.Bluetooth.Lite 89 * @since 6 90 */ 91export interface BluetoothDevice { 92 /** 93 * The addrType of address, may be public or random 94 * 95 * @syscap SystemCapability.Communication.Bluetooth.Lite 96 * @since 6 97 */ 98 addrType: 'public' | 'random'; 99 /** 100 * Address of BluetoothDevice 101 * 102 * @syscap SystemCapability.Communication.Bluetooth.Lite 103 * @since 6 104 */ 105 addr: string; 106 /** 107 * RSSI of the remote device 108 * 109 * @syscap SystemCapability.Communication.Bluetooth.Lite 110 * @since 6 111 */ 112 rssi: number; 113 /** 114 * Transmission power level for advertising 115 * 116 * @syscap SystemCapability.Communication.Bluetooth.Lite 117 * @since 6 118 */ 119 txpower: string; 120 /** 121 * The data of BluetoothDevice 122 * 123 * @syscap SystemCapability.Communication.Bluetooth.Lite 124 * @since 6 125 */ 126 data: string; 127} 128 129/** 130 * @typedef BLEFoundResponse 131 * @syscap SystemCapability.Communication.Bluetooth.Lite 132 * @since 6 133 */ 134export interface BLEFoundResponse { 135 /** 136 * The devices of BLEFoundResponse 137 * 138 * @syscap SystemCapability.Communication.Bluetooth.Lite 139 * @since 6 140 */ 141 devices: Array<BluetoothDevice>; 142} 143 144/** 145 * @typedef SubscribeBLEFoundOptions 146 * @syscap SystemCapability.Communication.Bluetooth.Lite 147 * @since 6 148 */ 149export interface SubscribeBLEFoundOptions { 150 /** 151 * SubscribeBLEFoundOptions success 152 * 153 * @syscap SystemCapability.Communication.Bluetooth.Lite 154 * @since 6 155 */ 156 success: (data: BLEFoundResponse) => void; 157 /** 158 * SubscribeBLEFoundOptions failed 159 * 160 * @syscap SystemCapability.Communication.Bluetooth.Lite 161 * @since 6 162 */ 163 fail: (data: string, code: number) => void; 164} 165 166/** 167 * Provides methods to manage BLE scan. 168 * 169 * @syscap SystemCapability.Communication.Bluetooth.Lite 170 * @since 6 171 */ 172export default class Bluetooth { 173 /** 174 * Start BLE scan 175 * 176 * @param { StartBLEScanOptions } options - Options 177 * @syscap SystemCapability.Communication.Bluetooth.Lite 178 * @since 6 179 */ 180 static startBLEScan(options: StartBLEScanOptions): void; 181 182 /** 183 * Stop BLE scan 184 * 185 * @param { StopBLEScanOptions } options - Options 186 * @syscap SystemCapability.Communication.Bluetooth.Lite 187 * @since 6 188 */ 189 static stopBLEScan(options: StopBLEScanOptions): void; 190 191 /** 192 * Subscribe BLE found 193 * 194 * @param { SubscribeBLEFoundOptions } options - Options 195 * @syscap SystemCapability.Communication.Bluetooth.Lite 196 * @since 6 197 */ 198 static subscribeBLEFound(options: SubscribeBLEFoundOptions): void; 199 200 /** 201 * Stop the subscription of BLE found 202 * 203 * @syscap SystemCapability.Communication.Bluetooth.Lite 204 * @since 6 205 */ 206 static unsubscribeBLEFound(): void; 207}