List of namespaces in socket.io

谁都会走 提交于 2019-12-24 01:49:11

问题


Is there any way to get a list of all the namespaces registered on the socket?

For example, suppose some client connects to a namespace: `socket = io('/some-nsp');

They are now in a namespace automagically because the socket.io does not prevent creating random namespaces.

If I want to go through the list of all existing namespaces and disconnect those users, how could I get such a list.

I've tried io.nsps, but this just is a circular list of junk.

Is there an "official" way to get a list of all the namespaces registered on the socket? I don't want a list of clients. I just want a list of namespaces.


回答1:


You may try this:

Object.keys(io.nsps);


来源:https://stackoverflow.com/questions/25081622/list-of-namespaces-in-socket-io

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!