The implementation of DDP server based on EventEmitter.
$ npm install --save ddp-server-event
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);
Each event handler binded to ddp
instance as this
, such methods are available.
Sends the result back to subscriber.
Sends the error back to subscriber.
Sends added back to subscriber.
Sends changed back to subscriber.
Sends removed back to subscriber.
Sends ready event, should be called inside sub
event handler.
Sends nosub event, should be called inside sub
event handler.
Sends generic back to subscriber.
- alexbeletsky/sparkling - Reactive API for Express.js