Skip to content
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"dependencies": {
"bindings": "1.1.0",
"eventemitter2": ">=0.4.11",
"nan": "^1.8.4"
"nan": "^2.0.9"
},
"gypfile": true,
"scripts": {
Expand Down
32 changes: 16 additions & 16 deletions src/detection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
#define OBJECT_ITEM_MOUNT_PATH "mountPath"


NanCallback* addedCallback;
Nan::Callback* addedCallback;
bool isAddedRegistered = false;

NanCallback* removedCallback;
Nan::Callback* removedCallback;
bool isRemovedRegistered = false;

void RegisterAdded(const v8::FunctionCallbackInfo<v8::Value>& args)
Expand All @@ -26,21 +26,21 @@ void RegisterAdded(const v8::FunctionCallbackInfo<v8::Value>& args)

if (args.Length() == 0)
{
return NanThrowTypeError("First argument must be a function");
return Nan::ThrowTypeError("First argument must be a function");
}

if (args.Length() == 1)
{
// callback
if (!args[0]->IsFunction())
{
return NanThrowTypeError("First argument must be a function");
return Nan::ThrowTypeError("First argument must be a function");
}

callback = args[0].As<v8::Function>();
}

addedCallback = new NanCallback(callback);
addedCallback = new Nan::Callback(callback);
isAddedRegistered = true;
}

Expand Down Expand Up @@ -101,21 +101,21 @@ void RegisterRemoved(const v8::FunctionCallbackInfo<v8::Value>& args)

if (args.Length() == 0)
{
return NanThrowTypeError("First argument must be a function");
return Nan::ThrowTypeError("First argument must be a function");
}

if (args.Length() == 1)
{
// callback
if (!args[0]->IsFunction())
{
return NanThrowTypeError("First argument must be a function");
return Nan::ThrowTypeError("First argument must be a function");
}

callback = args[0].As<v8::Function>();
}

removedCallback = new NanCallback(callback);
removedCallback = new Nan::Callback(callback);
isRemovedRegistered = true;
}

Expand Down Expand Up @@ -176,7 +176,7 @@ void Find(const v8::FunctionCallbackInfo<v8::Value>& args)

if (args.Length() == 0)
{
return NanThrowTypeError("First argument must be a function");
return Nan::ThrowTypeError("First argument must be a function");
}

if (args.Length() == 3)
Expand All @@ -190,7 +190,7 @@ void Find(const v8::FunctionCallbackInfo<v8::Value>& args)
// callback
if (!args[2]->IsFunction())
{
return NanThrowTypeError("Third argument must be a function");
return Nan::ThrowTypeError("Third argument must be a function");
}

callback = args[2].As<v8::Function>();
Expand All @@ -206,7 +206,7 @@ void Find(const v8::FunctionCallbackInfo<v8::Value>& args)
// callback
if (!args[1]->IsFunction())
{
return NanThrowTypeError("Second argument must be a function");
return Nan::ThrowTypeError("Second argument must be a function");
}

callback = args[1].As<v8::Function>();
Expand All @@ -217,15 +217,15 @@ void Find(const v8::FunctionCallbackInfo<v8::Value>& args)
// callback
if (!args[0]->IsFunction())
{
return NanThrowTypeError("First argument must be a function");
return Nan::ThrowTypeError("First argument must be a function");
}

callback = args[0].As<v8::Function>();
}

ListBaton* baton = new ListBaton();
strcpy(baton->errorString, "");
baton->callback = new NanCallback(callback);
baton->callback = new Nan::Callback(callback);

//baton->callback = v8::Persistent<v8::Value>::New(isolate, callback);
//NanAssignPersistent(baton->callback, new NanCallback(callback));
Expand All @@ -246,12 +246,12 @@ void EIO_AfterFind(uv_work_t* req)

ListBaton* data = static_cast<ListBaton*>(req->data);

v8::Handle<v8::Value> argv[2];
v8::Local<v8::Value> argv[2];

if (data->errorString[0])
{
argv[0] = v8::Exception::Error(v8::String::NewFromUtf8(isolate, data->errorString));
argv[1] = NanUndefined();
argv[1] = Nan::Undefined();
}

else
Expand Down Expand Up @@ -291,7 +291,7 @@ void EIO_AfterFind(uv_work_t* req)
results->Set(i, item);
}

argv[0] = NanUndefined();
argv[0] = Nan::Undefined();
argv[1] = results;
}

Expand Down
2 changes: 1 addition & 1 deletion src/detection.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct ListBaton
public:
//v8::Persistent<v8::Function> callback;

NanCallback* callback;
Nan::Callback* callback;
std::list<ListResultItem_t*> results;
char errorString[1024];
int vid;
Expand Down
6 changes: 1 addition & 5 deletions t.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
var monitor = require('./usb-detection');

monitor.find(function(err, devices) {
console.log("find: some devices");
});
monitor.find(vid, function(err, devices) {

Expand All @@ -12,7 +11,6 @@ monitor.find(vid, pid, function(err, devices) {
});

monitor.on('add', function(devices) {
console.log("add USB:", devices);

});

Expand All @@ -25,7 +23,6 @@ monitor.on('add:vid:pid', function(devices) {
});

monitor.on('remove', function(err, devices) {
console.log("remove USB ");

});

Expand All @@ -38,7 +35,6 @@ monitor.on('remove:vid:pid', function(err, devices) {
});

monitor.on('change', function(err, devices) {
console.log("change USB");
});

monitor.on('change:vid', function(err, devices) {
Expand All @@ -47,4 +43,4 @@ monitor.on('change:vid', function(err, devices) {

monitor.on('change:vid:pid', function(err, devices) {

});
});
5 changes: 1 addition & 4 deletions usb-detection.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ else
detector.find = detection.find;

detection.registerAdded(function(device) {
//console.log("registerAdded:", device, device.vendorId, device.productId);
console.log("registerAdded");

detector.emit('add', device);
detector.emit('add:' + device.vendorId + ':' + device.productId, device);
Expand All @@ -32,7 +30,6 @@ else
});

detection.registerRemoved(function(device) {
console.log("registerRemoved");

detector.emit('remove', device);
detector.emit('remove:' + device.vendorId + ':' + device.productId, device);
Expand Down Expand Up @@ -63,4 +60,4 @@ else
global[index.name] = detector;

module.exports = detector;
}
}