I have implemented REST API using restify.js. It is deployed on heroku. Now I want to add real-time communication between server and users (mobile apps). My idea is to emit events to clients to 'tell' them when any data are available for them (and they can call normal REST api to fetch this data). I am using redis PUB/SUB in my app to broadcast events.
So my very simpliefied code looks like this:
var redisClient = require('./redis-client');
var app = restify.createServer();
app.get('/give-me-data',function(req,res,next){
res.json('{ data: 'abcdef' });
});
redisClient.on('message',function(channel,message){
if(message=='data-available') {
// now I want to emit event to mobile clients through socket.io
}
});
redisClient.subscribe('data-available-channel');
app.listen(process.env.PORT);
How I can add socket.io
to such app to let clients (mobile apps) connect to it and listen for events?