main/leap-plugins-0.1.12.js
function () {
      var player = this;
      // This is the original normal protocol, used while in record mode but not recording.
      this.stopProtocol = this.controller.connection.protocol;

      // This consumes all frame data, making the device act as if not streaming
      this.playbackProtocol = function (data) {
        // The old protocol still needs to emit events, so we use it, but intercept Frames
        var eventOrFrame = player.stopProtocol(data);
        if (eventOrFrame instanceof Leap.Frame) {

          if (player.pauseOnHand) {
            if (data.hands.length > 0) {
              player.userHasControl = true;
              player.controller.emit('playback.userTakeControl');
              player.setGraphic();
              player.idle();
            } else if (data.hands.length == 0) {
              if (player.userHasControl && player.resumeOnHandLost) {
                player.userHasControl = false;
                player.controller.emit('playback.userReleaseControl');
                player.setGraphic('wave');
              }

            }
          }

          // prevent the actual frame from getting through
          return {type: 'playback'}
        } else {
          return eventOrFrame;
        }
      };

      // This pushes frame data, and watches for hands to auto change state.
      // Returns the eventOrFrame without modifying it.
      this.recordProtocol = function (data) {
        var eventOrFrame = player.stopProtocol(data);
        if (eventOrFrame instanceof Leap.Frame) {
          player.recordFrameHandler(data);
        }
        return eventOrFrame;
      };

      // Copy methods/properties from the default protocol over
      for (var property in this.stopProtocol) {
        if (this.stopProtocol.hasOwnProperty(property)) {
          this.playbackProtocol[property] = this.stopProtocol[property]
          this.recordProtocol[property] = this.stopProtocol[property]
        }
      }

      // todo: this is messy. Should cover all cases, not just active playback!
      if (this.state == 'playing') {
        this.controller.connection.protocol = this.playbackProtocol
      }
    }
function () {
      var player = this;
      // This is the original normal protocol, used while in record mode but not recording.
      this.stopProtocol = this.controller.connection.protocol;

      // This consumes all frame data, making the device act as if not streaming
      this.playbackProtocol = function (data) {
        // The old protocol still needs to emit events, so we use it, but intercept Frames
        var eventOrFrame = player.stopProtocol(data);
        if (eventOrFrame instanceof Leap.Frame) {

          if (player.pauseOnHand) {
            if (data.hands.length > 0) {
              player.userHasControl = true;
              player.controller.emit('playback.userTakeControl');
              player.setGraphic();
              player.idle();
            } else if (data.hands.length == 0) {
              if (player.userHasControl && player.resumeOnHandLost) {
                player.userHasControl = false;
                player.controller.emit('playback.userReleaseControl');
                player.setGraphic('wave');
              }

            }
          }

          // prevent the actual frame from getting through
          return {type: 'playback'}
        } else {
          return eventOrFrame;
        }
      };

      // This pushes frame data, and watches for hands to auto change state.
      // Returns the eventOrFrame without modifying it.
      this.recordProtocol = function (data) {
        var eventOrFrame = player.stopProtocol(data);
        if (eventOrFrame instanceof Leap.Frame) {
          player.recordFrameHandler(data);
        }
        return eventOrFrame;
      };

      // Copy methods/properties from the default protocol over
      for (var property in this.stopProtocol) {
        if (this.stopProtocol.hasOwnProperty(property)) {
          this.playbackProtocol[property] = this.stopProtocol[property]
          this.recordProtocol[property] = this.stopProtocol[property]
        }
      }

      // todo: this is messy. Should cover all cases, not just active playback!
      if (this.state == 'playing') {
        this.controller.connection.protocol = this.playbackProtocol
      }
    }
function ( ) { var player = this ; // This is the original normal protocol, used while in record mode but not recording. this . stopProtocol = this . controller . connection . protocol ; // This consumes all frame data, making the device act as if not streaming this . playbackProtocol = function ( data ) { // The old protocol still needs to emit events, so we use it, but intercept Frames var eventOrFrame = player . stopProtocol ( data ) ; if ( eventOrFrame instanceof Leap . Frame ) { if ( player . pauseOnHand ) { if ( data . hands . length > 0 ) { player . userHasControl = true ; player . controller . emit ( 'playback.userTakeControl' ) ; player . setGraphic ( ) ; player . idle ( ) ; } else if ( data . hands . length == 0 ) { if ( player . userHasControl && player . resumeOnHandLost ) { player . userHasControl = false ; player . controller . emit ( 'playback.userReleaseControl' ) ; player . setGraphic ( 'wave' ) ; } } } // prevent the actual frame from getting through return { type : 'playback' } } else { return eventOrFrame ; } } ; // This pushes frame data, and watches for hands to auto change state. // Returns the eventOrFrame without modifying it. this . recordProtocol = function ( data ) { var eventOrFrame = player . stopProtocol ( data ) ; if ( eventOrFrame instanceof Leap . Frame ) { player . recordFrameHandler ( data ) ; } return eventOrFrame ; } ; // Copy methods/properties from the default protocol over for ( var property in this . stopProtocol ) { if ( this . stopProtocol . hasOwnProperty ( property ) ) { this . playbackProtocol [ property ] = this . stopProtocol [ property ] this . recordProtocol [ property ] = this . stopProtocol [ property ] } } // todo: this is messy. Should cover all cases, not just active playback! if ( this . state == 'playing' ) { this . controller . connection . protocol = this . playbackProtocol } }
This is how we intercept frame data early By hooking in before Frame creation, we get data exactly as the frame sends it.
This is how we intercept frame data early By hooking in before Frame creation we get data exactly as the frame sends it .