Skip to content

Instantly share code, notes, and snippets.

@goliatone
Forked from TooTallNate/play-codestream.js
Created August 28, 2013 13:02
Show Gist options
  • Save goliatone/6365793 to your computer and use it in GitHub Desktop.
Save goliatone/6365793 to your computer and use it in GitHub Desktop.
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