Send updates of reports via sockets
This commit is contained in:
parent
9040cae21b
commit
2523b3e491
@ -55,6 +55,15 @@ module.exports.run = function(worker) {
|
|||||||
next();
|
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) {
|
scServer.on('connection', function(socket) {
|
||||||
var channelToWatch, channelToEmit;
|
var channelToWatch, channelToEmit;
|
||||||
socket.on('login', function (credentials, respond) {
|
socket.on('login', function (credentials, respond) {
|
||||||
@ -68,6 +77,11 @@ module.exports.run = function(worker) {
|
|||||||
});
|
});
|
||||||
respond(null, channelToWatch);
|
respond(null, channelToWatch);
|
||||||
});
|
});
|
||||||
|
socket.on('getReport', function (id, respond) {
|
||||||
|
store.get(id).then(function(data) {
|
||||||
|
respond(null, data);
|
||||||
|
});
|
||||||
|
});
|
||||||
socket.on('disconnect', function() {
|
socket.on('disconnect', function() {
|
||||||
var channel = worker.exchange.channel('sc-' + socket.id);
|
var channel = worker.exchange.channel('sc-' + socket.id);
|
||||||
channel.unsubscribe(); channel.destroy();
|
channel.unsubscribe(); channel.destroy();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user