Hi guys,
I have tried your socket.io example and found out that each rendering creates new presistent socket conection to the server. To reproduce it you shall change io.on in server.js as follows:
io.on('connection', (socket) => {
socket.on('last-messages', function (fn) {
fn(messages.slice(-50))
});
socket.on('send-message', function (message) {
messages.push(message)
socket.broadcast.emit('new-message', message)
});
console.log(Object.keys(io.sockets.clients().connected)); <-- new code
});
In the console you will see, that open connections list is growing on each page rendering.
I would like to ask if there is a way to listen to event when rendering is finished and run callback to close sockets connection?
The current solution i see is to use setTimeout(callback, 60*1000) for example.
<!--cmty--><!--cmty_prevent_hook--><div align="right"><sub><em>This question is available on <a href="https://nuxtjs.cmty.io">Nuxt.js</a> community (<a href="https://nuxtjs.cmty.io/nuxt/nuxt.js/issues/c784">#c784</a>)</em></sub></div>