Skip to content

Instantly share code, notes, and snippets.

@joyrexus
Last active December 17, 2015 04:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joyrexus/5550582 to your computer and use it in GitHub Desktop.
Save joyrexus/5550582 to your computer and use it in GitHub Desktop.
Pipe samples from the Leap's websocket stream to stdout.
#!/usr/bin/env coffee
###
Pipe samples from the Leap's websocket stream to stdout.
USAGE
leap.pipe.coffee [no. of samples]
leap.pipe.coffee 1000 > hand.data
###
WebSocket = require 'ws'
ws = new WebSocket 'ws://localhost:6437'
print = console.log
max = process.argv[2]
max ?= 100
i = 0
ws.on 'open', ->
print 'socket opened'
ws.send JSON.stringify {enableGestures: true}
ws.on 'close', (code, reason) ->
print "#{ws.bytesReceived} bytes received"
print "socket closed (#{code})"
print reason if reason
ws.on 'error', (err) -> print err
ws.on 'message', (d) -> if max > (i += 1) then print d else ws.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment