Skip to content

Commit

Permalink
Accept absolute volume values
Browse files Browse the repository at this point in the history
  • Loading branch information
Miguel Jimenez Esun committed Apr 14, 2020
1 parent 1a0606e commit abb31d6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
12 changes: 9 additions & 3 deletions bin/service/index.js
Expand Up @@ -40,12 +40,18 @@ http
})
.listen(6090);

const config = cfg.read(path.join('REPLACELBPCONFIGDIR', 'data.cfg'));
let config = null;

for (let id = 0; id < +config.data['music-servers']; id++) {
try {
config = cfg.read(path.join('REPLACELBPCONFIGDIR', 'data.cfg'));
} catch (err) {
config = {data: {'music-servers': 1, 'music-server-1-zones': 4}};
}

for (let id = 1; id <= +config.data['music-servers']; id++) {
const server = new MusicServer({
zones: +config.data['music-server-' + id + '-zones'],
port: 6091 + id,
port: 6090 + id,
});

server.start();
Expand Down
26 changes: 15 additions & 11 deletions bin/service/music-server/index.js
Expand Up @@ -170,7 +170,7 @@ module.exports = class MusicServer {
case /(?:^|\/)audio\/\d+\/queueplus(?:\/|$)/.test(url):
return this._audioQueuePlus(url);

case /(?:^|\/)audio\/\d+\/volume\/[+-]\d+(?:\/|$)/.test(url):
case /(?:^|\/)audio\/\d+\/volume\/[+-]?\d+(?:\/|$)/.test(url):
return this._audioVolume(url);

default:
Expand All @@ -197,15 +197,15 @@ module.exports = class MusicServer {
upnplicences: 0,
usetrigger: false,
players: this._zones.map((zone, i) => ({
playerid: i + 1,
clienttype: 0,
default_volume: zone.getVolume(),
enabled: true,
internalname: 'zone-' + (i + 1),
max_volume: 100,
name: 'Zone ' + (i + 1),
upnpmode: 0,
upnppredelay: 0,
playerid: i + 1,
clienttype: 0,
default_volume: zone.getVolume(),
enabled: true,
internalname: 'zone-' + (i + 1),
max_volume: 100,
name: 'Zone ' + (i + 1),
upnpmode: 0,
upnppredelay: 0,
})),
},
]);
Expand Down Expand Up @@ -309,7 +309,11 @@ module.exports = class MusicServer {
const [, zoneId, , volume] = url.split('/');
const zone = this._zones[+zoneId - 1];

zone.setVolume(zone.getVolume() + +volume);
if (/^[+-]/.test(volume)) {
zone.setVolume(zone.getVolume() + +volume);
} else {
zone.setVolume(+volume);
}

return this._audioCfgGetPlayersDetails('audio/cfg/getplayersdetails');
}
Expand Down

0 comments on commit abb31d6

Please sign in to comment.