UNPKG

intern

Version:

Intern. A next-generation code testing stack for JavaScript.

56 lines 2.31 kB
(function (factory) { if (typeof module === "object" && typeof module.exports === "object") { var v = factory(require, exports); if (v !== undefined) module.exports = v; } else if (typeof define === "function" && define.amd) { define(["require", "exports", "tslib", "./channels/WebSocket", "./channels/Http"], factory); } })(function (require, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var WebSocket_1 = tslib_1.__importDefault(require("./channels/WebSocket")); var Http_1 = tslib_1.__importDefault(require("./channels/Http")); var Channel = (function () { function Channel(options) { this.options = options; } Channel.prototype.sendMessage = function (name, data) { var _this = this; return this._initialize().then(function () { return _this._channel.sendMessage(name, data); }); }; Channel.prototype._initialize = function () { var _this = this; if (!this._initialized) { this._initialized = new Promise(function (resolve) { if (_this.options.port) { try { _this._channel = new WebSocket_1.default(_this.options); _this._channel.sendMessage('remoteStatus', 'ping').then(function () { resolve(); }, function (_error) { _this._channel = new Http_1.default(_this.options); resolve(); }); } catch (error) { _this._channel = new Http_1.default(_this.options); resolve(); } } else { _this._channel = new Http_1.default(_this.options); resolve(); } }); } return this._initialized; }; return Channel; }()); exports.default = Channel; }); //# sourceMappingURL=Channel.js.map