During development, it helps me a lot to see which packets arrive and go. This is possible on the server side using the registrar. However, there is no registrar on the client side. I find that console.log trash is all over the place.
Is it possible to override socket.emit and socket.on using console.log (arguments)? If I can override this on my socket, it will be very elegant.
Someone advised me to override the Parser instead.
What are your 2cents on this?
EDIT
I tried Kato's suggestion and wrote the following:
var _origEmit = socket.emit; socket.emit = function() { console.log("SENT", Array.prototype.slice.call(arguments)); _origEmit.call(socket, arguments); };
It works. However, not much with socket.on. My strategy is to wrap each callback with console.log. If you know python, it is like putting function decorators on callbacks that have console.log arguments.
(function(socket) { var _origOn = socket.on; socket.on = function() { var args = Array.prototype.slice.call(arguments) , handlerType = args[0] , originalCallback = args[1]; var wrappedCallback = function() {
Can anyone point out why the monkey patching socket.on is not working?
disappearedng Jan 12 '12 at 9:05 2012-01-12 09:05
source share