diff --git a/lib/worker.js b/lib/worker.js index 411d454..238d755 100644 --- a/lib/worker.js +++ b/lib/worker.js @@ -55,6 +55,15 @@ module.exports.run = function(worker) { next(); }); + scServer.addMiddleware(scServer.MIDDLEWARE_SUBSCRIBE, function (req, next) { + next(); + if (req.channel === 'report') { + store.list().then(function(data) { + req.socket.emit(req.channel, { type: 'list', data: data }); + }); + } + }); + scServer.on('connection', function(socket) { var channelToWatch, channelToEmit; socket.on('login', function (credentials, respond) { @@ -68,6 +77,11 @@ module.exports.run = function(worker) { }); respond(null, channelToWatch); }); + socket.on('getReport', function (id, respond) { + store.get(id).then(function(data) { + respond(null, data); + }); + }); socket.on('disconnect', function() { var channel = worker.exchange.channel('sc-' + socket.id); channel.unsubscribe(); channel.destroy();