简体   繁体   English

在node.js / socket.io中-哪个插槽(如果有)在“房间”中?

[英]in node.js / socket.io - which sockets, if any, are in a “room”?

in socket.io , if I have a room abc , it there a way of knowing if anyone is in the room, for example, getting an array of sockets that have joined a room? socket.io ,如果我有一个房间abc ,它有一种知道房间中是否有人的方法,例如,获取joined房间的套接字的数组?

for example, in fantasy football. 例如,在幻想足球中。 admin input changes the Payton Manning record in the database. 管理员输入更改数据库中的Payton Manning记录。 a table trigger sees the change his status, so Postgres sends a notification to the node.js app. 表格触发器会看到其状态更改,因此Postgres将通知发送到node.js应用程序。 on being notified at the app level, we wish to display Manning's stats to anyone who has drafted Manning and is online, that is, in the Peyton Manning room. 在收到应用级通知后,我们希望向起草Manning并在线(即在Peyton Manning会议室)的任何人显示Manning的统计信息。

if no one is in the room, do not wish to do the database query, since it's pretty expensive. 如果房间里没有人,则不希望执行数据库查询,因为这非常昂贵。 otherwise will do query the db and send the stats to everyone in the room. 否则将查询数据库并将统计信息发送给会议室中的每个人。

那就是我在聊天应用程序中所做的

var sockets = io.sockets.clients(channel); /*channel = room*/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM