Screenshot server side optimised
This commit is contained in:
джерело
3a3ff9215f
коміт
9bc4cbd489
|
@ -198,7 +198,7 @@ var liveClickHandler = function(e) {
|
|||
if (isLive) {
|
||||
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) {
|
||||
$tmpFilename = sprintf('%s/remote_i3wm_ws_screenshot.jpg', sys_get_temp_dir());
|
||||
$shell->exec('import -window root -quality 10 -display :0 %1$s && chmod 600 %1$s', $tmpFilename);
|
||||
$tmpFilename = sprintf('%s/remote_i3wm_ws_screenshot.lock', sys_get_temp_dir());
|
||||
|
||||
if (file_exists($tmpFilename)) {
|
||||
$base64 = base64_encode(file_get_contents($tmpFilename));
|
||||
if (file_exists($tmpFilename) && time() - filemtime($tmpFilename) < 10) {
|
||||
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([
|
||||
'type' => 'screenshot',
|
||||
'value' => $base64,
|
||||
]));
|
||||
|
||||
unlink($tmpFilename);
|
||||
}
|
||||
|
||||
unlink($tmpFilename);
|
||||
});
|
||||
|
||||
$server->addMessageHandler('messages', function (ConnectionInterface $from, array $data) use ($server) {
|
||||
|
|
Завантаження…
Посилання в новій задачі