ddp-server-event
v1.0.3
Published
The implementation of DDP server based on EventEmitter
Downloads
1
Maintainers
Readme
DDP Server based on Events
The implementation of DDP server based on EventEmitter.
Usage
$ npm install --save ddp-server-events
var server = http.createServer();
var ddp = new Ddp({server: server});
ddp.on('ready', function () {
console.log('ddp server ready');
});
ddp.on('sub', function (id, name, params) {
// handle sub to collection here...
this.sendReady(); // in case of error, this.sendNosub();
});
ddp.on('unsub', function (id, name, params) {
// handle unsub here...
this.sendReady();
});
// all methods calls are prefixed with "method:"
ddp.on('method:test', function (id, params) {
var x = params.x, y = params.y;
var sum = x + y;
this.sendResult(id, sum);
});
server.listen(3000);
Methods
Each event handler binded to ddp
instance as this
, such methods are available.
ddp.sendResult(id, result);
Sends the result back to subscriber.
ddp.sendError(id, error);
Sends the error back to subscriber.
ddp.sendAdded(id, collection, fields);
Sends added back to subscriber.
ddp.sendChanged(id, collection, fields, cleared);
Sends changed back to subscriber.
ddp.sendRemoved(id, collection, fields, cleared);
Sends removed back to subscriber.
ddp.sendReady(id);
Sends ready event, should be called inside sub
event handler.
ddp.sendNosub(id);
Sends nosub event, should be called inside sub
event handler.
ddp.sendEvent(msg, data);
Sends generic back to subscriber.