From da31c0154f48fdb4c74a02e2aa4b095611a8b652 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Sat, 7 Jul 2018 18:46:45 -0600 Subject: [PATCH] lots of debugging --- lib/cli-common.js | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/lib/cli-common.js b/lib/cli-common.js index 72424ee..f413fe5 100644 --- a/lib/cli-common.js +++ b/lib/cli-common.js @@ -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(); } });