Created
May 21, 2015 07:25
-
-
Save hansott/8c202ea808f0a0d32941 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
Thanks you bro