lots of debugging

This commit is contained in:
AJ ONeal 2018-07-07 18:46:45 -06:00
parent 96424aad4b
commit da31c0154f
1 changed files with 16 additions and 14 deletions

View File

@ -157,17 +157,17 @@ common.api.token = function (state, handlers) {
common.api.directory(state, function (err, dir) {
// directory, requested, connect, tunnelUrl, offer, granted, end
function afterDir() {
//console.log('[debug] after dir');
console.log('[debug] after dir');
state.wss = common.api._parseWss(state, dir);
handlers.tunnelUrl(state.wss, function () {
//console.log('[debug] after tunnelUrl');
console.log('[debug] after tunnelUrl');
if (state.config.secret /* && !state.config.token */) {
state.config._token = common.signToken(state);
}
state.token = state.token || state.config.token || state.config._token;
if (state.token) {
//console.log('[debug] token via token or secret');
console.log('[debug] token via token or secret');
// { token, pretoken }
handlers.connect(state.token, function () {
handlers.end(null, function () {});
@ -177,7 +177,7 @@ common.api.token = function (state, handlers) {
// backwards compat (TODO remove)
if (err || !dir || !dir.pair_request) {
//console.log('[debug] no dir, connect');
console.log('[debug] no dir, connect');
handlers.error(new Error("No token found or generated, and no pair_request api found."));
return;
}
@ -209,10 +209,11 @@ common.api.token = function (state, handlers) {
var firstReady = true;
function gotoNext(req) {
//console.log('[debug] gotoNext called');
console.log('[debug] gotoNext called');
console.log(req);
urequest(req, function (err, resp, body) {
if (err) {
//console.log('[debug] gotoNext error');
console.log('[debug] gotoNext error');
err._request = req;
err._hint = '[telebitd.js] pair request';
handlers.error(err, function () {});
@ -220,18 +221,19 @@ common.api.token = function (state, handlers) {
}
function checkLocation() {
//console.log('[debug] checkLocation');
console.log('[debug] checkLocation');
console.log(body);
// pending, try again
if ('pending' === body.status && resp.headers.location) {
//console.log('[debug] pending');
console.log('[debug] pending');
setTimeout(gotoNext, 2 * 1000, { url: resp.headers.location, json: true });
return;
}
if ('ready' === body.status) {
//console.log('[debug] ready');
console.log('[debug] ready');
if (firstReady) {
//console.log('[debug] first ready');
console.log('[debug] first ready');
firstReady = false;
state.token = body.access_token;
state.config.token = state.token;
@ -244,21 +246,21 @@ common.api.token = function (state, handlers) {
}
if ('complete' === body.status) {
//console.log('[debug] complete');
console.log('[debug] complete');
handlers.granted(null, function () {
handlers.end(null, function () {});
});
return;
}
//console.log('[debug] bad status');
console.log('[debug] bad status');
var err = new Error("Bad State:" + body.status);
err._request = req;
handlers.error(err, function () {});
}
if (firstReq) {
//console.log('[debug] first req');
console.log('[debug] first req');
handlers.requested(authReq, function () {
handlers.connect(body.access_token || body.jwt, function () {
var err;
@ -274,7 +276,7 @@ common.api.token = function (state, handlers) {
firstReq = false;
return;
} else {
//console.log('[debug] other req');
console.log('[debug] other req');
checkLocation();
}
});