-
-
Save clopezpro/7e9e12907a9ed0d7414a634d0641be83 to your computer and use it in GitHub Desktop.
Global socket.io in an application
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'); | |
var sockets = require('./sockets'); | |
var server = http.createServer(app); | |
sockets.connect(server); | |
sockets.emit('event', { message: 'This is an event!' }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment