emscripten-core / emscripten-core/emscripten
[Feature Request] WebTransport (QUIC) API Support
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
**Feature Request: Integration of the WebTransport API into Emscripten**
**Overview:**
WebTransport, a new HTTP/3 web standard, is already accessible in modern browsers such as Chrome, Edge, and Firefox (see compatibility at: [caniuse.com](https://caniuse.com/?search=webtransport)). As a direct user and advocate for this feature, I strongly believe that integrating WebTransport into Emscripten should be a high priority.
**Significance in Real-Time Multiplayer Games:**
In the realm of real-time multiplayer games, the necessity for unreliable messaging is paramount for scalability. Consider scenarios like player movement, which demands rollback mechanisms to conceal latency issues. This underscores the critical need for unreliable messaging in web-compatible engines. My project, Toxoid, a multiplayer polyglot WASM Rust game engine that utilizes C libraries and targets the web via Emscripten, serves as a prime example of this requirement. More about Toxoid can be found here: [Toxoid GitHub Repository](https://github.com/toxoidengine/toxoid).
**Current Landscape:**
For leveraging C/C++ libraries, and for Rust projects which include C/C++ libraries, Emscripten is often the go-to framework for browser/web API interoperability. However, because Emscripten does not support the WebTransport API, this indicates that it's falling behind the tier 1 Rust WebAssembly target in supporting the HTTP/3 standard.
In contrast, the Rust wasm target `wasm32-unknown-unknown` already supports the WebTransport API through the `web-sys` library (details at: [wasm-bindgen](https://rustwasm.github.io/wasm-bindgen/api/web_sys/struct.WebTransport.html)), but it does not facilitate the use of C libraries.
**Limitations of Alternatives:**
WebSockets, operating over TCP, present substantial limitations for our use case.
**TCP Network Congestion and Limitations in Real-Time Applications:**
**Congestion and Packet Loss:** TCP, the traditional protocol used for reliable communication, often encounters significant challenges in the context of real-time applications. One of the primary issues is network congestion. As TCP ensures data integrity and order, packet loss can lead to considerable delays. The TCP protocol requires acknowledgment of packet receipt, and lost packets result in retransmissions. This process, while ensuring data integrity, increases the round trip time (RTT), negatively impacting real-time interactions.
**Infinite Retries and Latency:** Another critical aspect of TCP is its approach to handling message transmission failures. TCP will attempt infinite retries to send messages until they are successfully delivered. This feature, while useful for ensuring complete data transfer in many scenarios, becomes a hindrance in real-time applications. In scenarios like multiplayer gaming or live streaming, where timely delivery is more crucial than completeness, these retries contribute to unacceptable latency.
**Advantages of SCTP over TCP:** Stream Control Transmission Protocol (SCTP), which operates over UDP, offers a more suitable alternative for such real-time applications. Unlike TCP, SCTP (and by extension, UDP) does not guarantee packet order or reliability. This lack of strict reliability, paradoxically, is advantageous in real-time contexts. It allows for faster data transmission without the burden of handling packet loss or order, significantly reducing latency. SCTP also enables multiplexing of several streams within a single connection, mitigating the head-of-line blocking problem inherent in TCP.


**The Need for a Modern Solution in Emscripten:**
Given these limitations of TCP in the realm of real-time web applications, the integration of a more advanced and suitable protocol like WebTransport, which leverages the benefits of protocols like SCTP over UDP, becomes increasingly critical in Emscripten. This integration will address the challenges posed by TCP, offering a more efficient, reliable, and latency-sensitive solution suitable for real-time applications like multiplayer games.
**The need for WebTransport (QUIC):**
While WebRTC can facilitate unreliable messaging, it introduces significant complexity in setup. WebTransport, utilizing QUIC as its transport layer, offers a more streamlined alternative with several benefits, including multiplexing without head-of-line blocking, reduced connection establishment time, built-in security with TLS 1.3, improved congestion control, connection migration, and suitability for modern internet applications.
**Proposed Technical Requirements for WebTransport Integration in Emscripten:**
1. **API Compatibility:** Ensure the WebTransport API is fully compatible with Emscripten, allowing seamless integration and usage within the Emscripten environment.
2. **Ease of Use:** Provide clear, comprehensive documentation and examples to facilitate easy implementation for developers.
3. **Cross-Platform Support:** Ensure that the implementation is cross-platform, allowing developers to target a wide range of devices and browsers.
Contributor guide
Assessment
This issue has not been assessed yet.