Public URL and Socket.io

Hello! Has anyone successfully communicated between client browser and Socket.io server running on Balena device (Raspberry Pi in this case) over public URL?

I have working local websocket connection (ws://), but now I need to access camera from browser with WebRTC and it requires encrypted connection. Long polling https connection to public URL returns “bad request” and wss connection throws error: “WebSocket connection to ‘wss://UUID.balena-devices.com/socket.io/?EIO=4&transport=websocket&sid=gCPktkkfTuZxD3oMABDA’ failed: WebSocket is closed before the connection is established.”

RPi has Caddy container listening :80 and reverse proxying to Socket.io server.

Hi @emalinen , I have managed to communicate between a client browser and socket.io server running on a Balena device (over RPi) over a public url. Although, in my case I did not require a secure connection. A clarifying question: Is the browser and camera which you are trying to access connected to your Raspberry Pi or is it hosted elsewhere?

Browser and camera is on a client device (pc, smartphone). Frontend React app is used for reading QR codes. I’m using react-qr-reader, which works flawlessly when using unencrypted localhost connection. But when the app is served from Raspberry Pi with static IP in the local network, browser blocks access to getUserMedia() function for privacy reasons. Camera feed is not sent anywhere over the unsecure network, only content of the QR code is sent to RPi.

Public url would be easy way to create encrypted connection, but I have not yet figured out why it does not work.

This was a CORS problem caused by Socket.io server. Adding “balena-devices.com” as allowed origin solved the problem.

Detailed solution for Python server is here: How to fix "Access-Control-Allow-Origin" error in a python socket-io server - Stack Overflow

@emalinen I’m glad you found a solution! Thanks for sharing it here! Also, feel free to keep us updated on your project. You can share any updates on your project in our show and tell forums: Show and Tell - balenaForums .