Send information from the server to the client
This commit is contained in:
parent
48cae17ecc
commit
4aa61beefb
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
|
|
|
@ -194,9 +194,11 @@
|
|||
</div>
|
||||
|
||||
<div id="disconneced">
|
||||
You are not connected. <a href="#" onclick="location.reload(); return false;">Refresh</a>
|
||||
You are disconnected [<a href="#" onclick="location.reload(); return false;">Refresh</a>]
|
||||
</div>
|
||||
|
||||
<div id="response"></div>
|
||||
|
||||
<script src="vendor/components/jquery/jquery.min.js"></script>
|
||||
<script src="vendor/twbs/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="vendor/twbs/bootstrap/dist/js/bootstrap.min.js"></script>
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue