Skip to content

Commit

Permalink
Merge pull request #20 from munkychop/master
Browse files Browse the repository at this point in the history
Added 'removeListener' method.
  • Loading branch information
bengfarrell committed Dec 4, 2014
2 parents 4384259 + d075a60 commit 7117c25
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ module.exports.setJoints = function(joints) {
} else {
module.exports.jointsTracking = joints;
}
}
};

/**
* add a listener for specific events (device/user/etc)
Expand All @@ -94,32 +94,51 @@ module.exports.addListener = function(eventName, callback) {
module.exports._eventCallbackDict[eventName[evt]] = callback;
}
}
}
};

/**
* remove a listener for specific events (device/user/etc)
* @param event name (string or array of events)
*/
module.exports.removeListener = function(eventName) {
if (typeof eventName == "string" && typeof module.exports._eventCallbackDict[eventName] !== "undefined") {
delete module.exports._eventCallbackDict[eventName];
} else {
for (var evt in eventName) {

if (typeof module.exports._eventCallbackDict[eventName[evt]] !== "undefined")
delete module.exports._eventCallbackDict[eventName[evt]];
}
}
};

/**
* add a listener for gestures
* @param gesture name (string or array of gestures)
* @parm callback function
*/
module.exports.addGesture = function(gestureName, callback) {

var gestureType;

if (typeof gestureName == "string") {
module.exports._gestureCallbackDict[gestureName] = callback;

//don't expose end user to system complexities of "gesture type"
//we'll get the type from the first part of the gesture name
var gestureType = gestureName.split("_")[0] + "_GESTURE";
gestureType = gestureName.split("_")[0] + "_GESTURE";
module.exports.addGestureListener(gestureType, gestureName);
} else {
for (var gst in gestureName) {
module.exports._gestureCallbackDict[gestureName[gst]] = callback;

//don't expose end user to system complexities of "gesture type"
//we'll get the type from the first part of the gesture name
var gestureType = gestureName[gst].split("_")[0] + "_GESTURE";
gestureType = gestureName[gst].split("_")[0] + "_GESTURE";
module.exports.addGestureListener(gestureType, gestureName[gst]);
}
}
}
};

/**
* start skeleton listener loop when skeleton is in view
Expand All @@ -139,10 +158,10 @@ module.exports.startSkeletonListener = function(joints, callback, rate) {
}

// if skeleton already tracking, immediately start the listener
if (module.exports.isSkeletonTracking == true && !module.exports._frameLoopTimer) {
if (module.exports.isSkeletonTracking === true && !module.exports._frameLoopTimer) {
module.exports._frameLoopTimer = setInterval(module.exports._onFrameLoopUpdate, module.exports.frameDelay);
}
}
};

/**
* timed frame loop update for issuing skeleton/joint tracking events
Expand All @@ -153,7 +172,7 @@ module.exports._onFrameLoopUpdate = function() {
var skeleton = module.exports.getJoints.apply(this, module.exports.jointsTracking);
module.exports.onSkeletonEventHandler.apply(this, [ {skeleton: skeleton} ]);
}
}
};

/**
* events listener
Expand Down

0 comments on commit 7117c25

Please sign in to comment.