Skip to content

Commit

Permalink
thumb event polling now working properly
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Sep 29, 2010
1 parent d792335 commit 8f01810
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
33 changes: 17 additions & 16 deletions lib/models/process.js
@@ -1,4 +1,5 @@
var fs = require('fs');
var sys = require('sys');
var path = require('path');

var RemoteEmitter = require('dnode/events');
Expand Down Expand Up @@ -46,33 +47,33 @@ function Process (params) {
FB(self.address, self.engine, function (err, fb) {
if (err) throw err;

fb.encoder.on('end', function () {
self.emit('exit');
});
framebuffer = fb;
self.emit('ready');

var elapsed = 0;
var lastUpdate = 0;
function update () {
if (self.connections == 0) return;
if ((Date.now() - lastUpdate) / 1000 > 10) {
var hasUpdates = false;
var iv = setInterval((function f () {
if (hasUpdates && self.connections > 0) {
fb.encoder.requestRedraw();
hasUpdates = false;
}
lastUpdate = Date.now();
}
return f;
})(), 3000);

fb.encoder.on('raw', update);
fb.encoder.on('copyRect', update);
fb.encoder.on('end', function () {
clearInterval(iv);
self.emit('exit');
});

fb.encoder.on('screenUpdate', function (rect) {
if (rect.fullScreen && self.connections > 0) {
var file = thumbDir + '/' + self.address + '.png';
saveRect(file, rect);
console.log('emit!');
self.emit('thumb', rect.width, rect.height);
}
else {
hasUpdates = true;
}
});

framebuffer = fb;
self.emit('ready');
});
}, 500);

Expand Down
1 change: 0 additions & 1 deletion static/js/site.js
Expand Up @@ -31,7 +31,6 @@ function registerDisk (disk, filename) {
});

sub.on('thumb', function () {
console.log('caught thumb');
procElem.find('img').remove();
procElem.append(makeImg());
});
Expand Down

0 comments on commit 8f01810

Please sign in to comment.