1 | "use strict";
|
2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3 | return new (P || (P = Promise))(function (resolve, reject) {
|
4 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
5 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
6 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
7 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
8 | });
|
9 | };
|
10 | Object.defineProperty(exports, "__esModule", { value: true });
|
11 | const util_1 = require("util");
|
12 |
|
13 | const launchSauceConnect = util_1.promisify(require('sauce-connect-launcher'));
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | function SauceConnect(emitter, logger) {
|
19 | const log = logger.create('launcher.SauceConnect');
|
20 |
|
21 |
|
22 | let activeInstancePromise = null;
|
23 | this.establishTunnel = (connectOptions) => __awaiter(this, void 0, void 0, function* () {
|
24 |
|
25 | connectOptions.logger = log.debug.bind(log);
|
26 |
|
27 |
|
28 |
|
29 | if (activeInstancePromise) {
|
30 | return activeInstancePromise;
|
31 | }
|
32 |
|
33 | return activeInstancePromise = launchSauceConnect(connectOptions);
|
34 | });
|
35 |
|
36 |
|
37 | emitter.on('exit', (doneFn) => {
|
38 | if (activeInstancePromise) {
|
39 | log.debug('Shutting down Sauce Connect');
|
40 |
|
41 | activeInstancePromise
|
42 | .then(instance => instance.close(doneFn()))
|
43 | .catch(() => doneFn());
|
44 | }
|
45 | else {
|
46 | doneFn();
|
47 | }
|
48 | });
|
49 | }
|
50 | exports.SauceConnect = SauceConnect;
|
51 |
|
\ | No newline at end of file |