- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
在this guide的帮助下,我正在尝试建立一个套接字聊天。快完成了,但是用户无法加入其他房间。下面的代码是我的“加入房间功能”:
client.on("joinRoom", function(id) {
var room = rooms[id];
if (client.id === room.owner) {
client.emit("update", "You are the owner of this room and you have already been joined.");
} else {
room.people.contains(client.id, function(found) {
if (found) {
client.emit("update", "You have already joined this room.");
} else {
if (people[client.id].inroom !== null) { //make sure that one person joins one room at a time
console.log("User is already in a room");
client.emit("update", "You are already in a room ("+rooms[people[client.id].inroom].name+"), please leave it first to join another room.");
} else {
room.addPerson(client.id);
people[client.id].inroom = id;
client.room = room.name;
client.join(client.room); //add person to the room
user = people[client.id];
socket.sockets.in(client.room).emit("update", user.name + " has connected to " + room.name + " room.");
client.emit("update", "Welcome to " + room.name + ".");
client.emit("sendRoomID", {id: id});
}
}
});
}
});
当用户尝试加入某人的房间时,该功能会在“更新”处停止,通知用户已经在房间中。这是为什么?
最佳答案
问题是!==。
改变
if (people[client.id].inroom !== null) {
至
if (people[client.id].inroom != null) {
undefined !== null 给你的是 true,但你本质上希望 undefined 表现得好像它等同于 null。 !== 实际上会将它们视为单独的,而 != 会将它们视为等效的,这就是您想要的。
关于javascript - 如何加入socket聊天室,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43512319/
我有聊天应用程序,可以一对一发送消息(fromId/toId)。我想升级它的聊天室。我怎样才能做到这一点? ChatingRoom 需要什么数据库结构?我还需要做什么? 我的 User.swift 模
本文实例讲述了python socket多线程通讯方法。分享给大家供大家参考,具体如下: ?
我正在使用简单的套接字连接创建一个聊天室。我有一个服务器和客户端程序。服务器在端口 225 上运行,然后当我在端口 225 上运行客户端以便它们可以读/写套接字时,客户端立即停止并显示错误消息 jav
我可以创建一个粘液室。但是如果我将房间名称指定为数据库中现有的房间名称,服务器会拒绝它。那么是否可以在 ejabberd 服务器(MYSQl 后端)中创建两个具有相同名称的房间? 如果可能的话,后果是
我正在尝试使用 PHP 创建一个聊天室(顺便说一句,它正在工作),但只显示消息,而不显示他们的用户名。我已经为他们创建了数据库、用户名和消息。我不知道为什么他们的用户名没有显示 ".$extract[
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
我想在我的应用程序中实现群聊,为此我正在使用 MUC 聊天室来实现它。 在这里,我想向房间添加一个成员列表(我有 JID)。我想在内部将它们添加到列表中的所有成员。我如何在不邀请他们的情况下添加他们。
我正在尝试在 Rails 中创建类似 Whatsapp 的消息应用程序服务器端,并进行私有(private)对话。现在,我正在尝试实现应用程序的实时部分 - 我正在使用 websocket-rails
我正在尝试为我的网站制作一个 PHP/JavaScript 聊天系统。如何在不刷新页面的情况下做到这一点? JavaScript 可以:--动态添加文本到文本框。 PHP 可以:--将聊天内容保存到聊
我已经为多个客户端完全开发了一个聊天室,其多线程服务器可以完成这项工作,但仅限于我的本地计算机。我想超越这个,让这个聊天室通过互联网工作。到目前为止,我已经在路由器上对 TCP 协议(protocol
我是 Angular 的初学者,我正在尝试构建一个聊天室应用程序,以此自学如何在该框架中进行开发。 我在后端使用 PHP 和 Yii 将 RESTful 数据发送回 Angular 应用程序。我知道我
我正在寻找好的建议来制作这个聊天室: 使用 Java Swing。我已经尝试了所有 java swing 组件 3 天,但我仍然不知道该选择什么。 容器还必须插入 JprogressBars 以进行文
嗨,我正在努力让两件事同时工作...... channels2 chat room例子可以开始,但我想添加一个功能,知道房间里有多少人。我通过更新房间模型来做到这一点。 然后我想要一个仪表板来显示当前
我正在编写一个需要持久存储对话的多聊天室应用程序(即新用户应该能够看到旧消息)。如果有帮助,我正在使用 socket.io。 目前,当用户登录到一个房间时,我的 Node 应用程序会检查是否有人去过那
我试图扩展doc中关于TCP的代码来制作一个简单的聊天室,简单地说,几个客户端连接到服务器,一个客户端发送一个字符串,服务器将字符串广播给所有客户端......我写的代码显示下面,它不起作用,有人可以
如何在 Microsoft-Teams 中自动向聊天室发布消息?这是用于单向消息传递:即发布消息,而不是阅读消息。 这里的大局是我们正在评估不同的群聊解决方案,其中一项要求是从各种服务和程序向聊天室发
我创建了一个小型的 jquery 和 php 聊天室,其中包含一些 .get 和 .post 函数以及用于将数据读写到 sql server 的 php 文档。它工作正常,但小问题是当有人发布一些东西
我想实现的是自动下载附件功能,无需进入 ChatRoom,使用 QuickBlox SDK iOS 版本 2.0.12, 为此,我想在登录后启动用户所属的所有对话框(聊天室)。 使用当前的 API,用
所以我有聊天室工作所以如果收件人是 All 或 ALL 它广播我有这个工作所以如果你的名字是'Sam'它发送它与“私有(private)消息:”文本我不知道如何检查用户名的花名册并将其私下发送给该用户
我正在尝试创建基于移动设备的聊天应用。 基本上,我希望用户使用他们的 Facebook 帐户连接到 Facebook(使用 XMPPFramework) 我想要预先存在的房间供用户加入。我注意到 XM
我是一名优秀的程序员,十分优秀!