Testing for ajax running refresh

This commit is contained in:
James Barnsley
2018-10-08 19:08:45 +13:00
parent 18cdcd4b7c
commit c844d09b78
4 changed files with 13950 additions and 10628 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -98,7 +98,7 @@
// Release details
// These are automatically injected to built HTML
var build = "1538878019";
var build = "1538940765";
var version = "3.27.2";
// Construct the script tag

View File

@ -105,15 +105,40 @@ function getToken(dispatch, getState){
}
// token is expiring/expired, so go get a new one and resolve that
refreshToken(dispatch, getState)
.then(
response => {
resolve(response.access_token)
},
error => {
reject(error)
}
);
// TODO: Detect whether we already have a pending refresh, in which case we
// need to wait until it's done, and then return that
// We've already got a refresh in progress
if (getState().ui.load_queue.spotify_refresh_token !== undefined){
console.log("Already loading!",getState().ui.load_queue.spotify_refresh_token)
// Re-check the queue periodically to see if it's finished yet
// TODO: Look at properly hooking up with the ajax finish event
setTimeout(
() => {
console.log("Running again")
// Return myself for a re-check
return getToken(dispatch, getState);
},
500
);
} else {
console.log("Not already refreshing token")
refreshToken(dispatch, getState)
.then(
response => {
resolve(response.access_token)
},
error => {
reject(error)
}
);
}
});
}