I am unable to emit events to rooms in my server application, using version 1.4.5
I tried these two ways to communicate in a room, but neither worked.
this.io.to(this.id).emit(eventName,data);
this.io.sockets.in(this.id).emit(eventName,data);
Before calling this, i register user in the room in this fashion
user.socket.join(this.id);
Further details
the this.io
object is require('socket.io')(http);
the user.socket
object is io.on('connection', function(socket)
I omitted the rest of the code because it is in overly complex structure and inheritance chain, and also irellevant to this question.
I dont necessarily require a code snippet to copy, rather a way how to debug and figure the issue out.
EDIT
When i pause the application at the moment when i want to emit the message, when I inspect the io
object, i get the following.
io -> nsps -> '/' -> adapter -> rooms -> theRoomName -> sockets
And my socket id is listed there.
Is there a way how to find out whether the message is actually being sent ?
EDIT #2
When I inspect the socket object, located at
io -> sockets -> sockets -> "socket id" -> rooms
the room id is present there as well
答案 0 :(得分:0)
根据您的要求对我的评论进行回答:
要确认的前四件事是:
this.io
的价值是什么,它应该是什么?this.id
的价值是什么,它应该是什么? eventName
? eventName
消息? 此外,您可以使用服务器调试程序跟踪到.emit()
并查看它实际上是否打算发送消息。
然后,您可以使用服务器上的网络跟踪(如WireShark或Ethereal)来验证服务器是否实际发送了消息。
然后,您可以使用Chrome调试器中的网络标签查看邮件是否实际到达浏览器页面。
PostScript:听起来上面的第4项是实际问题所在。