question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

There needs to be a wildcard feature in event handling

See original GitHub issue

Note: 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

http://stackoverflow.com/questions/32552155/how-do-i-handle-all-incoming-socket-events-rather-than-a-specific-one

http://stackoverflow.com/questions/32552481/did-the-socket-io-global-event-end-up-in-release?noredirect=1#comment52961409_32552481

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:closed
  • Created 8 years ago
  • Comments:22 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
viziionarycommented, Feb 25, 2016

Yeah I have no idea why Socket.io devs are still ignoring this / refusing to implement it natively.

1reaction
viziionarycommented, Dec 14, 2015

Also, many people seem to agree that this should be a native feature.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found