Skip to content

Instantly share code, notes, and snippets.

@youpy
Created June 17, 2012 09:19
Show Gist options
  • Save youpy/2943986 to your computer and use it in GitHub Desktop.
Save youpy/2943986 to your computer and use it in GitHub Desktop.
// 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