diff --git a/server/services/socket.js b/server/services/socket.js index d2f8bc7..0fc1fc6 100644 --- a/server/services/socket.js +++ b/server/services/socket.js @@ -1,4 +1,5 @@ const socket = require('socket.io'); +const redisAdapter = require('socket.io-redis'); const chalk = require('chalk'); const {pub, sub} = require('../connections/redis_conn') @@ -6,6 +7,7 @@ const {iWrite, closeWrite, iQuery} = require('../actions/influx_actions') module.exports = (server) => { const io = socket(server) + io.adapter(redisAdapter({host: 'redis', port: 6379})); io.on('connection', socket => { console.log(chalk.bgWhiteBright.black.bold(`Client with id: ${chalk.bgBlack.whiteBright(socket.id)} just connected!`)); @@ -15,16 +17,11 @@ module.exports = (server) => { }); socket.on('data', (data) => { - pub.publish('console', JSON.stringify(data)); - }); - - sub.on('message', (channel, data) => { - const {measurement, pointName} = JSON.parse(data); + const {measurement, pointName} = data; io.emit('console', {measurement}) iWrite(pointName, socket.id, measurement) }); - sub.subscribe('console') }); } \ No newline at end of file