openhab / openhab-cloud

Cloud companion for openHAB instances
Eclipse Public License 2.0
314 stars 162 forks source link

Proxy WebSocket connections #447

Open GiviMAD opened 7 months ago

GiviMAD commented 7 months ago

Hello, these is a proposed PR to allow proxy WebSocket connections to the OpenHAB instances, to the endpoints exposed under path /ws/.

With the PR, the code catches the upgraded response headers and setup the required listeners on the request Socket in order to transfer the incoming data through the Socket.IO connection to the destination server using the "websocket" event. Also handles the "websocket" events from the remote server and write the received data to the socket.

I have also changed the responses like res.send(200, '...'); to be res.status(200).send('...'); because I saw deprecation warnings when running the project using docker-compose.

These PR needs changes in the Cloud Connector add-on.

digitaldan commented 7 months ago

Hi @GiviMAD just wanted to let you know I plan on reviewing this soon, possible this weekend. Thanks!

GiviMAD commented 7 months ago

Thank you @digitaldan I was to write you the other day but I saw the message a little late. Hope everything is in place.

I have added a small change in the last commit using "process.nextTick" to write the pending socket data, because I think it will behave a little better when handling multiple clients.