-
-
Save TooTallNate/2294667 to your computer and use it in GitHub Desktop.
play codestre.am video on your terminal
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
var sio = require('socket.io-client') | |
, id = process.argv[2] || '3Y' | |
, socket = sio.connect('http://play.codestre.am/?id=' + id) | |
console.log('connecting...') | |
socket.on('connect', function () { | |
console.log('connected.') | |
}) | |
socket.on('frames', function (frames) { | |
// close the socket | |
socket.disconnect() | |
// playback the frames using local setTimeout() calls | |
play(frames) | |
}) | |
function play (frames) { | |
var pos = 0 | |
, len = frames.length | |
function loop () { | |
var obj = frames[pos++] | |
setTimeout(function () { | |
process.stdout.write(obj.data) | |
if (pos !== len) { | |
loop() | |
} | |
}, obj.delta) | |
} | |
loop() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment