blob: c34a6946eb3bd5ac027edcdca198ce00dd69c83c [file] [log] [blame]
var wire = require('../../wire');
var net = require('net');
function LayoutCaptureService() {
this.actionQueue = [];
}
LayoutCaptureService.prototype.enqueue = function(wireEvent, actionFn,
fetchView) {
this.actionQueue.push({
wireEvent: wireEvent,
actionFn: actionFn,
fetchView: fetchView
});
this.checkStartCaptures(wireEvent);
};
LayoutCaptureService.prototype.dequeue = function() {
if (this.actionQueue.length > 0) {
return this.actionQueue.shift();
} else {
return null;
}
};
LayoutCaptureService.prototype.checkStartCaptures = function() {
if (this.actionQueue.length > 0 && !this.processing) {
this.processing = true;
layoutCaptureService.processStr = '';
var nextItem = function() {
var eventActionObj = layoutCaptureService.dequeue();
if (eventActionObj) {
layoutCaptureService.processStr += ' (' +
eventActionObj.wireEvent.$code + ') ';
if (eventActionObj.wireEvent === wire.GestureStartMessage) {
eventActionObj.fetchView(function(err, layoutJSON) {
if (err) {
console.error(err);
} else {
eventActionObj.actionFn(layoutJSON);
nextItem();
}
});
} else {
eventActionObj.actionFn();
nextItem();
}
} else {
layoutCaptureService.processing = false;
}
};
nextItem();
}
};
var layoutCaptureService = new LayoutCaptureService();
module.exports = layoutCaptureService;