Skip to content

Instantly share code, notes, and snippets.

@TooTallNate
Forked from sugyan/play-codestream.js
Created April 3, 2012 18:56
Show Gist options
  • Save TooTallNate/2294667 to your computer and use it in GitHub Desktop.
Save TooTallNate/2294667 to your computer and use it in GitHub Desktop.
play codestre.am video on your terminal
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