UNPKG

open-epsilon

Version:

empty-epsilon / open-sound-control bidirectional proxy

42 lines 1.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.OscUdpDriver = void 0; const tslib_1 = require("tslib"); const rxjs_1 = require("rxjs"); const osc_1 = require("osc"); const operators_1 = require("rxjs/operators"); class OscUdpDriver { constructor(options) { this.subject = new rxjs_1.Subject(); this.outbox = this.subject; options = Object.assign({}, { remoteAddress: "255.255.255.255", broadcast: true, metadata: true }, options); this.port = new osc_1.UDPPort(options); this.subscription = this.subject .pipe(operators_1.groupBy((msg) => msg.address)) .pipe(operators_1.mergeMap((o) => { // o is an observable of all messages of the same address // this is the place to use distinctUntilKeyChanged('args', (args1, args2) => deepEqual(args1, args2)) // and throttleTime return o; })) .subscribe(msg => this.port.send(msg)); this.inbox = rxjs_1.fromEvent(this.port, 'message').pipe(operators_1.map(([msg]) => msg)); console.info(`OSC server listening on ${options.localAddress}:${options.localPort}, sending to ${options.remoteAddress}:${options.remotePort}`); } open() { return tslib_1.__awaiter(this, void 0, void 0, function* () { this.port.open(); yield new Promise(res => this.port.once('ready', res)); }); } close() { this.subscription.unsubscribe(); this.port.close(); } } exports.OscUdpDriver = OscUdpDriver; //# sourceMappingURL=osc-udp-driver.js.map