M-Welsch / base-webapp

1 stars 0 forks source link

Reuse WebSocket object #15

Open jackyscript opened 1 year ago

jackyscript commented 1 year ago

Currently a new WebSocket object is created on each message of base-webapp to base-bcu. As a matter of fact this process is repeated each second:

This seems unnecessary and against the whole WebSocket concept, as an already established connection should be reused as long as reasonable. That would imply:

  1. Use the same object for sending and receiving messages
  2. After a connection lost, try to reconnect
  3. If the connection cannot be recovered, create a brand new connection

This issue does not affect and address the page change matter, i.e. after changing or refreshing the page, the whole JS context - the WebSocket object included - is destroyed and created again. This is matter of concern in issue #16.

jackyscript commented 1 year ago

Caveat: As the time of writing the base-bcu server implementation automatically closes the websocket connection after sending a message.

See the following link for further information and also the existing issue in the base-bcu-repository.