Friday 2 June 2017

Socket.io emit to specific client in tabs

I am using socket.io with angular. It works fine but my problem is that it emits to all the tabs opened in Chrome. The current workflow is the app will be opened in multiple tabs to run different simulation. When i press the button (action) it updates all the opened tabs. However, i want to emit to specific tab. How do i design that? I looked at stackoverflow and github but couldnt get the socket.id to work.

Server Code

app.use(function(req, res, next) {
    var socketid = ''
    socketio.sockets.on('connection', function(socket) {
        socketid = socket.id

        res.socketid = socketid
            // 
    });
    res.socketio = socketio;
    next();
});

    console.log('sockrt ' + res.socketid)
    res.socketio.emit('pyr', output) //res.socketid is undefined



via Uma Maheshwaraa

No comments:

Post a Comment