There needs to be a wildcard feature in event handling
See original GitHub issueNote: The ‘anything’ event in docs can be confused as a global event, but of course isnt.
There should exist something to the effect of:
socket.wildcard = 'myWildcardValue';
socket.on('myWildCardValue', function(eventName, data){
//handle all incoming events
}
See:
http://stackoverflow.com/questions/10405070/socket-io-client-respond-to-all-events-with-one-handler
Because there’s no support for this, developers are having to modify Socket.io client side (note, the node.js patch for this is not applicable client side) with code like this:
var socket = io.connect();
var globalEvent = "*";
socket.$emit = function (name) {
if(!this.$events) return false;
for(var i=0;i<2;++i){
if(i==0 && name==globalEvent) continue;
var args = Array.prototype.slice.call(arguments, 1-i);
var handler = this.$events[i==0?name:globalEvent];
if(!handler) handler = [];
if ('function' == typeof handler) handler.apply(this, args);
else if (io.util.isArray(handler)) {
var listeners = handler.slice();
for (var i=0, l=listeners.length; i<l; i++)
listeners[i].apply(this, args);
} else return false;
}
return true;
};
socket.on(globalEvent,function(event){
var args = Array.prototype.slice.call(arguments, 1);
console.log("Global Event = "+event+"; Arguments = "+JSON.stringify(args));
});
Issue Analytics
- State:
- Created 8 years ago
- Comments:22 (4 by maintainers)
Top Results From Across the Web
JQuery custom event handler with wildcard in the event name
I have been trying to implement a wildcard name ...
Read more >ARCHIVED: What is a wildcard, and how can I use it? - IU KB
The asterisk represents any number of unknown characters. Use it when searching for documents or files for which you have only partial names....
Read more >Use of a wildcard in the source definition on Windows Event Log
aLTeReGo - curious to know if there has been any progress on the internal request (FB188190) for wildcards in the source definition on...
Read more >Supporting Wildcard Characters in Cmdlet Parameters
Windows PowerShell Cmdlets That Use Wildcards. Many Windows PowerShell cmdlets support wildcard characters for their parameter values.
Read more >EventEmitter2/EventEmitter2: A nodejs event emitter ... - GitHub
A nodejs event emitter implementation with namespaces, wildcards, TTL, works in the browser - GitHub - EventEmitter2/EventEmitter2: A nodejs event emitter ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yeah I have no idea why Socket.io devs are still ignoring this / refusing to implement it natively.
Also, many people seem to agree that this should be a native feature.