Socket
Socket
Sign inDemoInstall

linux-device

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

linux-device - npm Package Compare versions

Comparing version 1.0.8 to 1.0.9

bin/remote-device-server

10

index.js
"use strict";
var DeviceHandle = require('bindings')('DeviceHandle');
exports = module.exports = DeviceHandle.DeviceHandle;
if(process.env.DEVICE_DEBUG_SERVER) {
let DeviceHandle = require('./remote/client')(process.env.DEVICE_DEBUG_SERVER);
exports = module.exports = DeviceHandle;
} else {
let DeviceHandle = require('./lib/DeviceHandle');
exports = module.exports = DeviceHandle;
}
{
"name": "linux-device",
"version": "1.0.8",
"version": "1.0.9",
"description": "Native addon to communicate with linux devices (can also be used for sockets or FIFOs)",

@@ -31,2 +31,3 @@ "main": "index.js",

},
"bin": "./bin/remote-device-server",
"homepage": "https://github.com/athombv/node-linux-device#readme",

@@ -36,4 +37,6 @@ "dependencies": {

"nan": "^2.1.0",
"node-gyp": "^3.2.1"
"node-gyp": "^3.2.1",
"socket.io": "1.7.2",
"socket.io-client": "1.7.2"
}
}

@@ -1,27 +0,58 @@

const net = require('net');
"use strict";
const io = require('socket.io-client');
const metadata = require('./metadata.json');
const debugData = {
host: 'localhost',
port: 1337,
debug: true
let server;
let handles = {};
class DeviceHandleProxy {
constructor(path) {
let args = Array.prototype.slice.apply(arguments);
handles[path] = args.pop();
this._path = path;
args.unshift('create_handle');
server.then(serv => serv.emit.apply(serv, args));
}
}
module.exports = function(url) {
server = new Promise((resolve, reject) => {
let serv = io.connect(url);
serv.on('connect', () => resolve(serv));
serv.on('connect_error', () => reject());
serv.on('connect_timeout', () => reject());
class DeviceHandleProxy {
constructor() {
let args = Array.splice(arguments);
this._opts = debugData;
this._cb = args.pop();
this._client = net.createConnection(debugData.port, debugData.host);
this._client.once('connect', () => {
this._connected = true;
if(this._opts.debug) console.log('connected');
this._invoke('constructor', args, this._cb);
serv.on('read_error', function(path, err) {
if(handles[path]) handles[path](err);
});
this._client.once('error', ())
}
_invoke(func, args, cb) {
serv.on('read_data', (path, data) => {
if(handles[path]) handles[path](null, data);
});
}
serv.on('server_error', (error) => {
console.error('[linux-device] An remote error occured:', error);
});
}
serv.on('connect', () => console.log('REMOTE DEVICE SUPPORT ENABLED, CONNECTED TO:', url));
serv.on('disconnect', () => {
Object.keys(handles).forEach((handle) => {
handles[handle](new Error('Remote Connection unexpectedly closed.'));
});
});
});
metadata.functions.forEach((func) => {
DeviceHandleProxy.prototype[func] = function() {
server.then(serv => serv.emit.bind(serv, func, this._path).apply(null, arguments));
};
});
metadata.constants.forEach((c, index) => {
DeviceHandleProxy[c] = c;
});
return DeviceHandleProxy;
};

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