There are a few ways to solve this. It depends on how you want to use the actual module. Only one instance for every socket, or one for each socket. I suggest you make your module return a constructor instead of an object literal, like below:
module.exports = function(socket) {
var socket = socket;
this.refresh = function (msg) {
socket.emit('refresh', { message: msg });
}
this.lock = function (msg) {
socket.emit('lock', { message: msg });
}
}
Then you can create new objects containing the actual socket.
var Period = require('./server/functions/period.js'),
period = new Period(socket);
One solution would probably be to do this with every connecting socket.
var periodModule = require('./server/functions/period.js'),
io.on('connection', function(socket){
var period = new periodModule(socket);
//make a call
period.refresh();
});
You could also pass the io object in to your module to get the broadcasting interface as well.
module.exports = function(socket, io) {
var socket = socket,
io = io;
this.broadcastSomething = function(..) {
io.emit('data', { data: 'data'});
}
this.refresh = function (msg) {
socket.emit('refresh', { message: msg });
}
this.lock = function (msg) {
socket.emit('lock', { message: msg });
}
}