Skip to content

Commit

Permalink
[leap] Catch malformed packet
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudjuracek committed Dec 7, 2017
1 parent 50c5cd8 commit a6693ad
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions lib/leap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand All @@ -45,7 +56,6 @@ module.exports = {
z: normalizedPosition[1] * box[2]
}
}

return mockHand.update(box)
},
}
}

0 comments on commit a6693ad

Please sign in to comment.