Live data from Hacker News

Make any site multiplayer in a few lines. Serverless WebRTC matchmaking

oxism.com

41–50 of 71 posts

Re: Make any site multiplayer in a few lines. Serverless WebRTC matchmaking

#41
post #6

WOW this is cool! I love this, but as a nitpick, how scalable is it to do each connection peer to peer? Doesn't that mean that I have to keep a stream connection open for everyone who I want to include in the room?

> how scalable is it to do each connection peer to peer? I can tell you roughly how it works for webrtc video calls. If you're in a 5-person peer-to-peer webrtc video call where you receive 4 streams of video, you also need to send 4 streams of video. This is scalable in a sense; the uplink and downlink requirements are equal. The problem comes if you're in a 100-person meeting, and the application logic has hidden 9…

> If you're in a 5-person peer-to-peer webrtc video call where you receive 4 streams of video, you also need to send 4 streams of video. This is scalable in a sense; the uplink and downlink requirements are equal.

The issue is not with the throughput: a typical videoconference requires 700kbit/s per stream, so even 12Mbit/s upstream should be enough for 20 streams or so. The issue is with having to encode the video separately for every receiver.

WebRTC adapts to the available throughput by encoding the video separately for every receiver, with different parameters. If you're in a five-person peer-to-peer conference, you decode four videos simultaneously, which is fine, but you're also encoding your video four times, which is not.

An SFU works around the issue by not reencoding the video: the SFU merely decrypts the video and reencrypts it with the public key of every receiver. Since AES is implemented in hardware, the reencryption comes essentially for free.

(Of course, that implies that the SFU needs to use other techniques for bandwidth adaptation, such as simulcast or scalable video coding (SVC). See slides 10-12 of https://galene.org/galene-20250610.pdf if you're interested.)

Re: Make any site multiplayer in a few lines. Serverless WebRTC matchmaking

#42
post #25
post #24

Earlier quoted context omitted.

I didn't know about the QR-Code solution how does it work ?

Normally you need a "lobby" server that collects and lists available other clients and pass along connection details. You have no servers in P2P setup, so the "signaling" information has to be shared "out-of-band", like through QR code or super secret invite link or avian IPv4 or something.

wait but this should only work on locals / close networks shouldn't it ? i thought you still need some proxying in other cases (hence the turn) - i really need to study this again asap tough

Re: Make any site multiplayer in a few lines. Serverless WebRTC matchmaking

#43
post #8

This isn't serverless. It's just using someone else's servers for the SDP signaling. And in a production app you'd likely also need turn servers and maybe SFU servers. There are some true serverless approaches out there for the signaling, e.g. where both peers scan each other's QR code, but that obviously has very limited use.

You're not wrong! Serverless is a funny term. Cloud companies use serverless to mean you don't have to provision and manage the server yourself, but it is still very much serverful technically speaking. This is neat in that you don't even need to setup anything with a cloud provider yourself to enable p2p connections

I've always seen the distinction as "serverless" meaning there wasn't a set group of servers always on and instead they provision up and down on demand.

Only avoiding provisioning and managing the server just means you are renting rather than self-hosting.

Re: Make any site multiplayer in a few lines. Serverless WebRTC matchmaking

#45
post #42
post #25

Earlier quoted context omitted.

Normally you need a "lobby" server that collects and lists available other clients and pass along connection details. You have no servers in P2P setup, so the "signaling" information has to be shared "out-of-band", like through QR code or super secret invite link or avian IPv4 or something.

wait but this should only work on locals / close networks shouldn't it ? i thought you still need some proxying in other cases (hence the turn) - i really need to study this again asap tough

STUN gives back your public IP:port, TURN gives you assigned proxied IP:port.

You take that data and send to the peer over signaling connection, and they call you back on that IP:port. Most NAT implementations make and keep a temporary mapping between public port to private IP consistent[1] for few minutes, and not completely random per destination[2], so it usually works.

1: e.g. router.public.ip.example:23456 192.168.0.12:12345

2: e.g. if stun.l.google.com:12345 sent from port 23456 but if yourfriend.router.ip.example:12345 sent from port 45678

Re: Make any site multiplayer in a few lines. Serverless WebRTC matchmaking

#46
post #42
post #25

Earlier quoted context omitted.

Normally you need a "lobby" server that collects and lists available other clients and pass along connection details. You have no servers in P2P setup, so the "signaling" information has to be shared "out-of-band", like through QR code or super secret invite link or avian IPv4 or something.

wait but this should only work on locals / close networks shouldn't it ? i thought you still need some proxying in other cases (hence the turn) - i really need to study this again asap tough

Yes. Unless the party generating the QR code first obtains its external IP address by other means, which would still require some kind of echo server. Even then, ignoring outdated approaches like UPnP, a commonly accessible host would be needed to establish signalling with e.g. NAT hole punching for anything but the most basic of setups.

Re: Make any site multiplayer in a few lines. Serverless WebRTC matchmaking

#47
post #6

WOW this is cool! I love this, but as a nitpick, how scalable is it to do each connection peer to peer? Doesn't that mean that I have to keep a stream connection open for everyone who I want to include in the room?

When I experimented with this a few years back a true NxN room would cap around 8 people when using PCs and 4 on mobile, the bottleneck is encoding/decoding of the video. For larger rooms you need a server to route the video to all recipients, this is called an SFU. With an SFU you can have hundreds of participants, but not everyone can speak or be seen at once.

For audio-only the sky is the limit. I used to work on a voice-based social media and you also need an SFU here as well, but I added a few mixing features so that multiple incoming audio streams would be mixed together into a single outgoing one. Was very fun (and scalable).

Re: Make any site multiplayer in a few lines. Serverless WebRTC matchmaking

#48
post #8

This isn't serverless. It's just using someone else's servers for the SDP signaling. And in a production app you'd likely also need turn servers and maybe SFU servers. There are some true serverless approaches out there for the signaling, e.g. where both peers scan each other's QR code, but that obviously has very limited use.

You're not wrong! Serverless is a funny term. Cloud companies use serverless to mean you don't have to provision and manage the server yourself, but it is still very much serverful technically speaking. This is neat in that you don't even need to setup anything with a cloud provider yourself to enable p2p connections

[deleted]

Re: Make any site multiplayer in a few lines. Serverless WebRTC matchmaking

#49

Earlier quoted context omitted.

You're not wrong! Serverless is a funny term. Cloud companies use serverless to mean you don't have to provision and manage the server yourself, but it is still very much serverful technically speaking. This is neat in that you don't even need to setup anything with a cloud provider yourself to enable p2p connections

I've always seen the distinction as "serverless" meaning there wasn't a set group of servers always on and instead they provision up and down on demand. Only avoiding provisioning and managing the server just means you are renting rather than self-hosting.

The VPS is like renting office space. You don't own the space, but for the most part get to use it how you want, and all the responsibilities that come with that.

"Serverless" is like paying for a hot desk by the minute, with little control of your surroundings, but it is convenient and cheap if you only need it for an hour.

Re: Make any site multiplayer in a few lines. Serverless WebRTC matchmaking

#50
post #49

Earlier quoted context omitted.

I've always seen the distinction as "serverless" meaning there wasn't a set group of servers always on and instead they provision up and down on demand. Only avoiding provisioning and managing the server just means you are renting rather than self-hosting.

The VPS is like renting office space. You don't own the space, but for the most part get to use it how you want, and all the responsibilities that come with that. "Serverless" is like paying for a hot desk by the minute, with little control of your surroundings, but it is convenient and cheap if you only need it for an hour.

At one job I had access to some paid AWS support tier. It's basically a bunch of consultants. We needed to process a datastream of events from user actions on a website. We asked about serverless / AWS Lambda. Their answer was something like "Well yeah it'll work but don't do that. It'll cost too much money and you'll wind up rebuilding it around EC2 anyways"
Post reply on HN