3

I currently have the following in configuration for socket.io in my app.js file:

app
.configure(feathers.socketio(function(io){
    io.on('connection', function(socket){
        socket.emit('connect',{test: 'wow'});
        socket.on('createRecord', function(socket){
            analytics.service('record').create({type: socket.name, user: socket.interest}, function(error, user){
            });
        })
    })

}))

The above works fine, but is there a way to separate the socket.io logic from the app.js, as it will get very large as I continue on adding more emit and on methods. I am aware this can be done by passing the socket object into as an argument into a module in another file and using it from there. However, I am not sure how to proceed with that in feathersjs.

jumpr3
  • 125
  • 5

1 Answers1

3

If I'm understanding you correctly extracting

module.exports = feathers.socketio(function(io){
    io.on('connection', function(socket){
        socket.emit('connect',{test: 'wow'});
        socket.on('createRecord', function(socket){
            analytics.service('record').create({type: socket.name, user: socket.interest}, function(error, user){
            });
        })
    })

})

to ./socketsConfig and

var socketsConfig = require('./socketsConfig')
app.configure(socketsConfig);

will do the job.

sdespolit
  • 893
  • 8
  • 20