Browse Source

Screenshot server side optimised

develop
Simon Vieille 1 year ago
parent
commit
9bc4cbd489
No known key found for this signature in database
2 changed files with 14 additions and 7 deletions
  1. 1
    1
      client/assets/js/main.js
  2. 13
    6
      server/src/resource/server.php

+ 1
- 1
client/assets/js/main.js View File

@@ -198,7 +198,7 @@ var liveClickHandler = function(e) {
198 198
         if (isLive) {
199 199
             ws.send('{"type":"screenshot"}');
200 200
 
201
-            window.setTimeout(doScreenshot, 300);
201
+            window.setTimeout(doScreenshot, 100);
202 202
         }
203 203
     }
204 204
 

+ 13
- 6
server/src/resource/server.php View File

@@ -168,19 +168,26 @@ $server->addMessageHandler('text', function (ConnectionInterface $from, array $d
168 168
 });
169 169
 
170 170
 $server->addMessageHandler('screenshot', function (ConnectionInterface $from, array $data) use ($shell, $messageOutput) {
171
-    $tmpFilename = sprintf('%s/remote_i3wm_ws_screenshot.jpg', sys_get_temp_dir());
172
-    $shell->exec('import -window root -quality 10 -display :0 %1$s && chmod 600 %1$s', $tmpFilename);
171
+    $tmpFilename = sprintf('%s/remote_i3wm_ws_screenshot.lock', sys_get_temp_dir());
173 172
 
174
-    if (file_exists($tmpFilename)) {
175
-        $base64 = base64_encode(file_get_contents($tmpFilename));
173
+    if (file_exists($tmpFilename) && time() - filemtime($tmpFilename) < 10) {
174
+        return;
175
+    }
176
+
177
+    touch($tmpFilename);
178
+
179
+    $content = $shell->exec('import -window root -quality 10 -display :0 jpeg:-');
180
+
181
+    if (!empty($content)) {
182
+        $base64 = base64_encode($content);
176 183
 
177 184
         $from->send(json_encode([
178 185
             'type' => 'screenshot',
179 186
             'value' => $base64,
180 187
         ]));
181
-
182
-        unlink($tmpFilename);
183 188
     }
189
+
190
+    unlink($tmpFilename);
184 191
 });
185 192
 
186 193
 $server->addMessageHandler('messages', function (ConnectionInterface $from, array $data) use ($server) {

Loading…
Cancel
Save