Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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