sockethub/sockethub — pull request #3 by nilclass (2013-01-17 05:11:51+00:00)
Title: JSON generation and possible bug in protocol.functions.ping

Unfortunately I couldn't run the tests to verify my changes work, it fails with the following message:
```

/home/nil/src/sockethub/lib/wsServer.js:38
dispatcher.connect(connection);
^
TypeError: Cannot call method 'connect' of undefined
at WebSocketServer.wsServer.init (/home/nil/src/sockethub/lib/wsServer.js:38:18)
at WebSocketServer.EventEmitter.emit (events.js:115:20)
at WebSocketServer.handleUpgrade (/home/nil/src/sockethub/node_modules/websocket/lib/WebSocketServer.js:189:14)
at Server.EventEmitter.emit (events.js:115:20)
at Socket.socket.ondata (http.js:1710:14)
at TCP.onread (net.js:403:27)
npm ERR! Test failed. See above for more details.
npm ERR! not ok code 0
```

Looks like the wsServer needs to be passed a 'dispatcher' instance here: https://github.com/sockethub/sockethub/blob/master/test/message-suite.js#L69

Regarding the JSON generation through JSON.stringify: I believe using this approach instead of assembling the raw JSON data manually may impact performance marginally, but in the long run it's a lot safer, since no special care needs to be paid to escaping everything properly, wherever messages are created / updated.

Also I was wondering why JSON strings are passed around in the first place. It could just as well be real javascript objects, which can then be converted to JSON only when they are actually sent over the wire.