Skip to content

Instantly share code, notes, and snippets.

@hansott
Created May 21, 2015 07:25
Show Gist options
  • Save hansott/8c202ea808f0a0d32941 to your computer and use it in GitHub Desktop.
Save hansott/8c202ea808f0a0d32941 to your computer and use it in GitHub Desktop.
Global socket.io in an application
var http = require('http');
var sockets = require('./sockets');
var server = http.createServer(app);
sockets.connect(server);
sockets.emit('event', { message: 'This is an event!' });
var socketIO = require('socket.io');
var io = null;
module.exports = {
connect: function(server) {
io = socketIO(server);
},
emit: function(event, values) {
if (io) {
io.sockets.emit(event, values);
}
}
}
@clopezpro
Copy link

Thanks you bro

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment