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.
25 lines
787 B
25 lines
787 B
const socket = require('socket.io');
|
|
const chalk = require('chalk');
|
|
|
|
const {pub, sub} = require('../connections/redis_conn')
|
|
const {iWrite, closeWrite, iQuery} = require('../actions/influx_actions')
|
|
|
|
module.exports = (server) => {
|
|
// noinspection JSValidateTypes
|
|
const io = socket(server)
|
|
|
|
io.on('connection', socket => {
|
|
console.log(chalk.bgWhiteBright.black.bold(`Client with id: ${chalk.bgBlack.whiteBright(socket.id)} just connected!`));
|
|
|
|
socket.on('disconnect', () => {
|
|
console.log(chalk.red('Client disconnected!'));
|
|
});
|
|
|
|
socket.on('data', (data) => {
|
|
const {measurement, pointName} = data;
|
|
|
|
pub.publish('data', measurement);
|
|
iWrite(pointName, socket.id, measurement)
|
|
})
|
|
});
|
|
}
|