siesta-lite
Version:
Stress-free JavaScript unit testing and functional testing tool, works in NodeJS and browsers
51 lines (50 loc) • 2.27 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 (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 Common_js_1 = require("../../../generic/util/Common.js");
var ChannelEndPoint_js_1 = require("../../../generic/channel/ChannelEndPoint.js");
var ParseJsonSafely_js_1 = require("../../../generic/util/helper/ParseJsonSafely.js");
var NodeJsLogger_js_1 = require("../../util/role/NodeJsLogger.js");
var ServerEndPoint = /** @class */ (function (_super) {
__extends(ServerEndPoint, _super);
function ServerEndPoint(props) {
var _this = _super.call(this, props) || this;
Object.assign(_this, props);
if (!_this.socket)
throw new Error("`socket` attribute is required");
return _this;
}
ServerEndPoint.prototype.doConnect = function (channel) {
this.socket.addListener('message', this.messageListener = this.onRawChannelMessage.bind(this));
return Promise.resolve();
};
ServerEndPoint.prototype.doDisconnect = function () {
this.socket.removeListener('message', this.messageListener);
};
ServerEndPoint.prototype.sendMessage = function (message) {
this.socket.send(message);
};
ServerEndPoint.prototype.messageToEnvelop = function (message) {
var envelop = ParseJsonSafely_js_1.parseJsonSafely(message);
if (envelop && envelop.id == null)
return undefined;
return envelop;
};
ServerEndPoint.prototype.envelopToMessage = function (envelop) {
return JSON.stringify(envelop);
};
return ServerEndPoint;
}(ChannelEndPoint_js_1.ChannelEndPoint(NodeJsLogger_js_1.NodeJsLogger(Common_js_1.Base))));
exports.ServerEndPoint = ServerEndPoint;
;