From 14f9e505c6d45e69035c854a3bdc938d9511cba3 Mon Sep 17 00:00:00 2001 From: Haris Razis Date: Thu, 31 Dec 2020 17:31:10 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9E=95=20Add=20redis=20pub=20to=20emit=20int?= =?UTF-8?q?o=20web=20socket?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/services/socket.js | 12 +++++++++--- web/src/views/Dashboard.vue | 4 ++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/server/services/socket.js b/server/services/socket.js index 1be7385..d2f8bc7 100644 --- a/server/services/socket.js +++ b/server/services/socket.js @@ -15,10 +15,16 @@ module.exports = (server) => { }); socket.on('data', (data) => { - const {measurement, pointName} = data; + pub.publish('console', JSON.stringify(data)); + }); + + sub.on('message', (channel, data) => { + const {measurement, pointName} = JSON.parse(data); - pub.publish('data', measurement); + io.emit('console', {measurement}) iWrite(pointName, socket.id, measurement) - }) + }); + + sub.subscribe('console') }); } \ No newline at end of file diff --git a/web/src/views/Dashboard.vue b/web/src/views/Dashboard.vue index b480657..8d2feaa 100644 --- a/web/src/views/Dashboard.vue +++ b/web/src/views/Dashboard.vue @@ -32,6 +32,10 @@ export default class Dashboard extends Vue { console.log(('Reconnecting...')); }); + + this.socket.on('console', (data: {}) => { + console.log(data); + }) } }