D
D
D_E_S2018-06-09 11:49:17
Node.js
D_E_S, 2018-06-09 11:49:17

How to return socket.io connections after disconnect output on page refresh?

I create a socket connection that breaks after a page refresh. If the server side is restarted, then connections are restored. How can disconnect be handled to return connections.
connection per client

socketio(window.location.hostname+':8000', {
    transports: ['polling', 'websocket'],
    reconnection: true,
    autoConnect: true,
    timeout: 50000
})

On server
let app = express();
/*...*/
server = app.listen(8000);
Socket.runConnection(server);
/*...*/

The socket itself
export class Socket {
/*....*/
public runConnection(app){
        this.io = socketIo(app,{
            reconnection: true,
            reconnectionDelay: 1000,
            reconnectionDelayMax: 5000,
            'sync disconnect on unload': true
        });
        this.io.adapter(sio_redis(RedisConfig));
        this.listen();
    }
public listen(){
        let self = this;
/*....*/
        this.io.on('connection', function(socket:SocketIO.Socket) {
            console.log(`connection ${socket.id}`);
            socket.on('disconnect', function (reason) {
/*....*/
            });
        });
    }
}

On the client side socket.connect(); Does not help.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question