11var https = require ( 'https' ) ,
2+ url = require ( 'url' ) ,
23 fs = require ( 'fs' ) ,
34 path = require ( 'path' ) ,
45 os = require ( 'os' ) ,
6+ HttpsProxyAgent = require ( 'https-proxy-agent' ) ,
57 LocalError = require ( './LocalError' ) ;
68
79function LocalBinary ( ) {
@@ -20,15 +22,23 @@ function LocalBinary(){
2022 this . httpPath = 'https://s3.amazonaws.com/browserStack/browserstack-local/BrowserStackLocal-linux-ia32' ;
2123 }
2224
23- this . download = function ( destParentDir , callback ) {
25+ this . download = function ( conf , destParentDir , callback ) {
2426 if ( ! this . checkPath ( destParentDir ) )
2527 fs . mkdirSync ( destParentDir ) ;
2628
2729 var destBinaryName = ( this . windows ) ? 'BrowserStackLocal.exe' : 'BrowserStackLocal' ;
2830 var binaryPath = path . join ( destParentDir , destBinaryName ) ;
2931 var file = fs . createWriteStream ( binaryPath ) ;
3032
31- https . get ( this . httpPath , function ( response ) {
33+ var options = url . parse ( this . httpPath ) ;
34+ if ( conf . proxyHost && conf . proxyPort ) {
35+ options . agent = new HttpsProxyAgent ( {
36+ host : conf . proxyHost ,
37+ port : conf . proxyPort
38+ } ) ;
39+ }
40+
41+ https . get ( options , function ( response ) {
3242 response . on ( 'end' , function ( ) {
3343 fs . chmod ( binaryPath , '0755' , function ( ) {
3444 callback ( binaryPath ) ;
@@ -38,14 +48,14 @@ function LocalBinary(){
3848 } ) ;
3949 } ;
4050
41- this . binaryPath = function ( callback ) {
51+ this . binaryPath = function ( conf , callback ) {
4252 var destParentDir = this . getAvailableDirs ( ) ;
4353 var destBinaryName = ( this . windows ) ? 'BrowserStackLocal.exe' : 'BrowserStackLocal' ;
4454 var binaryPath = path . join ( destParentDir , destBinaryName ) ;
4555 if ( this . checkPath ( binaryPath , fs . X_OK ) ) {
4656 callback ( binaryPath ) ;
4757 } else {
48- this . download ( destParentDir , callback ) ;
58+ this . download ( conf , destParentDir , callback ) ;
4959 }
5060 } ;
5161
0 commit comments