Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

devicestack

Package Overview
Dependencies
Maintainers
1
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

devicestack - npm Package Compare versions

Comparing version 1.3.3 to 1.4.0

lib/globalserialdeviceloader.js

14

lib/deviceloader.js

@@ -10,3 +10,3 @@ var EventEmitter2 = require('eventemitter2').EventEmitter2,

var self = this;
// call super class

@@ -94,14 +94,2 @@ EventEmitter2.call(this, {

this.trigger(function(err, devices) {
// at the moment the serialport.list function consumes too much memory...
// (function run() {
// if (!self.isRunning) return;
// process.nextTick(function() {
// self.trigger(function() {
// run();
// });
// });
// })();
var triggering = false;

@@ -108,0 +96,0 @@ self.lookupIntervalId = setInterval(function() {

@@ -1,5 +0,6 @@

var sp = require("serialport"),
var sp = require('serialport'),
DeviceLoader = require('./deviceloader'),
util = require('util'),
_ = require('lodash');
_ = require('lodash'),
globalSerialDeviceLoader = require('./globalserialdeviceloader');

@@ -10,3 +11,3 @@ /**

*/
function SerialDeviceLoader(Device) {
function SerialDeviceLoader(Device, useGlobal) {

@@ -17,2 +18,8 @@ // call super class

this.Device = Device;
this.useGlobal = (useGlobal === undefined || useGlobal === null) ? true : useGlobal;
if (this.useGlobal) {
this.globalSerialDeviceLoader = globalSerialDeviceLoader.create(Device, this.filter);
}
}

@@ -22,2 +29,23 @@

/* Override of EventEmitter. */
SerialDeviceLoader.prototype.on = function(eventname, callback) {
if (this.useGlobal) {
this.globalSerialDeviceLoader.on.apply(this.globalSerialDeviceLoader, _.toArray(arguments));
} else {
DeviceLoader.prototype.on.apply(this, _.toArray(arguments));
}
};
/* Override of EventEmitter. */
SerialDeviceLoader.prototype.removeListener = function(eventname, callback) {
if (this.useGlobal) {
this.globalSerialDeviceLoader.removeListener.apply(this.globalSerialDeviceLoader, _.toArray(arguments));
} else {
DeviceLoader.prototype.removeListener.apply(this, _.toArray(arguments));
}
};
/* Same as removeListener */
SerialDeviceLoader.prototype.off = SerialDeviceLoader.prototype.removeListener;
/**

@@ -29,23 +57,67 @@ * Calls the callback with an array of devices.

SerialDeviceLoader.prototype.lookup = function(callback) {
var self = this;
sp.list(function(err, ports) {
if (err) { return callback(err); }
if (this.useGlobal) {
this.globalSerialDeviceLoader.lookup(callback);
} else {
var self = this;
sp.list(function(err, ports) {
if (err) { return callback(err); }
var resPorts = self.filter(ports);
var resPorts = self.filter(ports);
var devices = _.map(resPorts, function(p) {
var found = _.find(self.oldDevices, function(dev) {
return dev.get('portName') === p.comName;
});
if (found) {
return found;
} else {
return new self.Device(p.comName);
}
}) || [];
var devices = _.map(resPorts, function(p) {
var found = _.find(self.oldDevices, function(dev) {
return dev.get('portName') === p.comName;
});
if (found) {
return found;
} else {
return new self.Device(p.comName);
}
}) || [];
callback(null, devices);
});
callback(null, devices);
});
}
};
/**
* Calls lookup function with optional callback
* and emits 'plug' for new attached devices
* and 'unplug' for removed devices.
* @param {Function} callback The function, that will be called when finished triggering. [optional]
* `function(err, devices){}` devices is an array of Device objects.
*/
SerialDeviceLoader.prototype.trigger = function(callback) {
if (this.useGlobal) {
this.globalSerialDeviceLoader.trigger(callback);
} else {
DeviceLoader.prototype.trigger.apply(this, _.toArray(arguments));
}
};
/**
* Starts to lookup.
* @param {Number} interval The interval milliseconds. [optional]
* @param {Function} callback The function, that will be called when trigger has started. [optional]
* `function(err, devices){}` devices is an array of Device objects.
*/
SerialDeviceLoader.prototype.startLookup = function(interval, callback) {
if (this.useGlobal) {
this.globalSerialDeviceLoader.startLookup(interval, callback);
} else {
DeviceLoader.prototype.startLookup.apply(this, _.toArray(arguments));
}
};
/**
* Stops the interval that calls trigger function.
*/
SerialDeviceLoader.prototype.stopLookup = function() {
if (this.useGlobal) {
this.globalSerialDeviceLoader.stopLookup();
} else {
DeviceLoader.prototype.stopLookup.apply(this, _.toArray(arguments));
}
};
module.exports = SerialDeviceLoader;
{
"name": "devicestack",
"version": "1.3.3",
"version": "1.4.0",
"description": "This module helps you to represent a device and its protocol.",

@@ -5,0 +5,0 @@ "private": false,

@@ -717,6 +717,12 @@ <pre>

# Release Notes
## v1.4.0
- default serial device loaders uses the global serial device loader under the hood
# License
Copyright (c) 2012 Adriano Raiano
Copyright (c) 2013 Adriano Raiano

@@ -723,0 +729,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc