r/AskProgramming • • 1d ago

WebRTC on localhost?

For a personal project, I needed to create a video call and screen sharing service, but to avoid paying for a server, I was wondering if it’s actually possible to run the server on localhost and have the other person connect through a Cloudflare tunnel. Do you know if this is possible? How feasible is it, and what problems might arise?

0 Upvotes

5 comments sorted by

3

u/Individual-Flow9158 1d ago

You both can just use public STUN servers to find each other. Or there are loads of free VPSs, container runners, and lambdas, that are more than enough to help you find each other and make the initial connection.

The whole point of WebRTC is the peer-to-peer connection should be possible from anywhere to anywhere, even behind NAT. Cloudflare tunnels might well work, but I'd double check they forward all the ports and protocols required, and I think they're just an extra moving part anyway.

3

u/KingofGamesYami 1d ago

WebRTC I believe requires a valid TLS certificate. So you wouldn't be able to initiate a connection to a random computer easily. You'd need to issue a TLS certificate for the host and trust that certificate's authority on the client.

2

u/snap-dev 1d ago

yeah that works fine for a personal project. once the call is set up webrtc is peer to peer, so your localhost box mostly just handles signaling and a cloudflare tunnel is ok for that. the catch is nat: if either person is on a strict network the direct connection fails and you need a turn server to relay the video, which is the part that costs money. a free public stun server covers most home setups though.

2

u/mgruner 1d ago

if you are giving your peer access to you localhost then avoid all the turn and stun server complexity and stream directly to them using the localhost ICE candidate.

2

u/karolisrusenas 7h ago

Since you're trying to avoid paying for a server, you can skip signaling entirely for testing. Just paste the offer and answer SDPs between you and your friend over chat. Wait until ICE gathering completes before copying, or you'll only have local candidates in there. fwiw I built Webhook Relay, it does these localhost tunnels too, no open ports needed.