node-red-contrib-leap-motion
Version:
Node-Red nodes for leap motion
53 lines (46 loc) • 1.65 kB
JavaScript
var Pipeline = module.exports = function (controller) {
this.steps = [];
this.controller = controller;
}
Pipeline.prototype.addStep = function (step) {
this.steps.push(step);
}
Pipeline.prototype.run = function (frame) {
var stepsLength = this.steps.length;
for (var i = 0; i != stepsLength; i++) {
if (!frame) break;
frame = this.steps[i](frame);
}
return frame;
}
Pipeline.prototype.removeStep = function(step){
var index = this.steps.indexOf(step);
if (index === -1) throw "Step not found in pipeline";
this.steps.splice(index, 1);
}
/*
* Wraps a plugin callback method in method which can be run inside the pipeline.
* This wrapper method loops the callback over objects within the frame as is appropriate,
* calling the callback for each in turn.
*
* @method createStepFunction
* @memberOf Leap.Controller.prototype
* @param {Controller} The controller on which the callback is called.
* @param {String} type What frame object the callback is run for and receives.
* Can be one of 'frame', 'finger', 'hand', 'pointable', 'tool'
* @param {function} callback The method which will be run inside the pipeline loop. Receives one argument, such as a hand.
* @private
*/
Pipeline.prototype.addWrappedStep = function (type, callback) {
var controller = this.controller,
step = function (frame) {
var dependencies, i, len;
dependencies = (type == 'frame') ? [frame] : (frame[type + 's'] || []);
for (i = 0, len = dependencies.length; i < len; i++) {
callback.call(controller, dependencies[i]);
}
return frame;
};
this.addStep(step);
return step;
};