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