Created
April 2, 2014 06:30
-
-
Save robwormald/9928928 to your computer and use it in GitHub Desktop.
socket.io $emit override
This file contains hidden or 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 original_$emit = socket.$emit; | |
| socket.$emit = function() { | |
| var args = Array.prototype.slice.call(arguments); | |
| original_$emit.apply(socket, ['*'].concat(args)); | |
| if(!original_$emit.apply(socket, arguments)) { | |
| original_$emit.apply(socket, ['default'].concat(args)); | |
| } | |
| } | |
| //catch untrapped events | |
| socket.on('default',function(event, data) { | |
| console.log('Event not trapped: ' + event + ' - data:' + JSON.stringify(data)); | |
| }); | |
| //catch ALL events | |
| socket.on('*',function(event, data) { | |
| console.log('Event received: ' + event + ' - data:' + JSON.stringify(data)); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment