node-nfcpy-id
Advanced tools
Comparing version 0.0.5 to 0.0.6
143
index.js
@@ -1,3 +0,1 @@ | ||
'use strict'; | ||
const EventEmitter = require('events').EventEmitter; | ||
@@ -7,91 +5,90 @@ const PythonShell = require('python-shell'); | ||
module.exports = class extends EventEmitter { | ||
constructor(options) { | ||
super(); | ||
this._options = options; | ||
this._mode = 'mode' in (options || {}) ? options.mode : 'loop'; | ||
this._running = false; | ||
this._exiting = false; | ||
this._firstLaunch = false; | ||
constructor(options) { | ||
super(); | ||
this._options = options; | ||
this._mode = 'mode' in (options || {}) ? options.mode : 'loop'; | ||
this._running = false; | ||
this._exiting = false; | ||
this._firstLaunch = false; | ||
if (this._mode === 'non-loop') { | ||
this._loop = false; | ||
this._non_touchend = false; | ||
} else if (this._mode === 'non-touchend') { | ||
this._loop = false; | ||
this._non_touchend = true; | ||
} else { | ||
this._loop = true; | ||
this._non_touchend = false; | ||
} | ||
if (this._mode === 'non-loop') { | ||
this._loop = false; | ||
this._non_touchend = false; | ||
} else if (this._mode === 'non-touchend') { | ||
this._loop = false; | ||
this._non_touchend = true; | ||
} else { | ||
this._loop = true; | ||
this._non_touchend = false; | ||
} | ||
['SIGHUP', 'SIGINT', 'exit'].forEach((event) => { | ||
process.on(event, () => { | ||
if (this._firstLaunch) { | ||
this._exiting = true; | ||
this.sendSignal('SIGHUP'); | ||
console.log("aaaaaa"); | ||
} | ||
}); | ||
['SIGHUP', 'SIGINT', 'exit'].forEach((event) => { | ||
process.on(event, () => { | ||
if (this._firstLaunch) { | ||
this._exiting = true; | ||
this.sendSignal('SIGHUP'); | ||
} | ||
}); | ||
}); | ||
return this; | ||
} | ||
return this; | ||
} | ||
get isRunning() { | ||
return this._running; | ||
} | ||
get isRunning() { | ||
return this._running; | ||
} | ||
once() { | ||
const scriptFile = 'scriptFile' in (this._options || {}) ? | ||
this._options.scriptFile : 'reader.py'; | ||
const scriptPath = 'scriptPath' in (this._options || {}) ? | ||
this._options.scriptPath : __dirname; | ||
const args = [this._mode]; | ||
this.pyshell = new PythonShell(scriptFile, {scriptPath, args}, {mode: 'JSON'}); | ||
once() { | ||
const scriptFile = 'scriptFile' in (this._options || {}) ? | ||
this._options.scriptFile : 'reader.py'; | ||
const scriptPath = 'scriptPath' in (this._options || {}) ? | ||
this._options.scriptPath : __dirname; | ||
const args = [this._mode]; | ||
this.pyshell = new PythonShell(scriptFile, { scriptPath, args }, { mode: 'JSON' }); | ||
this.pyshell.stdout.on('data', (json) => { | ||
if (this.isRunning) { | ||
const data = JSON.parse(json.split('\n')[0]); | ||
this._running = this._loop || !this._non_touchend && !(data.event === 'touchend'); | ||
this.emit(data.event, data); | ||
} | ||
}); | ||
this.pyshell.end((err) => { | ||
if (!this._exiting) { | ||
this._running = false; | ||
this._firstLaunch = false; | ||
this.emit('error', err); | ||
} | ||
}); | ||
} | ||
start() { | ||
this.pyshell.stdout.on('data', (json) => { | ||
if (this.isRunning) { | ||
return this; | ||
const data = JSON.parse(json.split('\n')[0]); | ||
this._running = this._loop || (!this._non_touchend && !(data.event === 'touchend')); | ||
this.emit(data.event, data); | ||
} | ||
this._running = true; | ||
}); | ||
if (!this._firstLaunch) { | ||
this.once(); | ||
this._firstLaunch = true; | ||
} else { | ||
this.sendSignal('SIGCHLD'); | ||
this.pyshell.end((err) => { | ||
if (!this._exiting) { | ||
this._running = false; | ||
this._firstLaunch = false; | ||
this.emit('error', err); | ||
} | ||
}); | ||
} | ||
start() { | ||
if (this.isRunning) { | ||
return this; | ||
} | ||
this._running = true; | ||
pause() { | ||
if (!this.isRunning) { | ||
return this; | ||
} | ||
this._running = false; | ||
if (!this._firstLaunch) { | ||
this.once(); | ||
this._firstLaunch = true; | ||
} else { | ||
this.sendSignal('SIGCHLD'); | ||
} | ||
return this; | ||
} | ||
pause() { | ||
if (!this.isRunning) { | ||
return this; | ||
} | ||
this._running = false; | ||
this.sendSignal('SIGCHLD'); | ||
return this; | ||
} | ||
sendSignal(signal) { | ||
this.pyshell.childProcess.kill(signal); | ||
} | ||
} | ||
sendSignal(signal) { | ||
this.pyshell.childProcess.kill(signal); | ||
} | ||
}; |
{ | ||
"name": "node-nfcpy-id", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "Read the ID of an NFC Tag with nfcpy", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"lint": "eslint ./" | ||
}, | ||
@@ -26,4 +26,9 @@ "repository": { | ||
"babel-cli": "^6.24.1", | ||
"babel-preset-es2015": "^6.24.1" | ||
"babel-preset-es2015": "^6.24.1", | ||
"eslint": "^3.19.0", | ||
"eslint-config-airbnb": "^15.0.1", | ||
"eslint-plugin-import": "^2.3.0", | ||
"eslint-plugin-jsx-a11y": "^5.0.3", | ||
"eslint-plugin-react": "^7.0.1" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
2
7506
7
6
123