Created
May 22, 2014 20:52
-
-
Save dorfire/3ec749a6acce106a3484 to your computer and use it in GitHub Desktop.
Revisions
-
dorfire created this gist
May 22, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ const SOCKETIO_LISTEN_PORT = 81; const PG_CONNECTION_STRING = 'postgres://dor@localhost/app'; const PG_NOTIFICATION_CHANNEL = 'notifications'; var pg = require('pg'), sio = require('socket.io').listen(SOCKETIO_LISTEN_PORT); var db = new pg.Client(PG_CONNECTION_STRING); db.connect(); sio.sockets.on('connection', function(socket) { socket.on('join', socket.join); }); db.on('notification', function(data) { var model = JSON.parse(data.payload); var room = 'event_'+ model.event_pk; console.log('emitting notification #%d to room "%s"', model.pk, room); sio.sockets.in(room).emit('notification', model); }); db.query('LISTEN ' + PG_NOTIFICATION_CHANNEL);