UNPKG

open-epsilon

Version:

empty-epsilon / open-sound-control bidirectional proxy

45 lines 1.84 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.executeDriverCommands = exports.monitorByAddress = exports.getMonitoredAddresses = exports.FILE_PATH = void 0; const tslib_1 = require("tslib"); const operators_1 = require("rxjs/operators"); exports.FILE_PATH = 'game-monitor.json'; function getMonitoredAddresses(fs) { const result = []; function handleFileContent(fileContent) { try { const addresses = JSON.parse(fileContent.toLowerCase()); result.splice(0, result.length, ...addresses); } catch (e) { console.error(`failed parsing ${exports.FILE_PATH} : ${fileContent}`); } } fs.events.on('fileChanged', ({ newContent, fullPath }) => { if (fullPath === exports.FILE_PATH) { handleFileContent(newContent); } }); fs.loadTextFile(exports.FILE_PATH).then(handleFileContent); return result; } exports.getMonitoredAddresses = getMonitoredAddresses; function monitorByAddress(pollRequests, eeDriver, translator) { return pollRequests .pipe(operators_1.map(translator)) .pipe(operators_1.mergeMap((q) => tslib_1.__awaiter(this, void 0, void 0, function* () { const values = yield eeDriver.query(q.expr, q.type.length); return { address: q.address, args: values.map((value, i) => ({ type: q.type.charAt(i), value })) }; }))); } exports.monitorByAddress = monitorByAddress; function executeDriverCommands(pushRequests, eeDriver, translator) { return pushRequests .pipe(operators_1.map(translator)) .subscribe(gc => eeDriver.command(gc.template, gc.values)); } exports.executeDriverCommands = executeDriverCommands; //# sourceMappingURL=game-monitor.js.map