UNPKG

siesta-lite

Version:

Stress-free JavaScript unit testing and functional testing tool, works in NodeJS and browsers

67 lines (66 loc) 2.78 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 NodeJsLogger_js_1 = require("../../util/role/NodeJsLogger.js"); var Common_js_1 = require("../../../generic/util/Common.js"); var ws = require('ws'); var ConnectionServer = /** @class */ (function (_super) { __extends(ConnectionServer, _super); function ConnectionServer(props) { var _this = _super.call(this, props) || this; _this.port = 0; Object.assign(_this, props); return _this; } ConnectionServer.prototype.start = function () { var _this = this; return new Promise(function (resolve, reject) { var connectionServerWS = _this.connectionServerWS = new ws.Server({ clientTracking: true, port: _this.port }, function () { _this.port = _this.connectionServerWS.address().port; resolve(); }); connectionServerWS.on('connection', function (wsClient) { _this.debug("Connection received"); var cls = _this.serverClass; var config = Object.assign({ socket: wsClient, logLevel: _this.logLevel }, _this.serverConfig || {}); var webSocketServer = new cls(config); webSocketServer.connect(); }); connectionServerWS.on('error', function () { _this.stop(); }); // wsServer.on('error', (e) => console.log("ERROR: ", e)); // wsServer.on('headers', (headers, request) => console.log("HEADERS: ", headers, request)); }); }; ConnectionServer.prototype.stop = function () { var _this = this; return new Promise(function (resolve, reject) { if (_this.connectionServerWS) _this.connectionServerWS.close(function () { _this.connectionServerWS = null; resolve(); }); else resolve(); }); }; return ConnectionServer; }(NodeJsLogger_js_1.NodeJsLogger(Common_js_1.Base))); exports.ConnectionServer = ConnectionServer;