#Bun WebSocket Pub/Sub

1 messages · Page 1 of 1 (latest)

native glen
#

Hi guys, im trying the pub/sub methods in the websocket and whenever i make a socket.publish() its not received on the frontend and im getting "0" as a response to the publish request.

However, when i run a simple ws.send() (no pubsub, just regular ws) it works perfectly.
is there something different i need to do for the publish method? I followed the example on the https://bun.sh/docs/api/websockets page word by word 😦

small quarry
#

ws.publish() doesn't broadcast to itself

#

if you want to publish to everyone with no exceptions then use server.publish()

steel drum
#

try creating two websockets in two separate tabs if you want verification that this is working

native glen
steel drum
#

its still not getting reiceved correctly
feel free to open a new thread w/a code example if you at experiencing another bug unrelated to .publish()
apologies, if you already did that, I'm still going through everything

slim helm
small quarry
#

docs could go a little bit more into detail about it

steel drum
#

i added more detail earlier today

cold jewel
small quarry
#

it’s supposed to be server.publish

#

socket is dead when close is called

cold jewel
#

I see, thanks

small quarry
#

can’t send any messages through dead socket

#

you also don’t need to do .unsubscribe in close