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

Refactor #1

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
263dfa4
connect to bleno echo service example
don Jun 8, 2018
c4cd18a
Merge pull request #802 from don/echo-example
don Jun 8, 2018
6a930df
remove js mac bindings
geovie Oct 23, 2018
35b5d54
add native mac bindings
geovie Oct 23, 2018
a0366fb
add native winrt binding
geovie Oct 23, 2018
8cdd45b
extract and improve win32 bindings
geovie Oct 24, 2018
036f7ae
fix winrt advertisment duplicates
geovie Oct 24, 2018
e4bdccd
add node-pre-gyp
geovie Oct 24, 2018
307ecc9
add yarn.lock
geovie Oct 24, 2018
09db1f7
add appveyor
geovie Oct 24, 2018
6c943dd
version 1.9.9
geovie Oct 24, 2018
62fef1c
reduce build matrix
geovie Oct 25, 2018
cdc497c
fix url
geovie Oct 25, 2018
64cf938
use prebuild instead of node-pre-gyp
geovie Oct 26, 2018
a95245b
fix crash if bluetooth is turned off
geovie Oct 28, 2018
51c0c98
version 2.0.0
geovie Nov 5, 2018
718cf81
fix double connect, add log event
geovie Nov 6, 2018
a4f0f1f
version 2.0.1
geovie Nov 6, 2018
f9b24cf
only use the native winrt if a ble capable adapter is present
geovie Nov 7, 2018
4e2e0ca
increase min windows version to 10.0.17134 for now
geovie Nov 7, 2018
7183a8e
add travis for mac prebuilds
geovie Nov 8, 2018
a451aeb
version 2.0.2
geovie Nov 8, 2018
d70e13e
update ble-adapter dependency
geovie Nov 13, 2018
af05059
mac log errors, build from source on ci
geovie Nov 26, 2018
8401ebc
version 2.0.3
geovie Nov 26, 2018
4031409
add more mac log errors
geovie Nov 26, 2018
ab30ac3
version 2.0.4
geovie Nov 27, 2018
3f6bc55
update ble-adapter dependency
geovie Nov 29, 2018
48c9d55
fix bluetooth on/off detection
geovie Nov 30, 2018
ccf41ec
remove ble adapter detection
geovie Dec 3, 2018
d090d7b
fix ble on/off edge case
geovie Dec 6, 2018
afc24fa
integrate latest noble-mac changes:
geovie Mar 12, 2019
245ad03
adapt to latest Windows SDK:
geovie Mar 12, 2019
a722b7f
version 2.0.7
geovie Mar 12, 2019
0766df7
build for future electron
geovie Jun 18, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ results
build/
node_modules/
npm-debug.log

native/
51 changes: 20 additions & 31 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,23 @@
os:
- linux
- osx
language: cpp
env:
- NODE_VERSION="0.8"
- NODE_VERSION="0.10"
- NODE_VERSION="0.12"
- NODE_VERSION="4"
- NODE_VERSION="6"
- NODE_VERSION="8"
language: node_js

matrix:
fast_finish: true
before_install:
- git clone https://github.com/creationix/nvm.git /tmp/.nvm;
- source /tmp/.nvm/nvm.sh;
- nvm install $NODE_VERSION;
- nvm use --delete-prefix $NODE_VERSION;
- if [ $TRAVIS_OS_NAME == "linux" ]; then
export CC="g++-4.8";
fi
- if [ $NODE_VERSION == "0.8" ]; then
npm install -g npm@2;
fi
include:
- node_js: '8'
os: osx


install:
- npm install
- yarn install --frozen-lockfile
- yarn build:source
- yarn ci

script:
- npm test
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.8
- PUBLISH_BINARY=false
# if we are building a tag then publish
- if [[ $TRAVIS_BRANCH == `git describe --tags --always HEAD` ]]; then PUBLISH_BINARY=true; fi;
- >
if [ "$PUBLISH_BINARY" == true ]; then
yarn global add prebuild
prebuild -t 6.14.4 -t 8.12.0 -r node --upload $prebuild_upload
prebuild -t 2.0.0 -t 3.0.0 -t 4.0.4 -t 5.0.0 -r electron --upload $prebuild_upload
fi
33 changes: 33 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# vs 2017 image because Windows SDK 10.0.15063.0 is not available on vs 2015 image
image: Previous Visual Studio 2017

platform:
- x86
- x64

install:
- ps: Update-NodeJsInstallation (Get-NodeJsLatestBuild "8.12.0") $env:platform;
- ps: |
npm install -g node-gyp 2>&1 | out-null
if ($LASTEXITCODE -NE 0) { throw "Failed installing node-gyp"; }
- ps: node -v
- ps: npm -v
- ps: node-gyp -v
- cmd: yarn install --frozen-lockfile
- cmd: yarn build:source
- cmd: yarn ci
- ps: $publish_binary = 0
- ps: if ($env:appveyor_repo_tag -match "true") { $publish_binary=1; }
- ps: echo "tag $env:appveyor_repo_tag_name branch $env:APPVEYOR_REPO_BRANCH"
build_script:
- ps: echo "publish $publish_binary"
- ps: $arch = $env:platform
- ps: if ($arch -match "x86") { $arch="ia32"; }
- ps: |
if ($publish_binary -Eq "1") {
yarn global add prebuild 2>&1 | write-host
prebuild -t 6.14.4 -t 8.12.0 -r node --upload $env:prebuild_upload 2>&1 | write-host
prebuild -t 2.0.0 -t 3.0.0 -t 4.0.4 -t 5.0.0 -r electron --upload $env:prebuild_upload 2>&1 | write-host
}
echo "done."

