javascript - How to get element in Leap Motion frame? -
this how i'm trying specific element frame of leap motion device though websocket.
var websocket = require('ws'); ws = new websocket('ws://127.0.0.1:6437'); ws.on('message', function(data, flags) { var frame = json.parse(data); var id = frame.hands; var pos = id[0]; console.log(pos); });
the json object looks : leap motion sample frame
i'm getting error.
sanjeet-suhags-macbook-pro:leapjs sanjeetsuhag$ node index.js /users/sanjeetsuhag/developer/node/leapjs/index.js:7 var pos = id[0]; ^ typeerror: cannot read property '0' of undefined @ websocket.<anonymous> (/users/sanjeetsuhag/developer/node/leapjs/index.js:7:14) @ websocket.emit (events.js:98:17) @ receiver.self._receiver.ontext (/users/sanjeetsuhag/developer/node/leapjs/node_modules/ws/lib/websocket.js:697:10) @ receiver.opcodes.1.finish (/users/sanjeetsuhag/developer/node/leapjs/node_modules/ws/lib/receiver.js:397:14) @ receiver.expecthandler (/users/sanjeetsuhag/developer/node/leapjs/node_modules/ws/lib/receiver.js:384:31) @ receiver.add (/users/sanjeetsuhag/developer/node/leapjs/node_modules/ws/lib/receiver.js:93:24) @ firsthandler (/users/sanjeetsuhag/developer/node/leapjs/node_modules/ws/lib/websocket.js:673:22) @ process._tickcallback (node.js:419:13)
what's going wrong ? thanks.
the hands
array empty if no hands detected, change code to:
ws.on('message', function(data, flags) { var frame = json.parse(data); var id = frame.hands; if (id.length === 0) return; var pos = id[0]; console.log(pos); });
Comments
Post a Comment