diff --git a/client/assets/css/main.css b/client/assets/css/main.css index b3bdd3c..3defe0d 100644 --- a/client/assets/css/main.css +++ b/client/assets/css/main.css @@ -101,3 +101,13 @@ a { #shortcuts_special_keys input { display: none; } + +#response { + position: absolute; + bottom: 0; + width: 100%; + color: #fff; + background: #748c26; + padding: 5px; + display: none; +} diff --git a/client/assets/js/main.js b/client/assets/js/main.js index 13c843a..5c97083 100644 --- a/client/assets/js/main.js +++ b/client/assets/js/main.js @@ -1,5 +1,5 @@ var ws; -var $pointer, $scroller; +var $pointer, $scroller, $response; var scrollLastTimestamp, scrollLastValue; var mousePosX, mousePosY, mouseInitPosX, mouseInitPosY; @@ -16,7 +16,18 @@ var createWebSocketConnection = function() { window.setTimeout(createWebSocketConnection, 5000); } - ws.onmessage = function(event) {} + ws.onmessage = function(event) { + var data = JSON.parse(event.data); + + if (data.type === 'response') { + $response.text(data.value); + $response.fadeIn(); + + window.setTimeout(function() { + $response.fadeOut(); + }, 2500); + } + } } var navigationClickHandler = function(e) { @@ -214,6 +225,7 @@ var bootstrap = function() { $(function() { $pointer = $('#pointer'); $scroller = $('#scrollbar'); + $response = $('#response'); bootstrap(); }); diff --git a/client/index.html b/client/index.html index 714a478..e432e5a 100644 --- a/client/index.html +++ b/client/index.html @@ -194,9 +194,11 @@
- You are not connected. Refresh + You are disconnected [Refresh]
+
+ diff --git a/server/server b/server/server index 7087ccc..d7acb77 100755 --- a/server/server +++ b/server/server @@ -75,13 +75,17 @@ $server->addMessageHandler('volume', function (ConnectionInterface $from, array if ($value === 'up') { $shell->exec('amixer set Master 2%%+'); + $from->send(json_encode(['type' => 'response', 'value' => 'Volume up'])); + $messageOutput->writeln('Volume up'); } elseif ($value === 'down') { $shell->exec('amixer set Master 2%%-'); + $from->send(json_encode(['type' => 'response', 'value' => 'Volume down'])); + $messageOutput->writeln('Volume down'); } else { $shell->exec('amixer set Master %d%%', (int) $value); + $from->send(json_encode(['type' => 'response', 'value' => sprintf('Volume set to %d%%', $value)])); + $messageOutput->writeln(sprintf('Volume set to %d%%', $value)); } - - $messageOutput->writeln('Volume modified'); }); $server->addMessageHandler('media', function (ConnectionInterface $from, array $data) use ($shell, $messageOutput) { @@ -97,7 +101,18 @@ $server->addMessageHandler('media', function (ConnectionInterface $from, array $ if (!empty($cmd)) { $shell->exec('playerctl -p spotify %s', $cmd); - $messageOutput->writeln('Spotify managed'); + + usleep(500000); + $status = trim($shell->exec('playerctl -p spotify status')); + + if ($status === 'Playing') { + $song = $shell->exec('playerctl -p spotify metadata xesam:title'); + $from->send(json_encode(['type' => 'response', 'value' => 'Playing: '.$song])); + $messageOutput->writeln('Spotify playing'); + } else { + $from->send(json_encode(['type' => 'response', 'value' => 'Paused'])); + $messageOutput->writeln('Spotify paused'); + } } });