New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webContents: add event to select bluetooth device #5781

Merged
merged 5 commits into from Jun 1, 2016

Conversation

Projects
None yet
3 participants
@deepak1556
Member

deepak1556 commented May 31, 2016

Fixes #5565

Depends on
electron-archive/brightray#225

@deepak1556

This comment has been minimized.

Member

deepak1556 commented Jun 1, 2016

Should this be made an event of app instead ?

@@ -167,6 +167,8 @@
'atom/browser/atom_security_state_model_client.h',
'atom/browser/atom_speech_recognition_manager_delegate.cc',
'atom/browser/atom_speech_recognition_manager_delegate.h',
'atom/browser/bluetooth_chooser.cc',
'atom/browser/bluetooth_chooser.h',

This comment has been minimized.

@zcbenz

zcbenz Jun 1, 2016

Contributor

I prefer to move this to atom/browser/lib since its major purpose is to provide JavaScript API.

* `deviceId` String
Emitted when bluetooth device needs to be selected on call to
`navigator.bluetooth.requestDevice`. If `event.preventDefault` is not called,

This comment has been minimized.

@zcbenz

zcbenz Jun 1, 2016

Contributor

We should mention that WebBluetooth should be enabled before using navigator.bluetooth.

Also it should be documented how to cancel the request.

zcbenz added a commit that referenced this pull request Jun 1, 2016

@deepak1556

This comment has been minimized.

Member

deepak1556 commented Jun 1, 2016

Have made the changes, thanks!

@zcbenz

This comment has been minimized.

Contributor

zcbenz commented Jun 1, 2016

👍

@zcbenz zcbenz merged commit 8f49d43 into electron:master Jun 1, 2016

1 of 2 checks passed

continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
@barchard

This comment has been minimized.

barchard commented Jun 2, 2016

hi, is this available in the release version of 1.2.1? I am trying to test this but I am not seeing my callback run:

  win.webContents.on('select-bluetooth-device', (event, deviceList, callback) => {
  console.log('testing');
    event.preventDefault()
    let result = deviceList.find((device) => {
      return device.deviceName === 'test'
    })
    if (!result) {
      callback('')
    } else {
      callback(result.deviceId)
    }
  })
{ http_parser: '2.7.0',
  node: '6.1.0',
  v8: '5.1.281.47',
  uv: '1.9.0',
  zlib: '1.2.8',
  ares: '1.10.1-DEV',
  modules: '48',
  openssl: '1.0.2h',
  electron: '1.2.1',
  'atom-shell': '1.2.1',
  chrome: '51.0.2704.63' }
@deepak1556

This comment has been minimized.

Member

deepak1556 commented Jun 2, 2016

@barchard the callback wont fire if the device list is empty, it will cancel internally after some retries. Whats the output of the app with --enable-logging , are you able to discover devices and connect with chrome on the host ?

@barchard

This comment has been minimized.

barchard commented Jun 2, 2016

@deepak1556 I am trying to discover all devices around me. Not trying (yet) to pair or connect with one. Log is below.

Thanks
Greg

[19224:0602/113048:INFO:CONSOLE(19)] "Requesting Bluetooth Device...", source: file:///path/to/index.html (19)
[19224:0602/113048:ERROR:bluetooth_classic_device_mac.mm(108)] Not implemented reached in virtual uint16_t device::BluetoothClassicDeviceMac::GetAppearance() const
[19224:0602/113048:ERROR:bluetooth_classic_device_mac.mm(108)] Not implemented reached in virtual uint16_t device::BluetoothClassicDeviceMac::GetAppearance() const
[19224:0602/113049:ERROR:bluetooth_classic_device_mac.mm(108)] Not implemented reached in virtual uint16_t device::BluetoothClassicDeviceMac::GetAppearance() const
...<cut>....
[19334:0602/113434:ERROR:bluetooth_low_energy_device_mac.mm(115)] Not implemented reached in virtual uint16_t device::BluetoothLowEnergyDeviceMac::GetAppearance() const
....<cut>...
[19334:0602/113443:INFO:CONSOLE(28)] "Argh! NotFoundError: User cancelled the requestDevice() chooser.", source: file:///path/to/index.html (28)
@deepak1556

This comment has been minimized.

Member

deepak1556 commented Jun 2, 2016

the log states the request to be cancelled, does chrome show up a list of available devices ? i was able to list and connect to a device on linux. Thanks!

@barchard

This comment has been minimized.

barchard commented Jun 2, 2016

@deepak1556 Chrome gives me a little pop up but doesn't show me any devices. What device IDs are you filtering on? I am using:

var filters = [{
    services: [0x1800, 0x1801]
  }];
@deepak1556

This comment has been minimized.

Member

deepak1556 commented Jun 2, 2016

Chrome gives me a little pop up but doesn't show me any devices

Yup if there arent any devices then the event wont fire.

I tested with the following code

<html>
    <head>
    </head>
    <body>
    <button onclick="run();" class="scanDevices">Scan</button>
    <script>
    function run() {
        var filters = [{
    services: [0x1800]
  }];
          console.log('Requesting Bluetooth Device...');
  navigator.bluetooth.requestDevice({filters: filters})
  .then(device => {
    console.log('> Name:             ' + device.name);
    console.log('> Id:               ' + device.id);
    console.log('> UUIDs:            ' + device.uuids.join('\n' + ' '.repeat(20)));
    console.log('> Connected:        ' + device.gatt.connected);
  })
  .catch(error => {
    console.log('Argh! ' + error);
  });
  }
    </script>
    </body>
</html>
@barchard

This comment has been minimized.

barchard commented Jun 2, 2016

@deepak1556 yea, i'm not getting any devices listed on OS X 10.11.5 (15F34). This seems highly unlikely that there aren't any devices around me that respond to the generic access profile?!

@deepak1556

This comment has been minimized.

Member

deepak1556 commented Jun 2, 2016

I am not sure. I suggest reporting to the chromium issues tracker since you don't see the expected output on chrome. Thanks!

@zcbenz

This comment has been minimized.

Contributor

zcbenz commented Jun 3, 2016

@barchard It is probably Chromium has problems recognizing the device on your machine, I can successfully list the devices using web bluetooth API on my machine (OS X 10.11.5).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment