Screenshot server side optimised
This commit is contained in:
parent
3a3ff9215f
commit
9bc4cbd489
|
@ -198,7 +198,7 @@ var liveClickHandler = function(e) {
|
||||||
if (isLive) {
|
if (isLive) {
|
||||||
ws.send('{"type":"screenshot"}');
|
ws.send('{"type":"screenshot"}');
|
||||||
|
|
||||||
window.setTimeout(doScreenshot, 300);
|
window.setTimeout(doScreenshot, 100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -168,19 +168,26 @@ $server->addMessageHandler('text', function (ConnectionInterface $from, array $d
|
||||||
});
|
});
|
||||||
|
|
||||||
$server->addMessageHandler('screenshot', function (ConnectionInterface $from, array $data) use ($shell, $messageOutput) {
|
$server->addMessageHandler('screenshot', function (ConnectionInterface $from, array $data) use ($shell, $messageOutput) {
|
||||||
$tmpFilename = sprintf('%s/remote_i3wm_ws_screenshot.jpg', sys_get_temp_dir());
|
$tmpFilename = sprintf('%s/remote_i3wm_ws_screenshot.lock', sys_get_temp_dir());
|
||||||
$shell->exec('import -window root -quality 10 -display :0 %1$s && chmod 600 %1$s', $tmpFilename);
|
|
||||||
|
|
||||||
if (file_exists($tmpFilename)) {
|
if (file_exists($tmpFilename) && time() - filemtime($tmpFilename) < 10) {
|
||||||
$base64 = base64_encode(file_get_contents($tmpFilename));
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
touch($tmpFilename);
|
||||||
|
|
||||||
|
$content = $shell->exec('import -window root -quality 10 -display :0 jpeg:-');
|
||||||
|
|
||||||
|
if (!empty($content)) {
|
||||||
|
$base64 = base64_encode($content);
|
||||||
|
|
||||||
$from->send(json_encode([
|
$from->send(json_encode([
|
||||||
'type' => 'screenshot',
|
'type' => 'screenshot',
|
||||||
'value' => $base64,
|
'value' => $base64,
|
||||||
]));
|
]));
|
||||||
|
|
||||||
unlink($tmpFilename);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unlink($tmpFilename);
|
||||||
});
|
});
|
||||||
|
|
||||||
$server->addMessageHandler('messages', function (ConnectionInterface $from, array $data) use ($server) {
|
$server->addMessageHandler('messages', function (ConnectionInterface $from, array $data) use ($server) {
|
||||||
|
|
Loading…
Reference in a new issue