最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Socket.on() listen for any event - Stack Overflow

programmeradmin2浏览0评论

I want to catch when any event, regardless of the name was sent from a socket. Is there some sort of wildcard I can use here for that?

io.on('connection', function (socket) {
    socket.on('any event', function (data) {
        ...
    });
});

I want to catch when any event, regardless of the name was sent from a socket. Is there some sort of wildcard I can use here for that?

io.on('connection', function (socket) {
    socket.on('any event', function (data) {
        ...
    });
});
Share Improve this question asked Aug 1, 2015 at 0:59 DarrenDarren 1,9945 gold badges23 silver badges35 bronze badges 1
  • 1 possible duplicate of Socket.io Client: respond to all events with one handler? – Zachary Kuhn Commented Aug 1, 2015 at 1:20
Add a ment  | 

2 Answers 2

Reset to default 3

u can use

socket.onAny((eventName, args...)=>{
//something
});

https://socket.io/docs/v4/listening-to-events/#socketonanylistener

you can use the wildcard plugin to listen to all events

http://socket.io/docs/faq/ https://github./hden/socketio-wildcard

发布评论

评论列表(0)

  1. 暂无评论