Demo entry 6352803

js

   

Submitted by anonymous on Mar 26, 2017 at 09:27
Language: JavaScript. Code size: 2.0 kB.

var wss = new ws.Server({ port: 8888 });
// Broadcast to all.
wss.broadcast = function broadcast(data,websocket) {
  var preClient="";
  wss.clients.forEach(function(client) {
    if (client !== websocket && client.readyState === ws.OPEN) {
       
        console.log(data.id);
        client.send(stringify(data));
      }
  });
};

var controller = new Leap.Controller({
  host: '127.0.0.1',
  port: 6437,
  frameEventName: 'animationFrame',
  useAllPlugins: true
});
controller.connect();
wss.on('connection', function connection(websocket) {
  started = true;
  console.log("client connected");
  var message = '{"serviceVersion":"3.1.3+41910","version":6}';
  websocket.send(message);
  websocket.on('message', function incoming(data) {
    // Broadcast to everyone .
    console.log("chufa");
    var data;
    Leap.loop({enableGestures: true}, function(frame, done) {//access leap JSON Message
      data = objectframe(frame);
      wss.broadcast(data, websocket)
      //websocket.send(stringify(data));
	  });	
  });
});

function objectframe(frame){
  var data={"currentFrameRate":38.2541,"devices":[],"gestures":[],"hands":[],"id":79658,"interactionBox":{"center":[0.000000,200.000,0.000000],"size":[235.247,235.247,147.751]},"pointables":[],"r":[[1.00000,0.000000,0.000000],[0.000000,1.00000,0.000000],[0.000000,0.000000,1.00000]],"s":1.00000,"t":[0.000000,0.000000,0.000000],"timestamp":1863388369};
  data["currentFrameRate"] = frame.currentFrameRate;
  data["devices"] = frame.data.devices;
  data["gestures"] = frame.data.gestures;
  data["hands"] = frame.data.hands;
  data["id"] = frame.id;
  data["interactionBox"]["center"] =stringify( frame.interactionBox.center);
  data["interactionBox"]["size"] = stringify(frame.interactionBox.size);
  data["pointables"] = frame.pointables;
  data["r"] = stringify( frame.data.r);
  data["s"] = stringify( frame.data.s);
  data["t"] = stringify( frame.data.t);
  data["timestamp"] = frame.timestamp;
  return data;
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).