Skip to content

Commit

Permalink
feat: add SpotifyPlayer class
Browse files Browse the repository at this point in the history
  • Loading branch information
Symbitic committed May 22, 2021
0 parents commit 555161f
Show file tree
Hide file tree
Showing 14 changed files with 5,318 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
21 changes: 21 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---

extends:
- eslint:recommended
- plugin:@typescript-eslint/recommended
- plugin:import/typescript

parser: "@typescript-eslint/parser"

env:
browser: true
jest: true

plugins:
- "@typescript-eslint/eslint-plugin"

rules:
"@typescript-eslint/ban-ts-comment": off
"@typescript-eslint/explicit-module-boundary-types": off
"@typescript-eslint/no-explicit-any": off
"@typescript-eslint/no-inferrable-types": off
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
tmp/
node_modules/
dist/
docs/
23 changes: 23 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# MIT License

Copyright (c) 2021, Alex Shaw
Copyright (c) 2019, Gil Barbara

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
55 changes: 55 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Spotify Web Player

Spotify Web Player is a TypeScript-enabled API for using the Spotify Web Playback SDK.

The Spotify Web Playback SDK enables developers to stream and play Spotify tracks
in any web browser that supports [Encrypted Media Extensions](https://www.w3.org/TR/encrypted-media/)
(currently only FireFox, Google Chrome, and Microsoft Edge are supported).

See the [Web Playback SDK Quick Start](https://developer.spotify.com/documentation/web-playback-sdk/quick-start/) for a quick introduction to the Web Playback SDK, and the [Web Playback SDK Reference](https://developer.spotify.com/documentation/web-playback-sdk/reference/) for a more complete API reference.

## Setup

```bash
npm i -s spotify-web-player
```

or

```bash
yarn add spotify-web-player
```

## Getting Started

```javascript
const token = 'SPOTIFY_TOKEN';

const uri = 'spotify:album:51QBkcL7S3KYdXSSA0zM9R';

const spotify = new SpotifyPlayer();

await spotify.connect(token);

spotify.play(uri);
```

# Authorization

**This library does not handle obtaining a Spotify token. You have to take care of that yourself.**

You have two options:

1. Click [here] to obtain a temporary token. You can pass it to your code, but be aware it will expire after one hour.
2. Use the Spotify Web API to obtain an access token. See [this gist] for a full example of how to obtain a Spotify token in a web application. This workflow is highly recommended for production apps.

## Acknowledgements

Much of the inspiration for this API comes from Gil Barbara's [react-spotify-web-playback](https://github.com/gilbarbara/react-spotify-web-playback).

## License

Licensed under the [MIT](https://spdx.org/licenses/MIT) license. See [LICENSE.md](LICENSE.md) for more details.

[here]: https://accounts.spotify.com/en/authorize?response_type=token&client_id=adaaf209fb064dfab873a71817029e0d&redirect_uri=https:%2F%2Fdeveloper.spotify.com%2Fdocumentation%2Fweb-playback-sdk%2Fquick-start%2F&scope=streaming%20user-read-email%20user-read-private%20user-library-read%20user-library-modify%20user-read-playback-state%20user-modify-playback-state&show_dialog=true
[this gist]: https://gist.github.com/Symbitic/95c0f4321b310be3a86eb0adf4a268ff
7 changes: 7 additions & 0 deletions babel.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function () {
return {
presets: [
'@babel/typescript'
]
};
}
Loading

0 comments on commit 555161f

Please sign in to comment.