Browse Source

Add redis pub to emit into web socket

main
Haris Razis 4 years ago
parent
commit
14f9e505c6
  1. 12
      server/services/socket.js
  2. 4
      web/src/views/Dashboard.vue

12
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')
});
}

4
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);
})
}
}
</script>

Loading…
Cancel
Save