1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const child_process_1 = require("child_process");
|
4 | const q = require("q");
|
5 | const logger_1 = require("./logger");
|
6 | const BP_PATH = require.resolve('blocking-proxy/built/lib/bin.js');
|
7 | let logger = new logger_1.Logger('BlockingProxy');
|
8 | class BlockingProxyRunner {
|
9 | constructor(config) {
|
10 | this.config = config;
|
11 | }
|
12 | start() {
|
13 | return q.Promise((resolve, reject) => {
|
14 | this.checkSupportedConfig();
|
15 | let args = [
|
16 | '--fork',
|
17 | '--seleniumAddress',
|
18 | this.config.seleniumAddress,
|
19 | ];
|
20 | if (this.config.webDriverLogDir) {
|
21 | args.push('--logDir', this.config.webDriverLogDir);
|
22 | }
|
23 | if (this.config.highlightDelay) {
|
24 | args.push('--highlightDelay', this.config.highlightDelay.toString());
|
25 | }
|
26 | this.bpProcess = child_process_1.fork(BP_PATH, args, { silent: true });
|
27 | logger.info('Starting BlockingProxy with args: ' + args.toString());
|
28 | this.bpProcess
|
29 | .on('message', (data) => {
|
30 | this.port = data['port'];
|
31 | resolve(data['port']);
|
32 | })
|
33 | .on('error', (err) => {
|
34 | reject(new Error('Unable to start BlockingProxy ' + err));
|
35 | })
|
36 | .on('exit', (code, signal) => {
|
37 | reject(new Error('BP exited with ' + code));
|
38 | logger.error('Exited with ' + code);
|
39 | logger.error('signal ' + signal);
|
40 | });
|
41 | this.bpProcess.stdout.on('data', (msg) => {
|
42 | logger.debug(msg.toString().trim());
|
43 | });
|
44 | this.bpProcess.stderr.on('data', (msg) => {
|
45 | logger.error(msg.toString().trim());
|
46 | });
|
47 | process.on('exit', () => {
|
48 | this.bpProcess.kill();
|
49 | });
|
50 | });
|
51 | }
|
52 | checkSupportedConfig() {
|
53 | if (this.config.directConnect) {
|
54 | throw new Error('BlockingProxy not yet supported with directConnect!');
|
55 | }
|
56 | }
|
57 | }
|
58 | exports.BlockingProxyRunner = BlockingProxyRunner;
|
59 |
|
\ | No newline at end of file |