Last active
July 24, 2016 03:15
-
-
Save sklink/e75a5ac546fefbe0796ac2009f0b0695 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
// TODO: Verify if we're getting loaded from multiples location and prevent creating new child processes? | |
var EventEmitter2 = require('eventemitter2').EventEmitter2; | |
var path = require('path'); | |
var spawn = require('child_process').spawn; | |
var events = new EventEmitter2({wildcard: true}); | |
var javaPath = ''; | |
var gkm; | |
function start() { | |
gkm = spawn(javaPath + 'java', ['-jar', path.join(__dirname, 'lib/gkm.jar')]); | |
gkm.stdout.on('data', function(data) { | |
data = data.toString().split(/\r\n|\r|\n/).filter(function(item) { return item; }); | |
for (var i in data) { | |
var parts = data[i].split(':'); | |
events.emit(parts[0], parts.slice(1)); | |
} | |
}); | |
} | |
function stop() { | |
gkm.kill('SIGINT'); | |
} | |
function setJavaPath(path) { | |
if (typeof path === 'string') { | |
javaPath = path; | |
} else { | |
console.error("path must be a string"); | |
} | |
} | |
start(); | |
module.exports = { | |
events: events, | |
stop: stop, | |
start: start | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment