flyvictor/fortune — pull request #99 by radiodario (2014-11-23 05:59:22+00:00)
Title: Fortune Websockets

I've added a plugin that adds an `afterWrite` hook to fortune to notify users of creation, update and removal of documents on fortune via websockets.

In order to do this, a client can connect via socket io (currently on port 4000);

```js
var socket = io('http://localhost:4000');
socket.on('connect', function() {
socket.emit("watch", "person"); // watch the name of the resource
});
socket.on('add', function(data) {
// do something when a person is added
});
socket.on('update', function(data) {
// do something on update;
});
socket.on('delete', function(data) {
// do something on delete;
});
```

I've used rooms to separate away notifications to different resources but somehow namespaces might be better? Would appreciate some input in that aspect. [more info here](http://socket.io/docs/rooms-and-namespaces/)

## To Do:
- [x] Add websockets plugin with notifications for CUD (users don't need to be notified when an user Reads)
- [ ] Better tests
- [ ] Add namespace support instead of rooms?
- [ ] Decide on what the payload of the event should be for Create, Update and Delete.
- [ ] Obtain / decide on port number for socket.io to listen to - currently it is set to 4000