socket.rooms

  • (Object)

标识此socket所在房间的字符串哈希,按房间名称索引。

  1. io.on('connection',(socket)=>{
  2. socket.join('room 237',()=>{
  3. let rooms= Object.keys(socket.rooms)
  4. console.log(rooms); // [ <socket.id>,"room 237" ]
  5. })
  6. })