Let websocket listen to all DB notification channels

This commit is contained in:
D. Berge
2020-10-02 00:39:53 +02:00
parent 902338f835
commit 746e3405fb

View File

@@ -3,6 +3,13 @@ const URL = require('url');
const db = require('./db'); const db = require('./db');
function start (server, pingInterval=30000) { function start (server, pingInterval=30000) {
const channels = [
"realtime", "event", "project",
"preplot_lines", "preplot_points",
"raw_lines", "raw_shots",
"final_lines", "final_shots"
];
const wsServer = new ws.Server({ noServer: true }); const wsServer = new ws.Server({ noServer: true });
wsServer.on('connection', socket => { wsServer.on('connection', socket => {
@@ -21,7 +28,7 @@ function start (server, pingInterval=30000) {
} }
}); });
db.listen(["realtime", "event", "project"], (data) => { db.listen(channels, (data) => {
wsServer.clients.forEach( (socket) => { wsServer.clients.forEach( (socket) => {
socket.send(JSON.stringify(data)); socket.send(JSON.stringify(data));
}) })