Skip to content
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

deepak1556
Copy link
Member

@deepak1556
Copy link
Member Author

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',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

zcbenz added a commit that referenced this pull request Jun 1, 2016
@deepak1556
Copy link
Member Author

Have made the changes, thanks!

@zcbenz
Copy link
Contributor

zcbenz commented Jun 1, 2016

👍

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

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
Copy link
Member Author

@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
Copy link

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
Copy link
Member Author

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
Copy link

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
Copy link
Member Author

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
Copy link

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
Copy link
Member Author

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

@zcbenz
Copy link
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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants