Skip to content

Instantly share code, notes, and snippets.

@aklinkert
Last active January 14, 2019 19:42
Show Gist options
  • Save aklinkert/8660031 to your computer and use it in GitHub Desktop.
Save aklinkert/8660031 to your computer and use it in GitHub Desktop.
Log all Sockets Events of an socket.io client
// pre 1.0
(function() {
var emit = socket.emit;
socket.emit = function() {
console.log('***','emit', Array.prototype.slice.call(arguments));
emit.apply(socket, arguments);
};
var $emit = socket.$emit;
socket.$emit = function() {
console.log('***','on',Array.prototype.slice.call(arguments));
$emit.apply(socket, arguments);
};
})();
//post 1.0
(function () {
var emit = socket.emit,
onevent = socket.onevent;
socket.emit = function () {
console.log('***', 'emit', Array.prototype.slice.call(arguments));
emit.apply(socket, arguments);
};
socket.onevent = function (packet) {
console.log('***', 'on', Array.prototype.slice.call(packet.data || []));
onevent.apply(socket, arguments);
};
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment