Skip to content

Commit

Permalink
Web Bluetooth API shim for noble. (noble#238)
Browse files Browse the repository at this point in the history
* can connect from web, no services discovery

* cleanup

* cleanup

* reorganize stub data

* next tick and emit errors

* working notifications

* list service IDs

* working characteristics discover

* cleanup read

* replace console.log with debug

* add semicolon

* cleanup

* use dataview buffer, emit errors

* emit a bindings error if web bluettooth not available

* duplicate all uuids to optionalServices

* return full list of seri

* search by name or prefix

* remove console.log

* fix param juggling

* can connect from web, no services discovery

* cleanup

* cleanup

* reorganize stub data

* working notifications

* list service IDs

* working characteristics discover

* no write response

* revert to not using test abstraction

* Fix startScanning callback calling

According to README, when startScanning is passed a callback as a third argument, that callback is a usual Node-style "error first" callback.
But in fact, when scanning is started successfully, callback is called with `filterDuplicates` value as its first argument.
Here is an example situation where it causes problem:
```
// don't allow duplicates (as by default) but pass a callback
noble.startScanning([], false, function(error) {
  if(error) {
    console.log('Failed to start scanning:', error);
  }
});
```
What happens when you run this code:
`Failed to start scanning: true`

This PR is intended to fix this.

* allow for unsubscribing

* linting fixes

* Update central.js

Remove inaccurate comment

* can connect from web, no services discovery

* can connect from web, no services discovery

* cleanup

* cleanup

* cleanup

* cleanup

* reorganize stub data

* reorganize stub data

* next tick and emit errors

* working notifications

* working notifications

* list service IDs

* list service IDs

* working characteristics discover

* working characteristics discover

* cleanup read

* replace console.log with debug

* add semicolon

* cleanup

* use dataview buffer, emit errors

* emit a bindings error if web bluettooth not available

* duplicate all uuids to optionalServices

* return full list of seri

* search by name or prefix

* remove console.log

* fix param juggling

* no write response

* revert to not using test abstraction

* allow for unsubscribing

* linting fixes

* fix linting
  • Loading branch information
monteslu authored and Loghorn committed Apr 15, 2017
1 parent 0ae7f36 commit 98424c7
Show file tree
Hide file tree
Showing 5 changed files with 416 additions and 4 deletions.
10 changes: 10 additions & 0 deletions .jshintrc
@@ -0,0 +1,10 @@
{
"browser": true,
"node": true,
"mocha": true,
"unused": false, //enable after cleanup
"undef": false, //enable after cleanup
"globals": {
"Promise": true
}
}
9 changes: 9 additions & 0 deletions lib/resolve-bindings-web.js
@@ -0,0 +1,9 @@
function resolveBindings(){
if (navigator.bluetooth && !process.env.NOBLE_WEBSOCKET) {
return require('./webbluetooth/bindings');
}

return require('./websocket/bindings');
}

module.exports = resolveBindings;
2 changes: 1 addition & 1 deletion lib/resolve-bindings.js
Expand Up @@ -3,7 +3,7 @@ var os = require('os');
module.exports = function() {
var platform = os.platform();

if (process.env.NOBLE_WEBSOCKET || process.title === 'browser') {
if (process.env.NOBLE_WEBSOCKET) {
return require('./websocket/bindings');
} else if (process.env.NOBLE_DISTRIBUTED) {
return require('./distributed/bindings');
Expand Down

0 comments on commit 98424c7

Please sign in to comment.