在nodejs的io中的io.sockets.adapter.rooms在哪里? [英] Where is io.sockets.adapter.rooms in io of nodejs?

查看:64
本文介绍了在nodejs的io中的io.sockets.adapter.rooms在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

https://stackoverflow.com/a/6727354/462608

简短答案:
io.sockets.adapter.rooms

The short answer:
io.sockets.adapter.rooms

我分析了io:

该答案中所示的io的套接字输出部分包含以下内容:

The sockets output part from io as shown in that answer contains the following:

sockets: 
   { manager: [Circular],
     name: '',
     sockets: { '210837319844898486': [Object] },
     auth: false,
     flags: { endpoint: '', exceptions: [] },
     _events: { connection: [Function] } },

适配器在哪里?房间在哪里?

io 的输出中找出适配器和房间的方法是什么?

What is the way to find out adapter and rooms from the output of io?

推荐答案

我认为您正在尝试获取空间,然后再加入.首先,您必须加入会议室,然后才能在 io.sockets.adapter.rooms 中获得会议室.您可以签出

I think you are trying to get room before joining it. First You have to Join room and than you can get the rooms in io.sockets.adapter.rooms You can checkout this link to know rooms


let room_id = 111

io.sockets.on("connection", function (socket) {
    // Everytime a client logs in, display a connected message
    console.log("Server-Client Connected!");
    socket.join("_room" + room_id);
    socket.on('connected', function (data) {

    });
    console.log(io.sockets.adapter.rooms);
    socket.on('qr_code_scan', function (room_id) {
        io.sockets.in("_room" + room_id).emit("qr_code_scan", true);
    });
});

io.sockets.adapter.rooms

{bjYiUV5YZy54VedKAAAA: Room, _room111: Room}
app.js:55
_room111:Room {sockets: {…}, length: 1}
length:1
sockets:{-isBAZIB-Sm3jArgAAAB: true}
-isBAZIB-Sm3jArgAAAB:true
__proto__:Object
__proto__:Object
-isBAZIB-Sm3jArgAAAB:Room {sockets: {…}, length: 1}
length:1
sockets:{-isBAZIB-Sm3jArgAAAB: true}
-isBAZIB-Sm3jArgAAAB:true
__proto__:Object
__proto__:Object
__proto__:Object

这篇关于在nodejs的io中的io.sockets.adapter.rooms在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