tulz-app / laminext

Misc utilities and extensions for Laminar
MIT License
61 stars 15 forks source link

Can't get websockets to work on 0.15.0 #170

Closed efim closed 1 year ago

efim commented 1 year ago

Hello!

In trying to stream in websocket, I'm stuck on an error - somewhere in init-websocket: console log:

WebSocket connection to 'ws://0.0.0.0:5153/api/subscribe' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
$p_Lio_laminext_websocket_WebSocket__initWebSocket__V

When I print to console all "messages" from the websocket - all I get is:

PlanningPokerUrgh.scala:65 got state Error(io.laminext.websocket.WebSocketError$: WebSocket error)
(anonymous) @ PlanningPokerUrgh.scala:65
PlanningPokerUrgh.scala:65 got state Closed([object WebSocket],false)

I've checked with "websocat" - the server responds without a problem and I've checked with direct javascript connection hardcoded into "main.js" - I also receive the responses

It looks as though Laminext closes websocket before it reaches the server

this is how i create websocket

and the vite forwards it's standard "ws://0.0.0.0:5153/api/subscribe" request into "0.0.0.0:8080" port of the server which can be compiled and launched with sbt backend/assembly && java -jar ./backend/target/scala-3.2.0/backend-assembly-0.1.0-SNAPSHOT.jar

I'll try to privide a more minimal example than that whole repo ( at this commit )

I'm at a loss of what to try next to trouble shoot!

efim commented 1 year ago

P.S - i've downgraded laminar and laminex dependencies, but for some reason there's the same problem - direct javascript websocket connection from main.js works, but connection from scalajs - error's out immediately

got state Error(io.laminext.websocket.WebSocketError$: WebSocket error) PlanningPokerUrgh.scala:65:14 got state Closed([object WebSocket],false) PlanningPokerUrgh.scala:65:14

This raises chances of me not using the library in a correct way, Unfortunately I still have no idea what to do to fix things

efim commented 1 year ago

I've went searching for imports of laminext Websocket in other projects on github

So, I've tried to do instead of

  val roomStateWSStreamBad = io.laminext.websocket.WebSocket
    .url("ws://0.0.0.0:5153/api/subscribe")
    .string
    .build(
      managed = true,
      autoReconnect = false,
      reconnectDelay = 1.second,
      reconnectDelayOffline = 20.seconds,
      reconnectRetries = 1
    )

init websocket as

  val roomStateWSStreamGood = io.laminext.websocket.WebSocket.path("/api/subscribe").string
    .build(
      managed = true,
      autoReconnect = false,
      reconnectDelay = 1.second,
      reconnectDelayOffline = 20.seconds,
      reconnectRetries = 1
    )

And things started to work. first attempts connection at Firefox can’t establish a connection to the server at ws://0.0.0.0:5153/api/subscribe.

and the second: ws://0.0.0.0:5173/api/subscribe

So the problem I was trying so solve so a couple of hours was in actuality misspelling of the port, sorry for the inconvenience, thank you for attention =0

! A good reason to use "path" instead of "url" !

yurique commented 1 year ago

Ouch, sorry you had to dig through this. Bug glad that it worked after all :)