You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
close(ws){constmsg=`${ws.data.username} has left the chat`;ws.unsubscribe("the-group-chat");ws.publish("the-group-chat",msg);// 🔴 this message should get published to the topic and other subscribers should get this}
What do you see instead?
The message doesn't get published. 😕
I ran some tests and also checked the return value of the publish method.
seems like it returns a number
(3+ message length) : when it successfully publishes the message and
0: if the message is not published.
Message is not published if there is only one user subscribing to the topic and it is the sending user himself, which is OK.
but I tried with 2 and 3 users connected, and that publish line always returned 0, and the message in the close callback never gets published, so no one got to know that some user disconnected from chat.
Additional information
No response
The text was updated successfully, but these errors were encountered:
RohitKaushal7
changed the title
websocket not publishing to topic after connection close.websocket not publishing to topic after connection close.
Oct 24, 2023
But need to fix this in the docs here https://bun.sh/docs/api/websockets#pub-sub to clarify that closed ws cannot publish. Also, is it required to call ws.unsubscribe('topic') in the closed callback, does it not automatically get unsubscribed if the connection is closed?
What version of Bun is running?
1.0.7
What platform is your computer?
Linux 5.10.102.1-microsoft-standard-WSL2 x86_64 x86_64
What steps can reproduce the bug?
just create a simple websocket chat application as described in the documentation.
https://bun.sh/docs/api/websockets#pub-sub
What is the expected behavior?
What do you see instead?
The message doesn't get published. 😕
I ran some tests and also checked the return value of the publish method.
seems like it returns a number
Message is not published if there is only one user subscribing to the topic and it is the sending user himself, which is OK.
but I tried with 2 and 3 users connected, and that publish line always returned 0, and the message in the close callback never gets published, so no one got to know that some user disconnected from chat.
Additional information
No response
The text was updated successfully, but these errors were encountered: