godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.07k stars 69 forks source link

Add support for WebTransport #3899

Open mrakh opened 2 years ago

mrakh commented 2 years ago

Describe the project you are working on

A real-time multiplayer browser game with an authoritative server.

Describe the problem or limitation you are having in your project

A client-server multiplayer game requires a network transport that minimizes latency. For a natively installed game, this would traditionally be accomplished using a bespoke "netcode" sent over UDP, and any additional requirements like reliability or ordering were handled at the application layer. But within a browser, the only options for real-time full-duplex communication is via WebSockets or WebRTC.

WebSockets are ill suited for multiplayer games because the enforced ordering/reliability of the underlying TCP transport causes unacceptable latency spikes and degrades gameplay experience, particularly in the case of FPS games, MOBAs, and other such "twitch gameplay".

WebRTC has an option to use an unreliable/unordered transport mechanism, but it is designed with peer-to-peer in mind. Using it in a server is very clunky and difficult because there are no easy-to-use, stable, performant WebRTC implementations beyond what is in the Chrome/Firefox browser, and the handshaking process is fraught with complexities like STUN/TURN that are meant to address issues that don't exist for a public server.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

With the release of Google Chrome v97, The long-awaited WebTransport API is here at last. Like WebSockets, WebTransport offers a way to perform bidirectional client-server messaging. However, unlike WebSockets, a WebTransport connection can be configured to use an unreliable/unordered transport for low-latency real-time communications, where packet loss is tolerable.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Here you can find some examples of how to use the JavaScript API for WebTransport.

If this enhancement will not be used often, can it be worked around with a few lines of script?

When building for HTML5, one could wrap the WebTransport object with Godot's own JavaScriptObject. However, a headless server build would need a fairly extensive module/plugin to use an external WebTransport server library.

Is there a reason why this should be core and not an add-on in the asset library?

WebSocket, HTTP and WebRTC support are all core, so it makes sense to add WebTransport support to that as well.

Faless commented 2 years ago

My take on this is that it's way too soon to implement something like this. The "standard" is still a very early draft, support for it is basically chrome-only (as the implementation), it's based on QUIC and HTTP/3 which is going to be a pain to implement, and moreover its advantages are still to be determined.

mrakh commented 2 years ago

My take on this is that it's way too soon to implement something like this. The "standard" is still a very early draft, support for it is basically chrome-only (as the implementation), it's based on QUIC and HTTP/3 which is going to be a pain to implement, and moreover its advantages are still to be determined.

I agree that an attempt at a functional implementation at this time would be quite unproductive. The selection of available C/C++ libraries to implement a QUIC server is rather sparse. I nonetheless believe the feature proposal is worth keeping in mind - I anticipate that WebTransport adoption will be quite significant as it stabilizes, particularly within the niche of multiplayer browser games.

Tiedye commented 6 months ago

The spec is stable and available in multiple browsers now, is it a good time to look at this again?

Calinou commented 6 months ago

The spec is stable and available in multiple browsers now, is it a good time to look at this again?

Safari support is still missing as of December 2023: https://caniuse.com/webtransport

Anutrix commented 1 month ago

This ticket requires https://github.com/godotengine/godot-proposals/issues/8770 and then HTTP/3 and QUIC.