Skip to content

Commit

Permalink
little fixes after refactoring. Nothing important
Browse files Browse the repository at this point in the history
  • Loading branch information
Emmanuel LEGROS authored and Emmanuel LEGROS committed Feb 18, 2018
1 parent c782ddf commit 2836043
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 60 deletions.
3 changes: 2 additions & 1 deletion .gitignore
@@ -1,2 +1,3 @@
/node_modules
/src/api/token.js
/src/api/token.js
/package-lock.json
7 changes: 1 addition & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "rest-api-squeezebox",
"version": "0.0.1",
"version": "1.1.0",
"description": "This REST API is a translation of the slimserver / squeezebox server JSON RPC API.",
"repository": {
"type": "git",
Expand All @@ -13,7 +13,6 @@
"license": "Apache-2.0",
"dependencies": {
"express": "^4.16.2",
"q": "^1.5.1",
"request": "^2.83.0"
}
}
9 changes: 9 additions & 0 deletions src/integration/Mixer.js
Expand Up @@ -39,4 +39,13 @@ module.exports = class Mixer {
await SlimHelper.sendRequest([this.player.id, ['mixer', 'treble', this.treble]]);
}

toAPI() {
return {
power: this.power,
volume: this.volume,
bass: this.bass,
treble: this.treble
};
}

}
83 changes: 32 additions & 51 deletions src/integration/Player.js
Expand Up @@ -14,46 +14,41 @@ module.exports = class Player {
// After that, we can get the data.
async init() {

try {

const resultNbPlayers = await SlimHelper.sendRequest(['-', ['player', 'count', '?']]);
const resultNbPlayers = await SlimHelper.sendRequest(['-', ['player', 'count', '?']]);

const resultPlayers = await SlimHelper.sendRequest(['-', ['players', '0', resultNbPlayers._count]]);
const resultPlayers = await SlimHelper.sendRequest(['-', ['players', '0', resultNbPlayers._count]]);

let player = null;
for (let it = 0; it < resultPlayers.players_loop.length && player === null; it++) {
if (resultPlayers.players_loop[it].uuid === this.uuid) {
player = resultPlayers.players_loop[it];
}
}

if (player === null) {
let error = {
codeHttp: 404,
message: "player nont found on Player.init() " + this.uuid
};
throw error;
} else {
this.name = player.name;
this.id = player.playerid;
this.ip = player.ip;
this.model = player.modelname;
this.firmwareVersion = player.firmware;

this.mixer = new Mixer(this);
this.songPlayed = new SongPlayed(this);
const data = await Promise.all([
SlimHelper.sendRequest([this.id, ['signalstrength', '?']]),
SlimHelper.sendRequest([this.id, ['mode', '?']]),
this.mixer.init(),
this.songPlayed.init()
]);
this.signalStrength = data[0]._signalstrength;
this.playState = data[1]._mode;
let player = null;
for (let it = 0; it < resultPlayers.players_loop.length && player === null; it++) {
if (resultPlayers.players_loop[it].uuid === this.uuid) {
player = resultPlayers.players_loop[it];
}
}

} catch (error) {
console.log("Error on Player.init() for the uuid " + this.uuid + " " + error);
if (player === null) {
let error = {
codeHTTP: 404,
message: "player not found on Player.init() " + this.uuid
};
throw error;
} else {
this.name = player.name;
this.id = player.playerid;
this.ip = player.ip;
this.model = player.modelname;
this.firmwareVersion = player.firmware;

this.mixer = new Mixer(this);
this.songPlayed = new SongPlayed(this);
const data = await Promise.all([
SlimHelper.sendRequest([this.id, ['signalstrength', '?']]),
SlimHelper.sendRequest([this.id, ['mode', '?']]),
this.mixer.init(),
this.songPlayed.init()
]);
this.signalStrength = data[0]._signalstrength;
this.playState = data[1]._mode;
}

}
Expand Down Expand Up @@ -104,22 +99,8 @@ module.exports = class Player {
firmware_version: this.firmwareVersion,
signal_strength: this.signalStrength,
play_state: this.playState,
mixer: {
power: this.mixer.power,
volume: this.mixer.volume,
bass: this.mixer.bass,
treble: this.mixer.treble
},
song_currently_played: {
index_in_playlist: this.songPlayed.indexInPlaylist,
seconds_played: this.songPlayed.secondsPlayed,
duration: this.songPlayed.duration,
artist: this.songPlayed.artist,
album: this.songPlayed.album,
title: this.songPlayed.title,
is_remote: this.songPlayed.isRemote,
path: this.songPlayed.path
}
mixer: this.mixer.toAPI(),
song_currently_played: this.songPlayed.toAPI()
};
}

Expand Down
13 changes: 13 additions & 0 deletions src/integration/SongPlayed.js
Expand Up @@ -42,4 +42,17 @@ module.exports = class SongPlayed {
}
}

toAPI() {
return {
index_in_playlist: this.indexInPlaylist,
seconds_played: this.secondsPlayed,
duration: this.duration,
artist: this.artist,
album: this.album,
title: this.title,
is_remote: this.isRemote,
path: this.path
};
}

}

0 comments on commit 2836043

Please sign in to comment.