57 changes: 57 additions & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
'targets': [
{
'target_name': 'noble',
'include_dirs': ["<!@(node -p \"require('node-addon-api').include\")", "<!@(node -p \"require('napi-thread-safe-callback').include\")"],
'dependencies': ["<!(node -p \"require('node-addon-api').gyp\")"],
'cflags!': [ '-fno-exceptions' ],
'cflags_cc!': [ '-fno-exceptions' ],
'conditions': [
['OS=="mac"', {
'sources': [
'lib/mac/src/noble_mac.mm',
'lib/mac/src/napi_objc.mm',
'lib/mac/src/ble_manager.mm',
'lib/mac/src/objc_cpp.mm',
'lib/mac/src/callbacks.cc'
],
'xcode_settings': {
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
'CLANG_CXX_LIBRARY': 'libc++',
'MACOSX_DEPLOYMENT_TARGET': '10.7',
'OTHER_CFLAGS': [
'-fobjc-arc',
],
},
'link_settings': {
'libraries': [
'$(SDKROOT)/System/Library/Frameworks/CoreBluetooth.framework',
]
},
}],
['OS=="win"', {
'sources': [
'lib/winrt/src/noble_winrt.cc',
'lib/winrt/src/napi_winrt.cc',
'lib/winrt/src/peripheral_winrt.cc',
'lib/winrt/src/radio_watcher.cc',
'lib/winrt/src/notify_map.cc',
'lib/winrt/src/ble_manager.cc',
'lib/winrt/src/winrt_cpp.cc',
'lib/winrt/src/winrt_guid.cc',
'lib/winrt/src/callbacks.cc',
],
'msvs_settings': {
'VCCLCompilerTool': {
'ExceptionHandling': 1,
'AdditionalOptions': ['/await', '/std:c++latest'],
},
},
'msvs_target_platform_version':'10.0.15063.0',
'msvs_target_platform_minversion':'10.0.15063.0',
'defines': [ '_HAS_EXCEPTIONS=1' ],
}],
],
},
],
}
75 changes: 75 additions & 0 deletions examples/echo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Connect to a peripheral running the echo service
// https://github.com/noble/bleno/blob/master/examples/echo

// subscribe to be notified when the value changes
// start an interval to write data to the characteristic

//const noble = require('noble');
const noble = require('..');

const ECHO_SERVICE_UUID = 'ec00';
const ECHO_CHARACTERISTIC_UUID = 'ec0e';

noble.on('stateChange', state => {
if (state === 'poweredOn') {
console.log('Scanning');
noble.startScanning([ECHO_SERVICE_UUID]);
} else {
noble.stopScanning();
}
});

noble.on('discover', peripheral => {
// connect to the first peripheral that is scanned
noble.stopScanning();
const name = peripheral.advertisement.localName;
console.log(`Connecting to '${name}' ${peripheral.id}`);
connectAndSetUp(peripheral);
});

function connectAndSetUp(peripheral) {

peripheral.connect(error => {
console.log('Connected to', peripheral.id);

// specify the services and characteristics to discover
const serviceUUIDs = [ECHO_SERVICE_UUID];
const characteristicUUIDs = [ECHO_CHARACTERISTIC_UUID];

peripheral.discoverSomeServicesAndCharacteristics(
serviceUUIDs,
characteristicUUIDs,
onServicesAndCharacteristicsDiscovered
);
});

peripheral.on('disconnect', () => console.log('disconnected'));
}

function onServicesAndCharacteristicsDiscovered(error, services, characteristics) {
console.log('Discovered services and characteristics');
const echoCharacteristic = characteristics[0];

// data callback receives notifications
echoCharacteristic.on('data', (data, isNotification) => {
console.log('Received: "' + data + '"');
});

// subscribe to be notified whenever the peripheral update the characteristic
echoCharacteristic.subscribe(error => {
if (error) {
console.error('Error subscribing to echoCharacteristic');
} else {
console.log('Subscribed for echoCharacteristic notifications');
}
});

// create an interval to send data to the service
let count = 0;
setInterval(() => {
count++;
const message = new Buffer('hello, ble ' + count, 'utf-8');
console.log("Sending: '" + message + "'");
echoCharacteristic.write(message);
}, 2500);
}
20 changes: 8 additions & 12 deletions lib/mac/bindings.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
var os = require('os');
var osRelease = parseFloat(os.release());

if (osRelease < 13 ) {
module.exports = require('./legacy');
} else if (osRelease < 14) {
module.exports = require('./mavericks');
} else if (osRelease < 17) {
module.exports = require('./yosemite');
} else {
module.exports = require('./highsierra');
}
const events = require('events');
const util = require('util');

const NobleMac = require('bindings')('noble').NobleMac;

util.inherits(NobleMac, events.EventEmitter);

module.exports = new NobleMac();
Loading