UNPKG

@chix/flow

Version:
68 lines 2.37 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var _debug = require("debug"); var events_1 = require("./events"); var setting_1 = require("./setting"); var debug = _debug('chix:connector'); var Connector = (function (_super) { __extends(Connector, _super); function Connector() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.id = null; _this.pid = null; _this.port = null; _this.wire = null; return _this; } Connector.create = function (id, port, settings, action) { var c = new Connector(settings); c.plug(id, port, action); return c; }; Connector.prototype.plug = function (id, port, action) { debug('plug %s:%s', id, port); this.id = id; this.port = port; if (action) { this.action = action; } }; Connector.prototype.write = function (packet) { var index = this.get('index'); debug('write %s:%s %s', this.id, this.port, index === undefined ? '' : "[" + index + "]"); this.emit(events_1.ConnectorEvents.DATA, packet, this); }; Connector.prototype.setPid = function (pid) { this.pid = pid; }; Connector.prototype.toJSON = function () { var json = { id: this.id, port: this.port, setting: undefined, }; if (this.setting && Object.keys(this.setting).length > 0) { json.setting = JSON.parse(JSON.stringify(this.setting)); } if (this.action) { json.action = this.action; } return json; }; return Connector; }(setting_1.Setting)); exports.Connector = Connector; //# sourceMappingURL=connector.js.map