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
203 changes: 113 additions & 90 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,93 +1,116 @@
{
"extends": [
"airbnb-base",
"plugin:security/recommended",
"eslint:recommended",
"plugin:node/recommended"
],

"globals": {

},

"env": {
"browser": true,
"node": true,
"es6": true
},

"plugins": [
// Node specific ESLint rules (requires eslint-plugin-node)
"node",

// Identify potential security hotspots (requires eslint-plugin-security)
"security",

// Enable es6 imports (requires eslint-plugin-import)
"import"

// Enable linting in html files (requires eslint-plugin-html)
// "html"
],

"parserOptions": {
"ecmaVersion": 2017,
"sourceType": "module",
"ecmaFeatures": {
"impliedStrict": true
"extends": [
"airbnb-base",
"plugin:security/recommended",
"eslint:recommended",
"plugin:node/recommended"
],
"globals": {
},
"env": {
"browser": true,
"node": true,
"es6": true
},
"plugins": [
// Node specific ESLint rules (requires eslint-plugin-node)
"node",
// Identify potential security hotspots (requires eslint-plugin-security)
"security",
// Enable es6 imports (requires eslint-plugin-import)
"import"

// Enable linting in html files (requires eslint-plugin-html)
// "html"
],
"parserOptions": {
"ecmaVersion": 2017,
"sourceType": "module",
"ecmaFeatures": {
"impliedStrict": true
}
},
"rules": {
"indent": [
"error",
4,
{
"SwitchCase": 1,
"VariableDeclarator": 1,
"outerIIFEBody": 1,
// MemberExpression: null,
// CallExpression: {
// parameters: null,
// },
"FunctionDeclaration": {
"parameters": 1,
"body": 1
},
"FunctionExpression": {
"parameters": 1,
"body": 1
}
}
],
"no-underscore-dangle": [
"error",
{
"allowAfterThis": true,
"allowAfterSuper": true
}
],
"spaced-comment": [
"error",
"always",
{
"line": {
"exceptions": [
"-",
"+",
"*"
],
"markers": [
"=",
"!"
]
// space here to support sprockets directives
},
"block": {
"exceptions": [
"-",
"+",
"*"
],
"markers": [
"=",
"!"
],
// space here to support sprockets directives
"balanced": false
}
}
],
"comma-dangle": [
"error",
"never"
],
"max-len": [
"error",
120,
2,
{
"ignoreUrls": true,
"ignoreComments": false,
"ignoreRegExpLiterals": true,
"ignoreStrings": true,
"ignoreTemplateLiterals": true
}
],
"arrow-parens": [
"error",
"as-needed"
],
"security/detect-child-process": "off",
"security/detect-non-literal-fs-filename": "off"
}
},

"rules": {
"indent": ["error", 4, {
"SwitchCase": 1,
"VariableDeclarator": 1,
"outerIIFEBody": 1,
// MemberExpression: null,
// CallExpression: {
// parameters: null,
// },
"FunctionDeclaration": {
"parameters": 1,
"body": 1
},
"FunctionExpression": {
"parameters": 1,
"body": 1
}
}],

"no-underscore-dangle": ["error", {
"allowAfterThis": true,
"allowAfterSuper": true
}],

"spaced-comment": ["error", "always", {
"line": {
"exceptions": ["-", "+", "*"],
"markers": ["=", "!"] // space here to support sprockets directives
},
"block": {
"exceptions": ["-", "+", "*"],
"markers": ["=", "!"], // space here to support sprockets directives
"balanced": false
}
}],

"comma-dangle": ["error", "never"],

"max-len": ["error", 120, 2, {
"ignoreUrls": true,
"ignoreComments": false,
"ignoreRegExpLiterals": true,
"ignoreStrings": true,
"ignoreTemplateLiterals": true
}],

"arrow-parens": ["error", "as-needed"],

"security/detect-child-process": "off",
"security/detect-non-literal-fs-filename": "off"
}

}
55 changes: 46 additions & 9 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ const IS_WIN = process.platform === 'win32';
const IS_MAC = process.platform === 'darwin';

class LCUConnector extends EventEmitter {

/**
* Gets the lcu path from a running instance.
* @returns {Promise<unknown>}
*/
static getLCUPathFromProcess() {
return new Promise(resolve => {
const INSTALL_REGEX_WIN = /"--install-directory=(.*?)"/;
const INSTALL_REGEX_MAC = /--install-directory=(.*?)( --|\n|$)/;
const INSTALL_REGEX = IS_WIN ? INSTALL_REGEX_WIN : INSTALL_REGEX_MAC;
const command = IS_WIN ?
`WMIC PROCESS WHERE name='LeagueClientUx.exe' GET commandline` :
`ps x -o args | grep 'LeagueClientUx'`;
const command = IS_WIN
? 'WMIC PROCESS WHERE name=\'LeagueClientUx.exe\' GET commandline'
: 'ps x -o args | grep \'LeagueClientUx\'';

cp.exec(command, (err, stdout, stderr) => {
if (err || !stdout || stderr) {
Expand All @@ -32,6 +35,12 @@ class LCUConnector extends EventEmitter {
});
}

/**
* Checks if the path given is a valid lcu path.
*
* @param dirPath
* @returns {boolean}
*/
static isValidLCUPath(dirPath) {
if (!dirPath) {
return false;
Expand All @@ -41,11 +50,13 @@ class LCUConnector extends EventEmitter {
const common = fs.existsSync(path.join(dirPath, lcuClientApp)) && fs.existsSync(path.join(dirPath, 'Config'));
const isGlobal = common && fs.existsSync(path.join(dirPath, 'RADS'));
const isCN = common && fs.existsSync(path.join(dirPath, 'TQM'));
const isGarena = common; // Garena has no other

return isGlobal || isCN || isGarena;
// Garena has no other
return isGlobal || isCN || common;
}

/**
* @param {string} [executablePath]
*/
constructor(executablePath) {
super();

Expand All @@ -54,6 +65,9 @@ class LCUConnector extends EventEmitter {
}
}

/**
* Starts the lcu-connector
*/
start() {
if (LCUConnector.isValidLCUPath(this._dirPath)) {
this._initLockfileWatcher();
Expand All @@ -63,11 +77,17 @@ class LCUConnector extends EventEmitter {
this._initProcessWatcher();
}

/**
* Stops the lcu-connector
*/
stop() {
this._clearProcessWatcher();
this._clearLockfileWatcher();
}

/**
* @private
*/
_initLockfileWatcher() {
if (this._lockfileWatcher) {
return;
Expand All @@ -81,12 +101,19 @@ class LCUConnector extends EventEmitter {
this._lockfileWatcher.on('unlink', this._onFileRemoved.bind(this));
}

/**
* @private
*/
_clearLockfileWatcher() {
if (this._lockfileWatcher) {
this._lockfileWatcher.close();
}
}

/**
* @returns {Promise<unknown>}
* @private
*/
_initProcessWatcher() {
return LCUConnector.getLCUPathFromProcess().then(lcuPath => {
if (lcuPath) {
Expand All @@ -102,12 +129,19 @@ class LCUConnector extends EventEmitter {
});
}

/**
* @private
*/
_clearProcessWatcher() {
clearInterval(this._processWatcher);
}

_onFileCreated(path) {
lockfile.read(path).then(data => {
/**
* @param filePath
* @private
*/
_onFileCreated(filePath) {
lockfile.read(filePath).then(data => {
const result = {
protocol: data.protocol,
address: '127.0.0.1',
Expand All @@ -120,6 +154,9 @@ class LCUConnector extends EventEmitter {
});
}

/**
* @private
*/
_onFileRemoved() {
this.emit('disconnect');
}
Expand Down
Loading