RemoteDisconnect socket.io and redis

I am trying to implement socket.io with Redis adapter in NodeJs.

It mostly works, but sometimes I still get errors when trying to disconnect / connect sockets, so I think I haven't implemented it correctly.

Can someone please explain what is the difference between socket.disconnect();

andio.of('/').adapter.remoteDisconnect();

If I initialize my io with

io.adapter(redisIO({
   host: config.server.redis.host,
   port: config.server.redis.port,
   requestsTimeout: config.server.redis.request_timeout
}));

      

Shouldn't you then socket.disconnect();

know the use of redisIO? If on use remoteDisconnect

I can capture socket.on('disconnect', fn)

or should I be remoteDisconnect

called in socket.on('disconnect', fn)

?

What happens if a client disconnects? How can I propagate it to socket.io cluster?

Any working examples would be appreciated :)

Thank!

+4


source to share


1 answer


Capture the socket event disconnecting

instead disconnect

, then it's too late!



socket.on('disconnecting', () => {
  var room_name = sess.id
  io.of('/').adapter.remoteDisconnect(room_name, true, err => {
     delete socket.rooms[room_name]
     socket.removeAllListeners()
  })
})


      

0


source







All Articles