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

support node 10+ #129

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bluetooth-hci-socket",
"version": "0.5.2",
"version": "0.5.3",
"description": "Bluetooth HCI socket binding for Node.js",
"main": "index.js",
"repository": {
Expand All @@ -27,8 +27,8 @@
],
"dependencies": {
"debug": "^2.2.0",
"nan": "^2.0.5",
"node-pre-gyp": "0.6.x"
"nan": "^2.14.1",
"node-pre-gyp": "^0.15.0"
},
"optionalDependencies": {
"usb": "^1.1.0"
Expand All @@ -37,15 +37,15 @@
"jshint": "^2.8.0"
},
"scripts": {
"preinstall": "npm install node-pre-gyp",
"install": "node-pre-gyp install --fallback-to-build",
"test": "jshint lib/*.js"
"preinstall": "npm install node-pre-gyp",
"install": "node-pre-gyp install --fallback-to-build",
"test": "jshint lib/*.js"
},
"binary": {
"module_name": "binding",
"module_path": "./lib/binding/",
"host": "https://github.com/sandeepmistry/node-bluetooth-hci-socket/releases/download/",
"package_name": "{module_name}-{version}-{node_abi}-{platform}-{arch}.tar.gz",
"remote_path": "{version}"
"module_name": "binding",
"module_path": "./lib/binding/",
"host": "https://github.com/sandeepmistry/node-bluetooth-hci-socket/releases/download/",
"package_name": "{module_name}-{version}-{node_abi}-{platform}-{arch}.tar.gz",
"remote_path": "{version}"
}
}
33 changes: 22 additions & 11 deletions src/BluetoothHciSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

#define ATT_CID 4

using v8::Context;

enum {
HCI_UP,
HCI_INIT,
Expand Down Expand Up @@ -126,7 +128,15 @@ NAN_MODULE_INIT(BluetoothHciSocket::Init) {
Nan::SetPrototypeMethod(tmpl, "stop", Stop);
Nan::SetPrototypeMethod(tmpl, "write", Write);

target->Set(Nan::New("BluetoothHciSocket").ToLocalChecked(), tmpl->GetFunction());

v8::Isolate* isolate = target->GetIsolate();
v8::Local<v8::Context> context = isolate->GetCurrentContext();

target->Set(
context,
Nan::New("BluetoothHciSocket").ToLocalChecked(),
tmpl->GetFunction( context ).ToLocalChecked()
);
}

BluetoothHciSocket::BluetoothHciSocket() :
Expand Down Expand Up @@ -267,13 +277,14 @@ void BluetoothHciSocket::emitErrnoError() {
Nan::HandleScope scope;

Local<Object> globalObj = Nan::GetCurrentContext()->Global();
Local<Function> errorConstructor = Local<Function>::Cast(globalObj->Get(Nan::New("Error").ToLocalChecked()));

Local<Function> errorConstructor = Local<Function>::Cast(globalObj->Get(Nan::GetCurrentContext(), Nan::New("Error").ToLocalChecked()).ToLocalChecked() );

Local<Value> constructorArgs[1] = {
Nan::New(strerror(errno)).ToLocalChecked()
};

Local<Value> error = errorConstructor->NewInstance(1, constructorArgs);
Local<Value> error = errorConstructor->NewInstance(Nan::GetCurrentContext(), 1, constructorArgs).ToLocalChecked();

Local<Value> argv[2] = {
Nan::New("error").ToLocalChecked(),
Expand Down Expand Up @@ -393,7 +404,7 @@ NAN_METHOD(BluetoothHciSocket::BindRaw) {
if (info.Length() > 0) {
Local<Value> arg0 = info[0];
if (arg0->IsInt32() || arg0->IsUint32()) {
devId = arg0->IntegerValue();
devId = arg0->IntegerValue( Nan::GetCurrentContext() ).ToChecked();

pDevId = &devId;
}
Expand All @@ -415,7 +426,7 @@ NAN_METHOD(BluetoothHciSocket::BindUser) {
if (info.Length() > 0) {
Local<Value> arg0 = info[0];
if (arg0->IsInt32() || arg0->IsUint32()) {
devId = arg0->IntegerValue();
devId = arg0->IntegerValue( Nan::GetCurrentContext() ).ToChecked();

pDevId = &devId;
}
Expand Down Expand Up @@ -468,12 +479,12 @@ NAN_METHOD(BluetoothHciSocket::GetDeviceList) {
bool devUp = dr->dev_opt & (1 << HCI_UP);
if (dr != NULL) {
v8::Local<v8::Object> obj = Nan::New<v8::Object>();
obj->Set(Nan::New("devId").ToLocalChecked(), Nan::New<Number>(devId));
obj->Set(Nan::New("devUp").ToLocalChecked(), Nan::New<Boolean>(devUp));
obj->Set(Nan::New("idVendor").ToLocalChecked(), Nan::Null());
obj->Set(Nan::New("idProduct").ToLocalChecked(), Nan::Null());
obj->Set(Nan::New("busNumber").ToLocalChecked(), Nan::Null());
obj->Set(Nan::New("deviceAddress").ToLocalChecked(), Nan::Null());
obj->Set(obj, Nan::New("devUp").ToLocalChecked(), Nan::New<Boolean>(devUp));
obj->Set(obj, Nan::New("devId").ToLocalChecked(), Nan::New<Number>(devId));
obj->Set(obj, Nan::New("idVendor").ToLocalChecked(), Nan::Null());
obj->Set(obj, Nan::New("idProduct").ToLocalChecked(), Nan::Null());
obj->Set(obj, Nan::New("busNumber").ToLocalChecked(), Nan::Null());
obj->Set(obj, Nan::New("deviceAddress").ToLocalChecked(), Nan::Null());
Nan::Set(deviceList, di++, obj);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/BluetoothHciSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class BluetoothHciSocket : public node::ObjectWrap {
std::map<unsigned short,int> _l2sockets;
uint8_t _address[6];
uint8_t _addressType;
//v8::Isolate* isolate;

static Nan::Persistent<v8::FunctionTemplate> constructor_template;
};
Expand Down