From a6693ad30ffd6e636529e20babb38ce875220de2 Mon Sep 17 00:00:00 2001 From: RNO Date: Thu, 7 Dec 2017 11:06:57 +0100 Subject: [PATCH] [leap] Catch malformed packet See https://github.com/leapmotion/leapjs/issues/219 --- lib/leap.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/leap.js b/lib/leap.js index 3dabb2c..b020bb6 100644 --- a/lib/leap.js +++ b/lib/leap.js @@ -15,10 +15,21 @@ const leapjs = require('leapjs') const controller = new leapjs.Controller() if (args.leap) { - controller.on('connect', () => log.info('Successfully connected.')) controller.on('streamingStarted', () => log.info('A Leap device has been connected.')) controller.on('streamingStopped', () => log.info('A Leap device has been disconnected.')) - + controller.on('connect', function () { + log.info('Successfully connected.') + // NOTE: this block fixes the lame leapmotion's handling of malformed packets + // https://github.com/leapmotion/leapjs/issues/219 + const originalHandleData = this.connection.handleData + this.connection.handleData = function (data) { + try { + return originalHandleData.call(this, data) + } catch (e) { + log.warning(e) + } + } + }) controller.connect() } @@ -45,7 +56,6 @@ module.exports = { z: normalizedPosition[1] * box[2] } } - return mockHand.update(box) - }, + } }