@sevenqi/nodechannel
Version:
nodejs channel
58 lines • 2.08 kB
JavaScript
;
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SessionClient = exports.SessionServer = void 0;
var uuid_1 = require("uuid");
var SessionServer = /** @class */ (function () {
function SessionServer(channel) {
var _this = this;
this.onMessage = function (buffer) {
console.log(buffer);
};
this.onClose = function () {
console.log("tcp is closed!");
};
this.channel = channel;
this.id = (0, uuid_1.v4)();
this.channel.onClose = function () { return _this.onClose(_this.id); };
}
SessionServer.prototype.send = function (message) {
this.channel.send(message);
};
return SessionServer;
}());
exports.SessionServer = SessionServer;
var SessionClient = /** @class */ (function () {
function SessionClient(channelCtor, args) {
this.onMessage = function (buffer) {
console.log(buffer);
};
this.onClose = function () {
console.log("tcp is closed!");
};
this.channelCtor = channelCtor;
this.args = args;
this.id = (0, uuid_1.v4)();
}
SessionClient.prototype.send = function (message) {
this.channel.send(message);
};
SessionClient.prototype.openChannel = function () {
var _a;
var _this = this;
this.channel = new ((_a = this.channelCtor).bind.apply(_a, __spreadArray([void 0], this.args, false)))();
this.channel.onClose = function () { return _this.onClose(_this.id); };
return this.open();
};
return SessionClient;
}());
exports.SessionClient = SessionClient;
//# sourceMappingURL=session.js.map