BluetoothEmulation 接口
¥BluetoothEmulation interface
启用蓝牙模拟功能。
¥Exposes the bluetooth emulation abilities.
签名
¥Signature
export interface BluetoothEmulation
备注
¥Remarks
Web 蓝牙规范 要求每个顶层可导航页面都应该隔离模拟的适配器。但是,目前 Chromium 的蓝牙模拟实现仅限于浏览器上下文,而非页面。这意味着从同一浏览器上下文的不同页面暴露的蓝牙模拟会干扰它们的状态。
¥Web Bluetooth specification requires the emulated adapters should be isolated per top-level navigable. However, at the moment Chromium's bluetooth emulation implementation is tight to the browser context, not the page. This means the bluetooth emulation exposed from different pages of the same browser context would interfere their states.
示例
¥Example
await page.bluetooth.emulateAdapter('powered-on');
await page.bluetooth.simulatePreconnectedPeripheral({
address: '09:09:09:09:09:09',
name: 'SOME_NAME',
manufacturerData: [
{
key: 17,
data: 'AP8BAX8=',
},
],
knownServiceUuids: ['12345678-1234-5678-9abc-def123456789'],
});
await page.bluetooth.disableEmulation();
方法
¥Methods
方法 | 描述 |
|---|---|
| disableEmulation() | (实验性)禁用模拟蓝牙适配器。参见 bluetooth.disableSimulation。 |
| emulateAdapter(state, leSupported) | (实验性)模拟蓝牙适配器。蓝牙模拟的必需项,请参阅 bluetooth.simulateAdapter。 |
| simulatePreconnectedPeripheral(preconnectedPeripheral) | (实验性)模拟预连接的蓝牙外设。参见 bluetooth.simulatePreconnectedPeripheral。 |