Handling new api structure with client-triggered broadcasts

This commit is contained in:
James Barnsley
2018-03-20 13:02:38 +13:00
parent 2cde9fa786
commit 8549e9db85
10 changed files with 160 additions and 95 deletions

View File

@ -162,16 +162,27 @@ function refreshToken(dispatch, getState){
$.ajax(config)
.then(
response => {
var token = response.spotify_token;
token.token_expiry = new Date().getTime() + (token.expires_in * 1000 );
token.source = 'mopidy';
dispatch({
type: 'SPOTIFY_TOKEN_REFRESHED',
access_token_provider: 'backend',
data: token
});
resolve(token);
(response, status, xhr) => {
if (response.error){
dispatch({ type: 'SPOTIFY_DISCONNECTED' })
reject({
config: config,
xhr: xhr,
status: status,
error: response.error
});
} else {
var token = response.result.spotify_token;
token.token_expiry = new Date().getTime() + (token.expires_in * 1000 );
token.source = 'mopidy';
dispatch({
type: 'SPOTIFY_TOKEN_REFRESHED',
access_token_provider: 'backend',
data: token
});
resolve(token);
}
},
(xhr, status, error) => {