1 | /**
|
2 | * Leap is the global namespace of the Leap API.
|
3 | * @namespace Leap
|
4 | */
|
5 | module.exports = {
|
6 | Controller: require("./controller"),
|
7 | Frame: require("./frame"),
|
8 | Gesture: require("./gesture"),
|
9 | Hand: require("./hand"),
|
10 | Pointable: require("./pointable"),
|
11 | Finger: require("./finger"),
|
12 | InteractionBox: require("./interaction_box"),
|
13 | CircularBuffer: require("./circular_buffer"),
|
14 | UI: require("./ui"),
|
15 | JSONProtocol: require("./protocol").JSONProtocol,
|
16 | glMatrix: require("gl-matrix"),
|
17 | mat3: require("gl-matrix").mat3,
|
18 | vec3: require("gl-matrix").vec3,
|
19 | loopController: undefined,
|
20 | version: require('./version.js'),
|
21 | /**
|
22 | * The Leap.loop() function passes a frame of Leap data to your
|
23 | * callback function and then calls window.requestAnimationFrame() after
|
24 | * executing your callback function.
|
25 | *
|
26 | * Leap.loop() sets up the Leap controller and WebSocket connection for you.
|
27 | * You do not need to create your own controller when using this method.
|
28 | *
|
29 | * Your callback function is called on an interval determined by the client
|
30 | * browser. Typically, this is on an interval of 60 frames/second. The most
|
31 | * recent frame of Leap data is passed to your callback function. If the Leap
|
32 | * is producing frames at a slower rate than the browser frame rate, the same
|
33 | * frame of Leap data can be passed to your function in successive animation
|
34 | * updates.
|
35 | *
|
36 | * As an alternative, you can create your own Controller object and use a
|
37 | * {@link Controller#onFrame onFrame} callback to process the data at
|
38 | * the frame rate of the Leap device. See {@link Controller} for an
|
39 | * example.
|
40 | *
|
41 | * @method Leap.loop
|
42 | * @param {function} callback A function called when the browser is ready to
|
43 | * draw to the screen. The most recent {@link Frame} object is passed to
|
44 | * your callback function.
|
45 | *
|
46 | * ```javascript
|
47 | * Leap.loop( function( frame ) {
|
48 | * // ... your code here
|
49 | * })
|
50 | * ```
|
51 | */
|
52 | loop: function(opts, callback) {
|
53 | if (opts && callback === undefined && (!opts.frame && !opts.hand)) {
|
54 | callback = opts;
|
55 | opts = {};
|
56 | }
|
57 |
|
58 | if (this.loopController) {
|
59 | if (opts){
|
60 | this.loopController.setupFrameEvents(opts);
|
61 | }
|
62 | }else{
|
63 | this.loopController = new this.Controller(opts);
|
64 | }
|
65 |
|
66 | this.loopController.loop(callback);
|
67 | return this.loopController;
|
68 | },
|
69 |
|
70 | /*
|
71 | * Convenience method for Leap.Controller.plugin
|
72 | */
|
73 | plugin: function(name, options){
|
74 | this.Controller.plugin(name, options)
|
75 | }
|
76 | }
|