1
1
var exec = require ( 'child_process' ) . exec ,
2
2
fs = require ( 'fs' ) ,
3
3
http = require ( 'http' ) ,
4
- tunnelJar = __dirname + '/BrowserStackTunnel.jar ' ,
4
+ localBinary = __dirname + '/BrowserStackLocal ' ,
5
5
utils = require ( './utils' ) ,
6
6
config = require ( './config' ) ;
7
7
8
- var Tunnel = function Tunnel ( key , port , tunnelIdentifier , callback , err ) {
8
+ var Tunnel = function Tunnel ( key , port , uniqueIdentifier , callback , err ) {
9
9
var that = { } ;
10
10
11
11
function tunnelLauncher ( ) {
12
- var tunnelCommand = 'java -jar ' + tunnelJar + ' ' ;
12
+ var tunnelCommand = localBinary + ' ' ;
13
13
if ( config . debug )
14
14
tunnelCommand += ' -v ' ;
15
15
tunnelCommand += key + ' ' ;
16
16
tunnelCommand += 'localhost' + ',' ;
17
17
tunnelCommand += port . toString ( ) + ',' ;
18
18
tunnelCommand += '0' ;
19
- tunnelCommand += ( typeof tunnelIdentifier === 'undefined' ) ? ' -force -onlyAutomate' : ' -tunnelIdentifier ' + tunnelIdentifier ;
19
+ tunnelCommand += ( typeof uniqueIdentifier === 'undefined' ) ? ' -force -onlyAutomate' : ' -uniqueIdentifier ' + uniqueIdentifier ;
20
20
21
21
if ( typeof callback !== 'function' ) {
22
22
callback = function ( ) { } ;
23
23
}
24
24
25
- console . log ( "Launching tunnel" ) ;
25
+ console . log ( "[%s] Launching tunnel" , new Date ( ) ) ;
26
26
var subProcess = exec ( tunnelCommand , function ( error , stdout , stderr ) {
27
27
console . log ( stderr ) ;
28
+ console . log ( error ) ;
28
29
if ( stdout . indexOf ( 'Error' ) >= 0 ) {
29
- console . log ( "Tunnel launching failed" ) ;
30
+ console . log ( "[%s] Tunnel launching failed" , new Date ( ) ) ;
30
31
console . log ( stdout ) ;
31
32
process . exit ( 1 ) ;
32
33
}
@@ -38,8 +39,7 @@ var Tunnel = function Tunnel (key, port, tunnelIdentifier, callback, err) {
38
39
39
40
setTimeout ( function ( ) {
40
41
if ( ! running ) {
41
- utils . alertBrowserStack ( "Tunnel launch timeout" ,
42
- 'Stdout:\n' + data ) ;
42
+ utils . alertBrowserStack ( "Tunnel launch timeout" , 'Stdout:\n' + data ) ;
43
43
}
44
44
} , 30 * 1000 ) ;
45
45
@@ -52,27 +52,30 @@ var Tunnel = function Tunnel (key, port, tunnelIdentifier, callback, err) {
52
52
53
53
if ( data . indexOf ( runMatcher ) >= 0 ) {
54
54
running = true ;
55
- console . log ( "Tunnel launched" ) ;
55
+ console . log ( "[%s] Tunnel launched" , new Date ( ) ) ;
56
56
callback ( ) ;
57
57
}
58
58
} ) ;
59
59
60
60
that . process = subProcess ;
61
61
}
62
62
63
- fs . exists ( tunnelJar , function ( exists ) {
63
+ fs . exists ( localBinary , function ( exists ) {
64
64
if ( exists ) {
65
- fs . unlinkSync ( tunnelJar ) ;
65
+ fs . unlinkSync ( localBinary ) ;
66
+ // tunnelLauncher();
67
+ // return;
66
68
}
67
- console . log ( 'Downloading tunnel jar to `%s`' , tunnelJar ) ;
69
+ console . log ( 'Downloading BrowserStack Local to `%s`' , localBinary ) ;
68
70
69
- var file = fs . createWriteStream ( tunnelJar ) ;
71
+ var file = fs . createWriteStream ( localBinary ) ;
70
72
var request = http . get (
71
- "http://www.browserstack .com/BrowserStackTunnel.jar" ,
73
+ ( "http://s3.amazonaws .com/browserStack/browserstack-local/BrowserStackLocal-" + process . platform + "-" + process . arch ) ,
72
74
function ( response ) {
73
75
response . pipe ( file ) ;
74
76
75
77
response . on ( 'end' , function ( ) {
78
+ fs . chmodSync ( localBinary , 0700 ) ;
76
79
tunnelLauncher ( ) ;
77
80
} ) ;
78
81
}
0 commit comments