|
@ -1,4 +1,5 @@ |
|
|
const socket = require('socket.io'); |
|
|
const socket = require('socket.io'); |
|
|
|
|
|
const redisAdapter = require('socket.io-redis'); |
|
|
const chalk = require('chalk'); |
|
|
const chalk = require('chalk'); |
|
|
|
|
|
|
|
|
const {pub, sub} = require('../connections/redis_conn') |
|
|
const {pub, sub} = require('../connections/redis_conn') |
|
@ -6,6 +7,7 @@ const {iWrite, closeWrite, iQuery} = require('../actions/influx_actions') |
|
|
|
|
|
|
|
|
module.exports = (server) => { |
|
|
module.exports = (server) => { |
|
|
const io = socket(server) |
|
|
const io = socket(server) |
|
|
|
|
|
io.adapter(redisAdapter({host: 'redis', port: 6379})); |
|
|
|
|
|
|
|
|
io.on('connection', socket => { |
|
|
io.on('connection', socket => { |
|
|
console.log(chalk.bgWhiteBright.black.bold(`Client with id: ${chalk.bgBlack.whiteBright(socket.id)} just connected!`)); |
|
|
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) => { |
|
|
socket.on('data', (data) => { |
|
|
pub.publish('console', JSON.stringify(data)); |
|
|
const {measurement, pointName} = data; |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
sub.on('message', (channel, data) => { |
|
|
|
|
|
const {measurement, pointName} = JSON.parse(data); |
|
|
|
|
|
|
|
|
|
|
|
io.emit('console', {measurement}) |
|
|
io.emit('console', {measurement}) |
|
|
iWrite(pointName, socket.id, measurement) |
|
|
iWrite(pointName, socket.id, measurement) |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
sub.subscribe('console') |
|
|
|
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |