check for auth error

This commit is contained in:
AJ ONeal 2016-09-30 15:14:12 -04:00
parent fdf5b46a9c
commit 2333ec30f6
1 changed files with 8 additions and 4 deletions

View File

@ -136,13 +136,9 @@ function run(copts) {
return Object.keys(localclients).length;
}
};
var wsHandlers = {
onOpen: function () {
console.info("[open] connected to '" + copts.stunneld + "'");
var machine = require('tunnel-packer').create(handlers);
wstunneler.on('message', machine.fns.addChunk);
}
, onClose: function () {
@ -185,11 +181,19 @@ function run(copts) {
}
}
};
var machine = require('tunnel-packer').create(handlers);
console.info("[connect] '" + copts.stunneld + "'");
wstunneler = new WebSocket(tunnelUrl, { rejectUnauthorized: !copts.insecure });
wstunneler.on('open', wsHandlers.onOpen);
wstunneler.on('message', function (data, flags) {
if (data.error || '{' === data[0]) {
console.log(data);
return;
}
machine.fns.addChunk(data, flags);
});
wstunneler.on('close', wsHandlers.onClose);
wstunneler.on('error', wsHandlers.onError);
process.on('exit', wsHandlers.onExit);