In the postgresql database there is a table "alarm", a kind of alarm panel. I need to display the appearance of new events in real time. With the help of the socket.io library, I was able to display notifications about new events, but I need to, that the entire database was unloaded when I started, but in my case this does not happen, please tell me how best to implement it.
app.js`
var io = require('socket.io').listen(9999); var pg = require ('pg'); var con_string = 'postgres://username:password@localhost/dbname'; var pg_client = new pg.Client(con_string); pg_client.connect(); var query = pg_client.query('LISTEN alarmevent'); io.sockets.on('connection', function (socket) { socket.emit('connected', { connected: true }); socket.on('ready for data', function (data) { pg_client.on('notification', function(title) { socket.emit('update', { message: title }); console.log(title); }); }); });` index.html
WEB_SOCKET_SWF_LOCATION = 'inc/WebSocketMain.swf'; var socket = io.connect('http://localhost:9999'); socket.on('connected', function (data) { socket.emit('ready for data', {}); }); socket.on('update', function (data) { $('#future').append(data.message.payload + "<br/>"); });