Skip to content
This repository was archived by the owner on Dec 13, 2023. It is now read-only.

Commit df891dc

Browse files
author
warner
committed
Merge things.
2 parents 342a87f + f92eb5b commit df891dc

File tree

4 files changed

+59
-20
lines changed

4 files changed

+59
-20
lines changed

api.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,17 @@ module.exports = function(username, authkey, test, dev){
134134
return callback(err, resp);
135135
})
136136
},
137+
isTunnelAlive: function(tunnelId, callback){
138+
makeApiCall(server, 'GET', 'tunnels/' + tunnelId, null, username, authkey, (err, resp) => {
139+
if (err) return callback(err)
140+
// console.log('we got: ' + util.inspect(resp))
141+
if (resp.active !== undefined){
142+
return callback(null, resp.active);
143+
} else {
144+
return callback(null, false)
145+
}
146+
})
147+
},
137148
checkTunnelIp: function(callback){
138149
makeApiCall(server, 'GET', 'tunnels/checkIp', null, username, authkey, (err, resp) => {
139150
// console.log('got resp for checkTunnelIp');

cbt_tunnels.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -640,9 +640,11 @@ function cbtSocket(api, params) {
640640
fs.unlink(self.ready, function(err){
641641
if(err){
642642
global.logger.error(err);
643-
setTimeout(function(){
644-
process.exit(1);
645-
},10000);
643+
if (!self.nokill){
644+
setTimeout(function(){
645+
process.exit(1);
646+
},10000);
647+
}
646648
}
647649
})
648650
}
@@ -652,18 +654,20 @@ function cbtSocket(api, params) {
652654
self.end(function(err, killit){
653655
if(!err && killit === 'killit'){
654656
global.logger.info('Local connection disconnected.');
657+
if(cb) cb(null,true)
655658
if(!self.nokill){
656659
global.logger.info('Bye!');
657-
if(cb) cb(null,true)
658660
process.exit(0);
659661
}
660662
if(cb) cb(null,true)
661663
}else if(err){
662664
global.logger.error(err);
663-
setTimeout(function(){
664-
if(cb) cb(err,false)
665-
process.exit(1);
666-
}, 10000);
665+
if(cb) cb(err,false)
666+
if(!self.nokill){
667+
setTimeout(function(){
668+
process.exit(1);
669+
}, 10000);
670+
}
667671
}
668672
});
669673
}
@@ -679,4 +683,4 @@ function cbtSocket(api, params) {
679683
}
680684
}
681685

682-
module.exports = cbtSocket;
686+
module.exports = cbtSocket;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cbt_tunnels",
3-
"version": "0.9.6",
3+
"version": "0.9.7",
44
"description": "Creates a local connection to CrossBrowserTesting.com which allows you to test sites behind your firewall or to access web pages that are saved locally on your machine. In just a few seconds, you can establish a connection which allows you to do live testing, screenshots, or run Selenium scripts against any of the internal sites you have access to. This command line version uses WSS (secure websockets over https, port 443) to create the local connection. It can be scripted, so it is useful if you want to initiate a local connection programmatically before running automated javascript, screenshots, or selenium tests.",
55
"dependencies": {
66
"cli-color": "1.1.0",

tunnel_start.js

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,13 @@ var startTunnel = function(api, params, cb){
159159
cbts.endWrap();
160160
}else{
161161
warn(err);
162-
setTimeout(function(){
163-
process.exit(1);
164-
},10000);
162+
if (!cbts.nokill){
163+
setTimeout(function(){
164+
process.exit(1);
165+
},10000);
166+
} else {
167+
throw err;
168+
}
165169
}
166170
})
167171
}
@@ -324,7 +328,15 @@ module.exports = {
324328
if (err){
325329
return cb(err)
326330
} else {
327-
var i = setInterval(()=>{}, 10000);
331+
var i = setInterval(()=>{
332+
// console.log(`checking if tunnel ${tunnelObject.tunnel_id} is still alive`)
333+
api.isTunnelAlive(tunnelObject.tunnel_id, (err, isAlive) =>{
334+
if (!isAlive){
335+
// console.log(`tunnel ${tunnelObject.tunnel_id} is dead!`)
336+
clearInterval(i)
337+
}
338+
})
339+
}, 10000);
328340
process.on('SIGINT',function(){
329341
// kill tunnel
330342
api.deleteTunnel(tunnelObject.tunnel_id, (err) => {
@@ -335,7 +347,10 @@ module.exports = {
335347
fs.unlinkSync(params.ready);
336348
}
337349
global.logger.info('killed connection manager tunnel, quitting')
338-
process.exit(0)
350+
clearInterval(i);
351+
if (!params.nokill){
352+
process.exit(0);
353+
}
339354
});
340355
global.logger.info('\nAttempting a graceful shutdown...');
341356
});
@@ -351,7 +366,10 @@ module.exports = {
351366
fs.unlinkSync(params.ready);
352367
}
353368
global.logger.info('killed connection manager tunnel, quitting')
354-
process.exit(0)
369+
clearInterval(i);
370+
if (!params.nokill){
371+
process.exit(0)
372+
}
355373
});
356374
});
357375
if(params.ready){
@@ -383,13 +401,19 @@ module.exports = {
383401
fs.unlinkSync(params.ready);
384402
}
385403
global.logger.info('killed connection manager tunnel, quitting')
386-
process.exit(0)
404+
clearInterval(i);
405+
if (!params.nokill){
406+
process.exit(0);
407+
}
387408
});
388409
}else{
389410
warn(err);
390-
setTimeout(function(){
391-
process.exit(1);
392-
},10000);
411+
clearInterval(i);
412+
if (!params.nokill){
413+
setTimeout(function(){
414+
process.exit(1);
415+
},10000);
416+
}
393417
}
394418
})
395419
}

0 commit comments

Comments
 (0)