1import { hasComplete } from "./utils" 2 3export function mockBluetooth() { 4 global.systemplugin.bluetooth = { 5 startBLEScan: function (...args) { 6 console.warn("bluetooth.startBLEScan interface mocked in the Previewer. How this interface works on the" + 7 " Previewer may be different from that on a real device.") 8 args[0].success() 9 hasComplete(args[0].complete) 10 }, 11 stopBLEScan: function (...args) { 12 console.warn("bluetooth.stopBLEScan interface mocked in the Previewer. How this interface works on the" + 13 " Previewer may be different from that on a real device.") 14 args[0].success() 15 hasComplete(args[0].complete) 16 }, 17 subscribeBLEFound: function (...args) { 18 console.warn("bluetooth.subscribeBLEFound interface mocked in the Previewer. How this interface works on the" + 19 " Previewer may be different from that on a real device.") 20 const options = { 21 addrType: 'public', 22 addr: 'xx:xx:xx:xx', 23 rssi: 123, 24 txpower: 'xxx', 25 data: 'xxx' 26 } 27 const min = 1 28 const max = 6 29 clearInterval(this.unsubscribeBLE) 30 delete this.unsubscribeBLE 31 this.unsubscribeBLE = setInterval(() => { 32 const randomAddr = Math.floor(Math.random() * (max - min)) + min 33 const optionsArr = Array(randomAddr).fill(options) 34 args[0].success(optionsArr) 35 }, 1000) 36 }, 37 unsubscribeBLEFound: function () { 38 console.warn("bluetooth.unsubscribeBLEFound interface mocked in the Previewer. How this interface works on the" + 39 " Previewer may be different from that on a real device.") 40 clearInterval(this.unsubscribeBLE) 41 delete this.unsubscribeBLE 42 } 43 } 44 } 45