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 * @type { number } 31 * @syscap SystemCapability.Communication.Bluetooth.Lite 32 * @since 6 33 */ 34 interval: number; 35 /** 36 * StartBLEScanOptions success 37 * 38 * @type { function } 39 * @syscap SystemCapability.Communication.Bluetooth.Lite 40 * @since 6 41 */ 42 success: () => void; 43 /** 44 * StartBLEScanOptions failed 45 * 46 * @type { function } 47 * @syscap SystemCapability.Communication.Bluetooth.Lite 48 * @since 6 49 */ 50 fail: (data: string, code: number) => void; 51 /** 52 * StartBLEScanOptions completed 53 * 54 * @type { function } 55 * @syscap SystemCapability.Communication.Bluetooth.Lite 56 * @since 6 57 */ 58 complete: () => void; 59} 60 61/** 62 * @typedef StopBLEScanOptions 63 * @syscap SystemCapability.Communication.Bluetooth.Lite 64 * @since 6 65 */ 66export interface StopBLEScanOptions { 67 /** 68 * StopBLEScanOptions success 69 * 70 * @type { function } 71 * @syscap SystemCapability.Communication.Bluetooth.Lite 72 * @since 6 73 */ 74 success: () => void; 75 /** 76 * StopBLEScanOptions failed 77 * 78 * @type { function } 79 * @syscap SystemCapability.Communication.Bluetooth.Lite 80 * @since 6 81 */ 82 fail: (data: string, code: number) => void; 83 /** 84 * StopBLEScanOptions completed 85 * 86 * @type { function } 87 * @syscap SystemCapability.Communication.Bluetooth.Lite 88 * @since 6 89 */ 90 complete: () => void; 91} 92 93/** 94 * @typedef BluetoothDevice 95 * @syscap SystemCapability.Communication.Bluetooth.Lite 96 * @since 6 97 */ 98export interface BluetoothDevice { 99 /** 100 * The addrType of address, may be public or random 101 * 102 * @type { 'public' | 'random' } 103 * @syscap SystemCapability.Communication.Bluetooth.Lite 104 * @since 6 105 */ 106 addrType: 'public' | 'random'; 107 /** 108 * Address of BluetoothDevice 109 * 110 * @type { string } 111 * @syscap SystemCapability.Communication.Bluetooth.Lite 112 * @since 6 113 */ 114 addr: string; 115 /** 116 * RSSI of the remote device 117 * 118 * @type { number } 119 * @syscap SystemCapability.Communication.Bluetooth.Lite 120 * @since 6 121 */ 122 rssi: number; 123 /** 124 * Transmission power level for advertising 125 * 126 * @type { string } 127 * @syscap SystemCapability.Communication.Bluetooth.Lite 128 * @since 6 129 */ 130 txpower: string; 131 /** 132 * The data of BluetoothDevice 133 * 134 * @type { string } 135 * @syscap SystemCapability.Communication.Bluetooth.Lite 136 * @since 6 137 */ 138 data: string; 139} 140 141/** 142 * @typedef BLEFoundResponse 143 * @syscap SystemCapability.Communication.Bluetooth.Lite 144 * @since 6 145 */ 146export interface BLEFoundResponse { 147 /** 148 * The devices of BLEFoundResponse 149 * 150 * @type { Array<BluetoothDevice> } 151 * @syscap SystemCapability.Communication.Bluetooth.Lite 152 * @since 6 153 */ 154 devices: Array<BluetoothDevice>; 155} 156 157/** 158 * @typedef SubscribeBLEFoundOptions 159 * @syscap SystemCapability.Communication.Bluetooth.Lite 160 * @since 6 161 */ 162export interface SubscribeBLEFoundOptions { 163 /** 164 * SubscribeBLEFoundOptions success 165 * 166 * @type { function } 167 * @syscap SystemCapability.Communication.Bluetooth.Lite 168 * @since 6 169 */ 170 success: (data: BLEFoundResponse) => void; 171 /** 172 * SubscribeBLEFoundOptions failed 173 * 174 * @type { function } 175 * @syscap SystemCapability.Communication.Bluetooth.Lite 176 * @since 6 177 */ 178 fail: (data: string, code: number) => void; 179} 180 181/** 182 * Provides methods to manage BLE scan. 183 * 184 * @syscap SystemCapability.Communication.Bluetooth.Lite 185 * @since 6 186 */ 187export default class Bluetooth { 188 /** 189 * Start BLE scan 190 * 191 * @param { StartBLEScanOptions } options - Options 192 * @syscap SystemCapability.Communication.Bluetooth.Lite 193 * @since 6 194 */ 195 static startBLEScan(options: StartBLEScanOptions): void; 196 197 /** 198 * Stop BLE scan 199 * 200 * @param { StopBLEScanOptions } options - Options 201 * @syscap SystemCapability.Communication.Bluetooth.Lite 202 * @since 6 203 */ 204 static stopBLEScan(options: StopBLEScanOptions): void; 205 206 /** 207 * Subscribe BLE found 208 * 209 * @param { SubscribeBLEFoundOptions } options - Options 210 * @syscap SystemCapability.Communication.Bluetooth.Lite 211 * @since 6 212 */ 213 static subscribeBLEFound(options: SubscribeBLEFoundOptions): void; 214 215 /** 216 * Stop the subscription of BLE found 217 * 218 * @syscap SystemCapability.Communication.Bluetooth.Lite 219 * @since 6 220 */ 221 static unsubscribeBLEFound(): void; 222}