-
-
Notifications
You must be signed in to change notification settings - Fork 30
Inside event "close" cannot broadcast event. #63
Comments
It should broadcast to everyone, except the one who disconnected (which is relevant). Can you share, how exactly you are testing to know that the event is fired to all other connected clients? |
This is a script I created and included in template:
I'm had tried:
It's successfully fired event
And try closing one tab, the other's console didn't change anything! |
Yup, you are right, as soon as a socket disconnects. It is not able to send messages to other connected sockets. Lemme work on the fix. |
Hello, i'm newbie in JS, but i get that bug too. I interested was happening and started look at the source. Having found the function broadcast in Socket/index.js i see call makeEventPacket in current ws connection. Debug this before and after function call - understood that function broadcast stopping with execute makeEventPacket. In body function makeEventPacket (located in Connection/index.js) we see next if statement:
But, this if execute for broadcast and broadcastToAll functions every time. And if run broadcast or broadcastToAll inside onClose event - we already doesn't have this topic subscription and have If we comment on that if statement written above, broadcast will be work. PS: i hope that helps for fix this bug. |
@thetutlage was this resolved? Believe I have same issue |
+1 for this issue, any news about it? In socket.io, when a client closes the window, an event called |
When will this be fixed? |
…debug message replaced the error inside makeEventPacket to a debug message as this was blocking broadcasts from being sent when a socket connection was closed adonisjs#63
While you can't use the broadcast event inside close You should be able to use this method:
This should work as you're not broadcasting through the closed socket. According to the docs, this method can be used outside the scope of a socket. So, it should work even if the socket is closed |
I have a workaround on this to trigger the event upon disconnect, I used jona4life's code above and tweak it a little bit:
If anybody is needing this or stumble upon this. |
I have recently update my code base from AdonisJS version 3.2 to the latest. With much effort, everything working right, but not new
or
package.
With old code base, a code like this should working:
As the code above, whenever socket connection disconnect (close browser, ...), other socket connection would be notified by event
closing
. But, with a new code base:With event mapping from
disconnect
toclose
, andexceptMe().emit()
tobroadcast()
, it doesn't work anymore. On the server, eventclose
still be fire, but socket likely to not function anymore, so client could not receiveclosing
event? I guess that this happened due to prevent not necessary emit when socket is going to be closed, I tried to find out, but I'm not good at tweaking source code to find out the problem.My company project use AdonisJS, and my "boss" doesnt want to create a standalone socket server, so I must use builtin supported socket in AdonisJS. Please help me as soon as possible.
Thanks and best regard!
The text was updated successfully, but these errors were encountered: