-
Notifications
You must be signed in to change notification settings - Fork 0
/
SpotifyLocalPlayer.js
41 lines (32 loc) · 1.19 KB
/
SpotifyLocalPlayer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { W } from './wget.js';
export class SpotifyLocalPlayer {
constructor(clientName, localStorage, spotify) {
this.ready = $.Deferred();
this.deviceId = null;
this.player = new Spotify.Player({
name: clientName,
getOAuthToken: cb => { cb(spotify.auth.getCurrentToken()); },
volume: localStorage.get("vol_" + clientName, 0.2),
});
this.player.addListener('ready', ({ device_id }) => {
this.device_id = device_id;
console.log('Ready local player, Device ID', this.device_id);
this.ready.resolve();
});
this.player.addListener('not_ready', ({ device_id }) => {
console.log('Device ID has gone offline', device_id);
});
this.player.addListener('initialization_error', ({ message }) => {
console.error(message);
});
this.player.addListener('authentication_error', ({ message }) => {
console.log("Auth token seems expired, will request new one");
spotify.requestReauth().then(this.player.connect);
});
this.player.addListener('account_error', ({ message }) => {
console.error(message);
});
this.player.connect();
console.log("Connecting local player ", clientName);
}
};