-
-
Save sorah/3683181 to your computer and use it in GitHub Desktop.
listen to any events on socket.io / node EventEmitter; public domain own your risk
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') | |
, HTTP = require('http'); | |
var orig_emit = SocketIO.Socket.prototype.$emit // http://nodejs.org/api/events.html#events_emitter_emit_event_arg1_arg2 | |
SocketIO.Socket.prototype.$emit = function() { | |
orig_emit.apply(this, arguments) | |
var args = Array.prototype.slice.call(arguments); | |
var event = args.shift(); | |
orig_emit.apply(this, ['anything', event, args]); | |
}; | |
var app = HTTP.createServer(function (request, response) { | |
response.writeHead(404, {}); | |
response.end(''); | |
}); | |
app.listen(config.app); | |
var io = SocketIO.listen(app); | |
io.sockets.on('connection', function (socket) { | |
socket.on('anything', function (event, args) { | |
console.log("event: ", event, args); | |
}); | |
}); |
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
(function() { | |
var orig_emit = SocketIO.Socket.prototype.$emit // http://nodejs.org/api/events.html#events_emitter_emit_event_arg1_arg2 | |
SocketIO.Socket.prototype.$emit = function() { | |
orig_emit.apply(this, arguments) | |
var args = Array.prototype.slice.call(arguments); | |
var event = args.shift(); | |
orig_emit.apply(this, ['anything', event, args]); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment