hookio/webserver — pull request #8 by ianjennings (2012-01-09 07:38:17+00:00)
Title: [feature] browser events now broadcast to all clients

Hey all. I spent tonight working on way to get webserver to broadcast to all browser clients.

This works by assigning a unique id to clients and keeping a reference in webserver.js. When an event is received by webserver, it loops through and emits the event to every client. The client that emitted the event gets calledback.

A couple notes:

Broadcasted events are namespaced with webserver:: to avoid confusion with local events.

Because we store a reference to clients, we want to remove them when they disconnect to avoid memory leak. To do this, we simply remove a reference if the client hasn't sent a message in a while. We also relay a "webserver::timeout" to the disconnected client. If the client sends a message after being timedout they begin to receive events again.

Although this diff does not include it, there is still a need for private events for things like sessions, passwords, and private messages. I feel broadcasting to all nodes by default is closer to the vision of hook.io, so maybe a private:: namespace comes next.

This required copying over the hook.js file from version 0.8.0.
https://github.com/hookio/hook.js/tree/0.8.0

This is relevant to the following thread (with further references to issues).
https://github.com/hookio/hook.io/issues/134