node.js - socket.io: client receive all incoming messages into a single function -
i using socket.io 1.2.0 . in client browser how receive events in single listener
socket.on("*",fuction(event,data){ });
my previous implementation not working after uploaded 0.9 ....
my previous hack receive events
var original_$emit = getsocket().$emit; getsocket().$emit = function () { var args = array.prototype.slice.call(arguments); original_$emit.apply(getsocket(), ["*"].concat(args)); if (!original_$emit.apply(getsocket(), arguments)) { original_$emit.apply(getsocket(), ["default"].concat(args)) } };
this not perfect solution working fine....
code changes server socket.io
/node_modules/socket.io/lib/socket.js
in line no: 128
if (~exports.events.indexof(ev)) { emit.apply(this, arguments); }
change
if (~exports.events.indexof(ev)) { var arg = ["*",arguments]; emit.apply(this, arg); }
in line no: 328
emit.apply(this, args);
change
args.splice(0, 0, "*"); emit.apply(this, args);
example:
var io = require('socket.io')(server); io.on('connection', function (socket) { socket.on('*', function (event, data) { }); });
code changes socket.io (browser javascript node.js app);
node_modules/socket.io/node_modules/socket.io-client/socket.io.js
in line no: 724
emit.apply(this, arg);
change
var arg = ["*",ev]; emit.apply(this, arg);
in line no: 847
if (this.connected) { emit.apply(this, args); }
change
if (this.connected) { args.splice(0, 0, "*"); emit.apply(this, args); } var arg = ["*",ev];
example:
var socket = io(); socket.on("*", function (event, data) { });
code changes require('socket.io-client') (node.js app node.js app);
/node_modules/socket.io-client/lib/socket.js
in line no: 129
emit.apply(this, arguments);
change
var arg = ["*",ev]; emit.apply(this, arg);
in line no: 253
if (this.connected) { emit.apply(this, args); }
change
if (this.connected) { args.splice(0, 0, "*"); emit.apply(this, args); } var arg = ["*",ev];
example:
var io = require('socket.io-client'); var socket = io(url,{}); socket.on("*", function (event, data) { });
Comments
Post a Comment