How to listen to internal ping pong of socket.io

1.8k Views Asked by At

I font this solution to listening the internal ping pong. Internal library of Socket.io i.e. engine.io triggers the 'heartbeat' event after sending pong event to client. you can listen to this event using following hack.

I tried to override the socket.io in new file but it not work. currently following code works for me.

1

There are 1 best solutions below

0
On

You can use following code also, without overriding the internal working.

socket_io = require('socket.io');

io = socket_io.listen(server, {pingTimeout : 60000, pingInterval : 15000});

//Listening to heartbeat of internal socket ping pong
io.engine.on('connection', function(socket_conn) {

    socket_conn.on('heartbeat', function(){

        manager.resetTimer(socket_conn.id);

    })
});