UNPKG

open-epsilon

Version:

empty-epsilon / open-sound-control bidirectional proxy

37 lines 1.78 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.OpenEpsilon = void 0; const ee_schema_1 = require("./ee-schema"); const rxjs_1 = require("rxjs"); const game_monitor_1 = require("./game-monitor"); const operators_1 = require("rxjs/operators"); const translate_1 = require("./translate"); const process_schema_1 = require("./process-schema"); class OpenEpsilon { constructor(eeDriver, oscDriver, apiSchema = ee_schema_1.emptyEpsilonSchema, namespace = 'ee') { this.eeDriver = eeDriver; this.oscDriver = oscDriver; this.namespace = namespace; this.monitoredAddresses = []; this.subscription = []; this.translator = new translate_1.MessageTranslator(process_schema_1.processApiSchema(apiSchema), namespace); } init(interval = 1000) { if (this.isInitialized()) { throw new Error('init() called on initialized service'); } const pulse = rxjs_1.interval(interval); const pollRequests = pulse.pipe(operators_1.switchMap(_ => this.monitoredAddresses)); this.subscription.push(game_monitor_1.monitorByAddress(pollRequests, this.eeDriver, this.translator.translateAddressToGameQuery).subscribe(this.oscDriver.outbox)); this.subscription.push(game_monitor_1.executeDriverCommands(this.oscDriver.inbox.pipe(operators_1.filter(m => m.address.startsWith(`/${this.namespace}/`))), this.eeDriver, this.translator.translateOscMessageToGameCommand)); } isInitialized() { return !!this.subscription.length; } destroy() { this.subscription.forEach(s => s.unsubscribe()); this.subscription = []; } } exports.OpenEpsilon = OpenEpsilon; //# sourceMappingURL=service.js.map