Skip to content

Commit

Permalink
Add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Niklas Fondberg committed Mar 5, 2019
1 parent b56e541 commit 9339045
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Choose an online media player and click on a playlist to play it on the device.
This component will query the current playback
The component used the [Spotify Web API](https://developer.spotify.com/documentation/web-api/).

![Screenshot](/spotify-card-highlight.png)

### Requirements
As I wanted to create a vanilla javascript []Web Component](https://developer.mozilla.org/en-US/docs/Web/Web_Components) the code is not transpiled and might not work in your browser.
If this is the case either create a fix and post a PR or upgrade to a more modern browser.
Expand Down
Binary file removed src/Spotify_Logo_RGB_White.png
Binary file not shown.
7 changes: 0 additions & 7 deletions src/speaker.svg

This file was deleted.

9 changes: 7 additions & 2 deletions src/spotify-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class SpotifyCard extends Component {
async componentDidMount() {
const hashParams = new URLSearchParams(window.location.hash.substring(1));
const access_token = hashParams.get('access_token') || localStorage.getItem('access_token');
const token_expires_ms = localStorage.getItem('token_expires_ms');

const headers = {
'Authorization': `Bearer ${access_token}`
Expand All @@ -85,11 +86,15 @@ class SpotifyCard extends Component {

this.setState({ authenticationRequired: false });

localStorage.setItem('access_token', access_token);
if(hashParams.get('access_token')) {
const expires_in = hashParams.get('expires_in');
localStorage.setItem('access_token', access_token);
localStorage.setItem('token_expires_ms', new Date().getTime() + (expires_in * 1000));

// Auth success, remove the parameters from spotify
const newurl = window.location.href.split('#')[0];
window.history.pushState({path:newurl}, '', newurl);
// TODO: request refresh token option 4 in https://developer.spotify.com/documentation/general/guides/authorization-guide/
}


Expand All @@ -110,7 +115,7 @@ class SpotifyCard extends Component {
authenticateSpotify() {
const redirectUrl = window.location.href.split('?')[0];
const { clientId } = this.props;
window.location.href = `https://accounts.spotify.com/sv/authorize?client_id=${clientId}&redirect_uri=${redirectUrl}&scope=${this.scopes.join('%20')}&response_type=token`;
window.location.href = `https://accounts.spotify.com/authorize?client_id=${clientId}&redirect_uri=${redirectUrl}&scope=${this.scopes.join('%20')}&response_type=token`;
}

playPlaylist() {
Expand Down

0 comments on commit 9339045

Please sign in to comment.