@sevenqi/nodechannel
Version:
nodejs channel
51 lines • 2.04 kB
JavaScript
;
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 (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.UdpDuplex = void 0;
var stream_1 = require("stream");
var UdpDuplex = /** @class */ (function (_super) {
__extends(UdpDuplex, _super);
function UdpDuplex(udp) {
var _this = _super.call(this, { readableObjectMode: true }) || this;
_this.udp = udp;
_this.udp.on("message", function (msg, rinfo) {
_this.push(JSON.stringify({ msg: msg, rinfo: rinfo }));
});
_this.udp.on("close", function () {
_this.emit("close");
});
return _this;
}
UdpDuplex.prototype._write = function (chunk, encoding, callback) {
this.udp.send(chunk, this.port, this.address, callback);
};
UdpDuplex.prototype._read = function (size) {
this.resume();
};
UdpDuplex.prototype.connect = function (port, host, connectionListener) {
this.port = port;
this.address = host;
};
UdpDuplex.prototype.bind = function (port, host, connectionListener) {
this.port = port;
this.address = host;
this.udp.bind(port, host, connectionListener);
};
return UdpDuplex;
}(stream_1.Duplex));
exports.UdpDuplex = UdpDuplex;
//# sourceMappingURL=udpDuplex.js.map