Last active
December 17, 2015 04:28
-
-
Save joyrexus/5550582 to your computer and use it in GitHub Desktop.
Pipe samples from the Leap's websocket stream to stdout.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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