My preference is to not alter my sockets method. I was hoping to be able to utilize the io object within the connected function.
Could this be a possibility?
function sockets (server) {
const io = require('socket.io')(server);
io.sockets.on('connection', connected);
}
const connected = (socket) => {
socket.on('emit_to_all', data => {
emitToAll(socket, data);
// the same result could be achieved with
// io.emit('emit_to_all', data);
});
};
I searched on the github page here but none of the initial examples had a named callback function.
I stumbled upon the necessary documentation here.
Lastly, for details about the API, look at the documentation here.