Skip to main content

HTMLBluetoothElement.requestAndConnectDevice()

BFChainWebComponentHTMLBluetoothElementrequestAndConnectDeviceLess than 1 minute

Opens the bluetooth device; internally calls the BluetoothPlugin.requestAndConnectDevice() method

HTMLBluetoothElement.requestAndConnectDevice(options)

Parameters

Return Value

Returns a Promise that resolves to an object implementing the BluetoothRequestAndConnectDeviceResponse interface;

Example

<body>

  <dweb-bluetooth></dweb-bluetooth>

  <button>open</button>

  <script type="module">

    import "@plaoc/plugins"
    
    const bluetooth = document.querySelector("dweb-bluetooth")!
    
    const btn = document.querySelector('button');
    
    btn.addEventListener('click', async () => {
    
      bluetooth
      .open()
      .then(res => {
        if(res.success){
        
          const options = {
            acceptAllDevices: true,
            optionalServices: ["00003802-0000-1000-8000-00805f9b34fb"],
          }
          
          return bluetoothPlugin.requestAndConnectDevice(options)
        }
      })
      .then(res => {
        if(res.success){
        
          // Successfully queried and connected bluetooth device;
          
        }
      })
    })
    
  </script>

</body>

Platform Compatibility

Properties/Methods/EventsAndroidiOSDesktop-DevDesktop
requestAndConnectDeviceX

HTMLBluetoothElement

Comments
  • Latest
  • Oldest
  • Hottest
Powered by Waline v2.15.7