Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions public/spotify-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ class SpotifyPlayer {
if (!this.obtainingToken) {
this.fetchPlayer()
.then(data => {
if (data !== null && data.item !== null) {
this.dispatch('update', data);
}
this.dispatch('update', data);
})
.catch(e => {
console.log('Logging user out due to error', e);
Expand Down Expand Up @@ -96,6 +94,11 @@ class SpotifyPlayer {

const width = 450, height = 730, left = screen.width / 2 - width / 2, top = screen.height / 2 - height / 2;

const eventOptions = {
once: true,
capture: false
};

window.addEventListener(
'message',
event => {
Expand All @@ -113,7 +116,7 @@ class SpotifyPlayer {
}
}
},
false
eventOptions
);

const w = window.open(
Expand Down Expand Up @@ -157,6 +160,17 @@ class SpotifyPlayer {
// assume an error on Spotify's site
console.error('Got error when fetching player', response);
return null;
} else if (response.status === 204) {
// No song playing, or account in private mode
return response.json()
.then(json => {
// Account in private mode, json = {}
return Promise.resolve(json);
})
.catch(err => {
// No song playing, empty response
return Promise.resolve(null);
});
} else {
return response.json();
}
Expand Down