#Websocket broadcast
1 messages ยท Page 1 of 1 (latest)
either socket.publish() or server.publish()
oh thanks!
ok... I'm having some weird stuff going on, maybe it's normal and I'm just noob on this...
I've setup a websocket server to broadcast data to all connected clients when a clients connect (open(ws){ws.publish('channel',MESSAGE)})...
the issue happens when the client loses connection to the websocket server, I setup a reconnection code (socket.onclose = (e)=>{ socket = new Websocket(ADDR) }), so it should make the server publish the set MESSAGE, but it doesn't get to any clients that have reconnected without reloading the page... that's the thing I don't understand... the webpage must be reloaded for it to receive the broadcast or message... ๐ค
did you subscribe that client to topic after reconnect?
and ws.publish() skips itself when broadcasting
yeah, I set it up to open(ws){ws.subscribe(CHANNEL);ws.publish(...)} and close(ws,c,m){ws.unsubscribe(CHANNEL)} ๐ค
is it because I'm unsubscribing them?
they should subscribe again, no?
did you rebind .onmessage handler on your clients?
socket = new Websocket() creates completely new client that has no onmessage listener attached
yeah... I just realized that I did rebind the "onclose" but the "onmessaage" ๐ซ
(including all other events like .onclose and so on)
yeah... that was the issue... ๐ thanks and sorry for the time...
always here to help
btw, is it the same to use socket.onmessage and socket.addEventListener('message', callback)??
oh ok... just wanted to be sure...