javascript - socketio 无法创建空间
问题描述
我正在尝试动态创建一个房间。我得到一个 id,这将是房间的名称。在回调中,我看到正在使用的房间列表,io.sockets.adapter.rooms
但没有看到我加入的房间。
io.of('/chat').on('connection', (socket) => {
const socketQuery = socket.handshake.query;
if(socketQuery.action === 'createRoom' && socketQuery.doctorUserId){
console.log("Creating room", socketQuery.doctorUserId);
socket.join("A ROOM", () => console.log(io.sockets.adapter.rooms)); //I want the id here to be the name of the room
}
我试图只给出一些文本(A ROOM),但仍然没有在回调中看到房间名称。
我在 console.log 中看到了这个:
Creating room 5e972498125a3d1488d0985f
{ 'tHlX-TYkQeVlxEB9AAAA': Room { sockets: { 'tHlX-TYkQeVlxEB9AAAA': true }, length: 1 } }
Creating room 5e972498125a3d1488d0985f
{ pZe_38mllgVtSUfrAAAB: Room { sockets: { pZe_38mllgVtSUfrAAAB: true }, length: 1 },
'7oZdWV9mwvuhnvQTAAAC': Room { sockets: { '7oZdWV9mwvuhnvQTAAAC': true }, length: 1 } }
编辑如果我不使用命名空间而只加入它,它就可以工作。我究竟做错了什么
解决方案
推荐阅读
- javascript - 间歇性引用错误:$ 未定义
- ionic-framework - Ionic AudioToggle 插件如何使用?
- terraform - Terraform“无法计算'count'的值:为什么?
- python - 如何从列表中输出元素以及它们在文档中出现的次数?
- spring-integration - Spring集成Java DSL:如何在一个集成流运行中共享标头变量
- python - 您传递给模型的 Numpy 数组列表不是模型预期的大小。预计会看到 2 个数组
- javascript - 使用 FB.ui 在 facebook 上分享重定向到 facebook 游戏?
- ios - Swift UITest在tableviewcell中找不到collectionview
- ios - 如何从本地领域数据库恢复数据?
- angular - Center Mat-Menu,Center MatMenu Overlay to Button