UNPKG

node-red-contrib-leap-motion

Version:

Node-Red nodes for leap motion

86 lines (80 loc) 2.78 kB
/** * Leap is the global namespace of the Leap API. * @namespace Leap */ module.exports = { Controller: require("./controller"), Frame: require("./frame"), Gesture: require("./gesture"), Hand: require("./hand"), Pointable: require("./pointable"), Finger: require("./finger"), InteractionBox: require("./interaction_box"), CircularBuffer: require("./circular_buffer"), UI: require("./ui"), JSONProtocol: require("./protocol").JSONProtocol, glMatrix: require("gl-matrix"), mat3: require("gl-matrix").mat3, vec3: require("gl-matrix").vec3, loopController: undefined, version: require('./version.js'), /** * Expose utility libraries for convenience * Use carefully - they may be subject to upgrade or removal in different versions of LeapJS. * */ _: require('underscore'), EventEmitter: require('events').EventEmitter, /** * The Leap.loop() function passes a frame of Leap data to your * callback function and then calls window.requestAnimationFrame() after * executing your callback function. * * Leap.loop() sets up the Leap controller and WebSocket connection for you. * You do not need to create your own controller when using this method. * * Your callback function is called on an interval determined by the client * browser. Typically, this is on an interval of 60 frames/second. The most * recent frame of Leap data is passed to your callback function. If the Leap * is producing frames at a slower rate than the browser frame rate, the same * frame of Leap data can be passed to your function in successive animation * updates. * * As an alternative, you can create your own Controller object and use a * {@link Controller#onFrame onFrame} callback to process the data at * the frame rate of the Leap device. See {@link Controller} for an * example. * * @method Leap.loop * @param {function} callback A function called when the browser is ready to * draw to the screen. The most recent {@link Frame} object is passed to * your callback function. * * ```javascript * Leap.loop( function( frame ) { * // ... your code here * }) * ``` */ loop: function(opts, callback) { if (opts && callback === undefined && ( ({}).toString.call(opts) === '[object Function]' ) ) { callback = opts; opts = {}; } if (this.loopController) { if (opts){ this.loopController.setupFrameEvents(opts); } }else{ this.loopController = new this.Controller(opts); } this.loopController.loop(callback); return this.loopController; }, /* * Convenience method for Leap.Controller.plugin */ plugin: function(name, options){ this.Controller.plugin(name, options) } }