Created
June 17, 2012 09:19
-
-
Save youpy/2943986 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// usage: tail -f xxx.log | node tailf.js | |
var | |
WebSocket = require('ws'), | |
async = require('async'), | |
spawn = require('child_process').spawn, | |
wsUrl = 'http://beer.jit.su', | |
webUrl = 'http://tailf.herokuapp.com', | |
id, | |
createChannel = function(callback) { | |
var ws = new WebSocket(wsUrl + '/channels'); | |
ws.on('open', function() { | |
ws.on('message', function(data, flags) { | |
id = data; | |
ws.close(); | |
}); | |
}); | |
ws.on('close', function() { | |
callback(); | |
}); | |
}, | |
connect = function(callback) { | |
var ws = new WebSocket(wsUrl + '/channels/' + id); | |
ws.on('open', function() { | |
var url = webUrl + '/streams/' + id, | |
stdin = process.stdin; | |
console.log(url); | |
// TODO: support linux + windows | |
spawn('open', [url]); | |
stdin.resume(); | |
stdin.on('data', function(chunk) { | |
var str = chunk.toString(); | |
ws.send(str); | |
}); | |
}); | |
}; | |
async.series([createChannel, connect]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment