Scalable IoT solution for real-time body position data
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
861 B

4 years ago
const socket = require('socket.io');
const redisAdapter = require('socket.io-redis');
4 years ago
const chalk = require('chalk');
const {pub, sub} = require('../connections/redis_conn')
const {iWrite, closeWrite, iQuery} = require('../actions/influx_actions')
4 years ago
module.exports = (server) => {
const io = socket(server)
io.adapter(redisAdapter({host: 'redis', port: 6379}));
4 years ago
io.on('connection', socket => {
console.log(chalk.bgWhiteBright.black.bold(`Client with id: ${chalk.bgBlack.whiteBright(socket.id)} just connected!`));
4 years ago
socket.on('disconnect', () => {
console.log(chalk.red('Client disconnected!'));
});
socket.on('data', (data) => {
const {measurement, pointName} = data;
4 years ago
io.emit('console', {measurement})
iWrite(pointName, socket.id, measurement)
});
4 years ago
});
}