diff --git a/server/services/passport.js b/server/services/passport.js new file mode 100644 index 0000000..e69de29 diff --git a/server/services/redis.js b/server/services/redis.js index e69de29..0ba9195 100644 --- a/server/services/redis.js +++ b/server/services/redis.js @@ -0,0 +1,25 @@ +const redis = require('redis'); + +const subscriber = redis.createClient(); +const publisher = redis.createClient(); + +let messageCount = 0; + +subscriber.on('subscribe', function (channel, count) { + publisher.publish('a channel', 'a message'); + publisher.publish('a channel', 'another message'); +}); + +subscriber.on('message', function (channel, message) { + messageCount += 1; + + console.log('Subscriber received message in channel \'' + channel + '\': ' + message); + + if (messageCount === 2) { + subscriber.unsubscribe(); + subscriber.quit(); + publisher.quit(); + } +}); + +subscriber.subscribe('a channel'); \ No newline at end of file diff --git a/server/services/socket.js b/server/services/socket.js index dee8c71..1ed9c50 100644 --- a/server/services/socket.js +++ b/server/services/socket.js @@ -1,5 +1,8 @@ const socket = require('socket.io'); -const chalk = require('chalk') +const chalk = require('chalk'); + +const {pub, sub} = require('../connections/redis_conn') +const {write, closeWrite, query} = require('../actions/influx_actions') module.exports = (server) => { // noinspection JSValidateTypes @@ -7,5 +10,16 @@ module.exports = (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); + write(socket.id, measurement, pointName) + }) }); } \ No newline at end of file