block by joyrexus 7934042

Render your leap stream

Full Screen

The leap-stream.js script provides a leap method which takes a single callback for rendering data frames coming from the Leap’s websocket stream:

<script src="leap-stream.js"></script>
<script>
  render = function(frame) { ... };
  leap(render);
</script>

See index.html and its rendering script (render.coffee, render.js) for sample usage: in this case, a simple viewer for observing hand movement.

Note: index.coffee.html is identical to index.html albeit for the fact that we’ve embedded the rendering method as a coffeescript script.

Here’s the supplied method:

leap = (render) ->
  stream = new WebSocket 'ws://localhost:6437'
  stream.onmessage = (event) -> 
    render(JSON.parse(event.data)) if event.data
  ''

This is intended as a ultra-minimalist alternative to the leap.js framework, and a simple starting point for personal leap hacking.

index.html

index.coffee.html

leap-stream.coffee

leap-stream.js

render.coffee

render.js