From fa9e22b1c94e567d85e5d316cb3260303fc05c17 Mon Sep 17 00:00:00 2001 From: Haris Razis Date: Fri, 1 Jan 2021 11:51:35 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9E=95=20Add=20socket.io-redis?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/services/socket.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) 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