Merge branch 'v1' of ssh://git.coolaj86.com:22042/coolaj86/telebit.js into v1
This commit is contained in:
commit
a763ead434
|
@ -509,7 +509,7 @@ function connectTunnel() {
|
|||
};
|
||||
|
||||
state.greenlockConf = state.config.greenlock || {};
|
||||
state.sortingHat = state.config.sortingHat || path.resolve(__dirname, '..', 'lib/sorting-hat.js');
|
||||
state.sortingHat = state.config.sortingHat;
|
||||
|
||||
// TODO sortingHat.print(); ?
|
||||
|
||||
|
|
|
@ -23,6 +23,9 @@ function _connect(state) {
|
|||
// they can get a promise that will provide feedback about invalid tokens.
|
||||
var tokens = [];
|
||||
var auth;
|
||||
if(!state.sortingHat) {
|
||||
state.sortingHat = "./sorting-hat.js";
|
||||
}
|
||||
if (state.token) {
|
||||
tokens.push(state.token);
|
||||
}
|
||||
|
@ -30,6 +33,7 @@ function _connect(state) {
|
|||
var wstunneler;
|
||||
var authenticated = false;
|
||||
var authsent = false;
|
||||
var initialConnect = true;
|
||||
|
||||
var localclients = {};
|
||||
var pausedClients = [];
|
||||
|
@ -401,6 +405,7 @@ function _connect(state) {
|
|||
, onOpen: function () {
|
||||
console.info("[open] connected to '" + (state.wss || state.relay) + "'");
|
||||
wsHandlers.refreshTimeout();
|
||||
|
||||
timeoutId = setTimeout(wsHandlers.checkTimeout, activityTimeout);
|
||||
|
||||
wstunneler._socket.on('drain', function () {
|
||||
|
@ -422,10 +427,17 @@ function _connect(state) {
|
|||
|
||||
pausedClients.length = 0;
|
||||
});
|
||||
|
||||
//Call either Open or Reconnect handlers.
|
||||
if(state.handlers.onOpen && initialConnect) {
|
||||
state.handlers.onOpen();
|
||||
} else if (state.handlers.onReconnect && !initialConnect) {
|
||||
state.handlers.onReconnect();
|
||||
}
|
||||
initialConnect = false;
|
||||
}
|
||||
|
||||
, onClose: function () {
|
||||
console.log('ON CLOSE');
|
||||
clearTimeout(timeoutId);
|
||||
wstunneler = null;
|
||||
clientHandlers.closeAll();
|
||||
|
@ -440,12 +452,26 @@ function _connect(state) {
|
|||
}
|
||||
|
||||
if (!authenticated) {
|
||||
if(state.handlers.onError) {
|
||||
let err = new Error('Failed to connect on first attempt... check authentication');
|
||||
state.handlers.onError(err);
|
||||
}
|
||||
if(state.handlers.onClose) {
|
||||
state.handlers.onClose()
|
||||
}
|
||||
console.info('[close] failed on first attempt... check authentication.');
|
||||
timeoutId = null;
|
||||
}
|
||||
else if (tokens.length) {
|
||||
if(state.handlers.onDisconnect) {
|
||||
state.handlers.onDisconnect();
|
||||
}
|
||||
console.info('[retry] disconnected and waiting...');
|
||||
timeoutId = setTimeout(connect, 5000);
|
||||
} else {
|
||||
if(state.handlers.onClose) {
|
||||
state.handlers.onClose()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue