mirror of
https://github.com/openharmony/third_party_jsframework.git
synced 2026-08-26 21:11:18 -04:00
f61a1e266b
Signed-off-by: zhongjianfei <zhongjianfei@huawei.com> Change-Id: I8f85afce8872ae510c2819979d8930db8a3e3519
45 lines
1.8 KiB
JavaScript
45 lines
1.8 KiB
JavaScript
import { hasComplete } from "./utils"
|
|
|
|
export function mockBluetooth() {
|
|
global.systemplugin.bluetooth = {
|
|
startBLEScan: function (...args) {
|
|
console.warn("bluetooth.startBLEScan interface mocked in the Previewer. How this interface works on the" +
|
|
" Previewer may be different from that on a real device.")
|
|
args[0].success()
|
|
hasComplete(args[0].complete)
|
|
},
|
|
stopBLEScan: function (...args) {
|
|
console.warn("bluetooth.stopBLEScan interface mocked in the Previewer. How this interface works on the" +
|
|
" Previewer may be different from that on a real device.")
|
|
args[0].success()
|
|
hasComplete(args[0].complete)
|
|
},
|
|
subscribeBLEFound: function (...args) {
|
|
console.warn("bluetooth.subscribeBLEFound interface mocked in the Previewer. How this interface works on the" +
|
|
" Previewer may be different from that on a real device.")
|
|
const options = {
|
|
addrType: 'public',
|
|
addr: 'xx:xx:xx:xx',
|
|
rssi: 123,
|
|
txpower: 'xxx',
|
|
data: 'xxx'
|
|
}
|
|
const min = 1
|
|
const max = 6
|
|
clearInterval(this.unsubscribeBLE)
|
|
delete this.unsubscribeBLE
|
|
this.unsubscribeBLE = setInterval(() => {
|
|
const randomAddr = Math.floor(Math.random() * (max - min)) + min
|
|
const optionsArr = Array(randomAddr).fill(options)
|
|
args[0].success(optionsArr)
|
|
}, 1000)
|
|
},
|
|
unsubscribeBLEFound: function () {
|
|
console.warn("bluetooth.unsubscribeBLEFound interface mocked in the Previewer. How this interface works on the" +
|
|
" Previewer may be different from that on a real device.")
|
|
clearInterval(this.unsubscribeBLE)
|
|
delete this.unsubscribeBLE
|
|
}
|
|
}
|
|
}
|
|
|