From 614f9c09969a4eb6c1f03ef6e75ecdb2949e5103 Mon Sep 17 00:00:00 2001 From: CoderRing28 <12738461+CoderRing28@users.noreply.github.com> Date: Tue, 23 Jun 2020 18:24:13 -0500 Subject: [PATCH] Add current volume indications --- eventcmd.sh | 6 +++++- index.js | 28 ++++++++++++++++++++++++++++ views/css/main.css | 13 +++++++++++++ views/index.html | 2 ++ views/js/main.js | 13 +++++++++++++ 5 files changed, 61 insertions(+), 1 deletion(-) diff --git a/eventcmd.sh b/eventcmd.sh index a444820..278dd32 100755 --- a/eventcmd.sh +++ b/eventcmd.sh @@ -15,7 +15,7 @@ while read L; do k="`echo "$L" | cut -d '=' -f 1`" v="`echo "$L" | cut -d '=' -f 2`" export "$k=$v" -done < <(grep -e '^\(title\|artist\|album\|stationName\|songStationName\|pRet\|pRetStr\|wRet\|wRetStr\|songDuration\|songPlayed\|rating\|coverArt\|stationCount\|station[0-9]*\)=' /dev/stdin) # don't overwrite $1... +done < <(grep -e '^\(title\|artist\|album\|stationName\|songStationName\|pRet\|pRetStr\|wRet\|wRetStr\|songDuration\|songPlayed\|rating\|coverArt\|stationCount\|volume\|station[0-9]*\)=' /dev/stdin) # don't overwrite $1... @@ -56,6 +56,10 @@ case "$1" in stationList ;; + volchange) + query="/volumechange/?volume=${volume}" + clean $query + ;; # songfinish) # ;; diff --git a/index.js b/index.js index dfcc15e..6d7e890 100644 --- a/index.js +++ b/index.js @@ -12,6 +12,25 @@ server.listen(listenPort); // Routing app.use(express.static(__dirname + '/views')); +function readVolume() { + var currentVol = fs.readFileSync(process.env.HOME + '/.config/pianobar/state').toString() + + if(currentVol){ + var v = currentVol.split('\n'); + var i; + var actualVolume; + for (i=0; i < v.length; i++){ + var vol = v[i].split('='); + if(vol[0].trim() == 'volume'){ + actualVolume = vol[1] + break; + } else { + continue; + } + } + io.emit('volume', {volume: actualVolume}); + } +} function readCurrentSong() { var currentSong = fs.readFileSync(process.env.HOME + '/.config/pianobar/currentSong').toString() @@ -64,6 +83,7 @@ io.on('connection', function(socket) { console.log('a user connected'); readCurrentSong(); readStations(); + readVolume(); socket.on('action', function (data) { var action = data.action.substring(0, 1) @@ -99,5 +119,13 @@ app.post('/lovehate', function(request, response) { console.log(request.query); }); +app.post('/volumechange', function(request, response) { + newvolume = request.query.volume; + + io.emit('newvolume', { volume: newvolume }); + + response.send(request.query); + +}); }); diff --git a/views/css/main.css b/views/css/main.css index f20f620..f13bf16 100644 --- a/views/css/main.css +++ b/views/css/main.css @@ -22,6 +22,19 @@ body { font-size:110%; } +#currentVol { + color: orange; + font-style: italic; + font-size:90%; +} + +#resetVol{ + color: orange; + font-style: italic; + font-size:55%; + cursor: pointer; +} + #player { background-color: #222; border-radius:3px; diff --git a/views/index.html b/views/index.html index cedd45e..bd14c5e 100644 --- a/views/index.html +++ b/views/index.html @@ -35,6 +35,7 @@
{{title}}
{{albumartist}}
+Volume:
RESET
diff --git a/views/js/main.js b/views/js/main.js index 7481a49..35343a5 100644 --- a/views/js/main.js +++ b/views/js/main.js @@ -68,6 +68,16 @@ function SongController($scope, socket) { } }); + socket.on('volume', function(msg) { + var vol = msg.volume; + document.getElementById("currentVol").innerHTML = vol; + }); + + socket.on('newvolume', function(msg) { + var vol = msg.volume; + document.getElementById("currentVol").innerHTML = vol; + }); + $scope.sendCommand = function(action) { socket.emit('action', { action: action }); } @@ -76,6 +86,9 @@ function SongController($scope, socket) { $(this).children().toggleClass('glyphicon-pause glyphicon-play'); }); + $("#resetVol").click(function() { + socket.emit('action', { action: '^'}); + }); socket.on('lovehate', function(msg) { if (msg.rating == 1) { document.getElementById("love").className = "btn btn-success pull-left";