electron-reactive-ipc
Version:
rxjs based electron IPC channel wrapper
46 lines • 1.63 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DuplexChannel = void 0;
var rxjs_1 = require("rxjs");
var types_1 = require("./types");
var DuplexChannel = /** @class */ (function () {
function DuplexChannel(data, state) {
if (state === void 0) { state = types_1.ChannelState.OUTGOING; }
if (state !== types_1.ChannelState.OUTGOING) {
this.incoming = new rxjs_1.BehaviorSubject(data);
this.outgoing = new rxjs_1.BehaviorSubject(null);
}
else {
this.outgoing = new rxjs_1.BehaviorSubject(data);
this.incoming = new rxjs_1.BehaviorSubject(null);
}
//this.init();
}
Object.defineProperty(DuplexChannel.prototype, "listen", {
get: function () {
return this.incoming.pipe((0, rxjs_1.filter)(function (val) { return val ? true : false; }));
},
enumerable: false,
configurable: true
});
DuplexChannel.prototype.send = function (data) {
var _a;
(_a = this.outgoing) === null || _a === void 0 ? void 0 : _a.next(data);
};
/*
private init() {
this.outgoing.subscribe(val => {
if (val) { }
});
}
*/
DuplexChannel.prototype.close = function () {
if (!this.incoming.closed)
this.incoming.unsubscribe();
if (!this.outgoing.closed)
this.outgoing.unsubscribe();
};
return DuplexChannel;
}());
exports.DuplexChannel = DuplexChannel;
//# sourceMappingURL=channel.js.map