DailyJS

DailyJS

The JavaScript blog.


Tagirc
Featured

irc node apps

Shout: An IRC Client for the Web

Posted on .

Shout IRC

Shout (GitHub: erming / shout, License: MIT, npm: shout) by Mattias Erming is a web-based IRC client. The UI is very impressive, it feels lightweight and fast, but still familiar to die-hard IRC users like me.

I still use an IRC client on a server with tmux, and I probably always will, but there are times when I get forced into using web-based chat services. This is usually for work, and I pretty much never like them. The thing that's good about Shout is you can run it on your own server, so you could install an IRC daemon on a server somewhere then set it up to connect to it automatically.

This means your colleagues that hate console software can use a friendly web interface, while you can hang out in the shell like a civilized person. There are commercial services that offer IRC backends and friendly web frontends (Gitter and Grove are good examples), but you may like to host your own or hack Shout in some way.

Shout is built using a simple server based on Connect and Socket.IO that maps the client UI to a real IRC server. It has a Grunt build script, and treats IRC commands like plugins so it should be easy to add new ones.

The client-side code uses Handlebars for the templates, and the CSS looks easy to modify. There's a folder called themes but the example CSS file is currently empty, so I'm not sure how the authors intend that to be used.

The underlying IRC client implementation is slate-irc, which I seem to remember TJ Holowaychuk wrote for a cool Node desktop app. Mattias Erming is now a maintainer, and he's been committing work to the slate-irc project on GitHub.

Overall Shout looks like it has a lot of potential, and I've been impressed by what I've seen so far.

Featured

irc node modules security talks slides

Node Roundup: 0.10.24, irc-message-stream, 100% Uptime

Posted on .

Node 0.10.24 Released

Node 0.10.24 was released soon after 0.10.23. It updates uv and npm, but presumably this release was due to CVE-2013-6639 and CVE-2013-6640. These are security related patches for V8:

... allows remote attackers to cause a denial of service (out-of-bounds read) via JavaScript code that sets a variable to the value of an array element with a crafted index

If you run this example in Node 0.10.22 you should see a segfault.

var size = 0x20000;  
var a = new Float64Array(size);  
var training = new Float64Array(10);

function store(a, index) {  
  var offset = 0x20000000;
  for (var i = 0; i < 1; i++) {
    a[index + offset] = 0xcc;
  }
}

store(training, -0x20000000);  
store(training, -0x20000000 + 1);  
store(training, -0x20000000);  
store(training, -0x20000000 + 1);

for (var i = -0x20000000; i < -0x20000000 + size; i++) {  
  store(a, i);
}

irc-message-stream

irc-message (GitHub: expr / irc-message, License: BSD 2-Clause, npm: irc-message) by Fionn Kelleher is a small parser that outputs objects based on RFC1459. The author has used it to create irc-message-stream, which is a transform stream.

That means you can take a socket connection to an IRC server and pipe it through your own stream handlers:

var net = require('net');  
var MessageStream = require('irc-message-stream');  
var messageStream = new MessageStream();

messageStream.on('line', function(line) {  
  console.log('Raw line:', line);
});

messageStream.on('data', function(message) {  
  console.log('Parsed message:', JSON.stringify(message));
});

var socket = net.connect(6667, 'irc.freenode.net');  
socket.pipe(messageStream);  

I think this is a great way to handle IRC in Node -- taking advantage of the newer streams API seems a lot more idiomatic than other approaches that I've seen (and made!).

Towards 100% Uptime with Node

William sent in his slides for a talk called Towards 100% Uptime with Node. The slides cover the difficulties of handling uncaught exceptions in a cluster of Node processes, and ensuring that every request has a response, even if it's to report an error.

One of the tips he mentions is to be able to generate errors on demand for development and staging. I do this in my tests -- if critical paths are expected to throw exceptions, emit 'error' events, or return error objects to callbacks, then all of these eventualities should be hit as part of automated testing.

The Node applications I work on for my day job are hosted on Heroku, and I've found you have to be extremely careful with code that throws errors and causes the process to stop. Sometimes Heroku gets confused about the state of a process and won't gracefully restart it, so a worker just hangs for an undefined amount of time. The way I stopped this was to fix all the bugs, which sounds like an obvious thing to say, but it took lots of log file archaeology. Coincidentally, Heroku's default logging is inadequate, so you have to send logs to a syslog daemon somewhere, or a service like Loggly (which I preferred to Splunk).

Featured

nodejs irc

Node.js on IRC

Posted on .

Node.js makes writing IRC-related programs straightforward and super-efficient, thanks to its evented networking.
Therefore it isn’t surprising that a lot of projects have appeared
already.

I’ve been looking around for reusable JavaScript IRC libraries, and
discovered the following projects.

IRC Daemon Demo

This IRC daemon demo presented at jsconf.eu/2009 demonstrates how to build a server. It has
simple prototypal classes for channels and users, and parses IRC
commands using a regex and a switch. It also uses node’s
TCP library.

nodelog

nodelog is an IRC logger. This would be a good place to start if you’d like to build a JavaScript IRC
bot. The client code is clear and reusable. The log.js file
demonstrates how to use the irc.js library.

irccat-nodejs

irccat-nodejs is based on irccat which allows you to send messages to IRC using HTTP or a TCP socket. The client code is again
fairly simple.

egret

egret is a command-line IRC client. The base code uses node’s TCP sockets and a hash to interpret IRC
commands into English.

nodejs.irc

nodejs.irc is an IRC bot. It’s not finished yet, but the code is separated out and easy to follow.

aoibot

aoibot is similar to nodejs.irc, but it looks like the finished product will be less generic. Again, it’s
unfinished, so I expect the author still has a lot of ideas and work to
do.