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.greenlockConf = state.config.greenlock || {};
|
||||||
state.sortingHat = state.config.sortingHat || path.resolve(__dirname, '..', 'lib/sorting-hat.js');
|
state.sortingHat = state.config.sortingHat;
|
||||||
|
|
||||||
// TODO sortingHat.print(); ?
|
// TODO sortingHat.print(); ?
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,9 @@ function _connect(state) {
|
||||||
// they can get a promise that will provide feedback about invalid tokens.
|
// they can get a promise that will provide feedback about invalid tokens.
|
||||||
var tokens = [];
|
var tokens = [];
|
||||||
var auth;
|
var auth;
|
||||||
|
if(!state.sortingHat) {
|
||||||
|
state.sortingHat = "./sorting-hat.js";
|
||||||
|
}
|
||||||
if (state.token) {
|
if (state.token) {
|
||||||
tokens.push(state.token);
|
tokens.push(state.token);
|
||||||
}
|
}
|
||||||
|
@ -30,6 +33,7 @@ function _connect(state) {
|
||||||
var wstunneler;
|
var wstunneler;
|
||||||
var authenticated = false;
|
var authenticated = false;
|
||||||
var authsent = false;
|
var authsent = false;
|
||||||
|
var initialConnect = true;
|
||||||
|
|
||||||
var localclients = {};
|
var localclients = {};
|
||||||
var pausedClients = [];
|
var pausedClients = [];
|
||||||
|
@ -401,6 +405,7 @@ function _connect(state) {
|
||||||
, onOpen: function () {
|
, onOpen: function () {
|
||||||
console.info("[open] connected to '" + (state.wss || state.relay) + "'");
|
console.info("[open] connected to '" + (state.wss || state.relay) + "'");
|
||||||
wsHandlers.refreshTimeout();
|
wsHandlers.refreshTimeout();
|
||||||
|
|
||||||
timeoutId = setTimeout(wsHandlers.checkTimeout, activityTimeout);
|
timeoutId = setTimeout(wsHandlers.checkTimeout, activityTimeout);
|
||||||
|
|
||||||
wstunneler._socket.on('drain', function () {
|
wstunneler._socket.on('drain', function () {
|
||||||
|
@ -422,10 +427,17 @@ function _connect(state) {
|
||||||
|
|
||||||
pausedClients.length = 0;
|
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 () {
|
, onClose: function () {
|
||||||
console.log('ON CLOSE');
|
|
||||||
clearTimeout(timeoutId);
|
clearTimeout(timeoutId);
|
||||||
wstunneler = null;
|
wstunneler = null;
|
||||||
clientHandlers.closeAll();
|
clientHandlers.closeAll();
|
||||||
|
@ -440,12 +452,26 @@ function _connect(state) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!authenticated) {
|
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.');
|
console.info('[close] failed on first attempt... check authentication.');
|
||||||
timeoutId = null;
|
timeoutId = null;
|
||||||
}
|
}
|
||||||
else if (tokens.length) {
|
else if (tokens.length) {
|
||||||
|
if(state.handlers.onDisconnect) {
|
||||||
|
state.handlers.onDisconnect();
|
||||||
|
}
|
||||||
console.info('[retry] disconnected and waiting...');
|
console.info('[retry] disconnected and waiting...');
|
||||||
timeoutId = setTimeout(connect, 5000);
|
timeoutId = setTimeout(connect, 5000);
|
||||||
|
} else {
|
||||||
|
if(state.handlers.onClose) {
|
||||||
|
state.handlers.onClose()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue