Node Roundup: NodObjC, SockJS, French Node Blog

2011-09-14 00:00:00 +0100 by Alex R. Young
You can send your node modules and articles in for review through our [contact form](/contact.html) or [@dailyjs](http://twitter.com/dailyjs).


NodObjC (npm: NodObjC) by Nathan Rajlich is an Objective-C bridge:

It uses the BridgeSupport files to dynamically generate an API from an Objective-C "Framework", and uses node-ffi to dynamically interact with the Objective-C runtime.

If you're an Objective-C developer, then you should be able to follow
this basic app structure:

var $ = require('NodObjC')

// First you need to "import" the Framework

// Setup the recommended NSAutoreleasePool instance
var pool = $.NSAutoreleasePool('alloc')('init')

// NSStrings and JavaScript Strings are distinct objects, you must create an
// NSString from a JS String when an Objective-C class method requires one.
var string = $.NSString('stringWithUTF8String', 'Hello Objective-C World!')

// Print out the contents (calling [string description])
//   → Prints "Hello Objective-C World!"


Sending messages to objects looks like this: obj('func',
. So a call like [array insertObject:obj
would be written as array('insertObject', obj,
'atIndex', 5)

This means Apple's native APIs are accessible from Node, so you could
create GUI apps for Mac OS. There are examples out there of GUI code
already: cocoa-hello-world2.js.


SockJS (License: MIT) is a WebSocket emulation library that attempts to provide simple APIs for
both server and clients, while remaining as close to the WebSocket API
as possible. It's designed to work from behind restrictive corporate
proxies, and browsers that don't support WebSocket. The project includes
the server-side library,
sockjs-node and client-side: sockjs-client.

Using sockets in the browser looks like this:

var sockjs = new SockJS('http://mydomain.com/my_prefix');
sockjs.onopen = function() {
  console.log('open', e.data);
sockjs.onmessage = function(e) {
  console.log('message', e.data);
sockjs.onclose = function(e) {
  console.log('close', e.data);

To me this looks like the current draft of the WebSocket spec (Editor's
Draft 10 September 2011):

var socket = new WebSocket('ws://game.example.com:12010/updates');
socket.onopen = function() {
  setInterval(function() {
    if (socket.bufferedAmount == 0)
  }, 50);

This is different to Socket.IO:

var socket = io.connect('http://localhost');
socket.on('news', function (data) {
  socket.emit('my other event', { my: 'data' });

There's a detailed article about the library on RabbitMQ's blog: SockJS
- WebSocket emulation

and it includes details on how SockJS can be used with load balancing.

One interesting detail I noticed in the project README is it falls over
to polling rather than Flash:

No Flash inside (no need to open port 843 - which doesn't work through proxies, no need to host 'crossdomain.xml', no need to wait for 3 seconds in order to detect problems)

French Node Blog

Vincent Rabah emailed us to share his French Node blog: IT Wars: Node
. He's got articles
covering Socket.IO, Twitter, Vim, Windows, and a variety of other topics
including log monitoring.