UNPKG

jspurefix

Version:
58 lines 2.67 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); require("reflect-metadata"); const http_server_1 = require("./http-server"); const http_client_1 = require("./http-client"); const runtime_1 = require("../../../runtime"); const util = require("util"); class AppLauncher extends runtime_1.SessionLauncher { constructor() { super('data/session/test-http-initiator.json', 'data/session/test-http-acceptor.json'); } makeFactory(config) { const isInitiator = this.isInitiator(config.description); return { makeSession: () => isInitiator ? new http_client_1.HttpClient(config) : new http_server_1.HttpServer(config) }; } waitFor(ms) { return __awaiter(this, void 0, void 0, function* () { const to = util.promisify(setTimeout); return new Promise((resolve, reject) => { to(ms).then(() => { resolve(null); }).catch(e => { reject(e); }); }); }); } getInitiator(sessionContainer) { var _a, _b; return __awaiter(this, void 0, void 0, function* () { const config = sessionContainer.resolve(runtime_1.DITokens.IJsFixConfig); const http = (_b = (_a = config === null || config === void 0 ? void 0 : config.description) === null || _a === void 0 ? void 0 : _a.application) === null || _b === void 0 ? void 0 : _b.http; if (http) { http.adapter = sessionContainer.resolve(runtime_1.DITokens.IHttpAdapter); const initiator = sessionContainer.resolve(runtime_1.DITokens.FixEntity); return this.waitFor(1000).then(() => __awaiter(this, void 0, void 0, function* () { return initiator.start(); })); } }); } } const l = new AppLauncher(); l.exec(); //# sourceMappingURL=app.js.map