|
1 | 1 | ---
|
2 | 2 | title: "WebRTC"
|
3 |
| -description: "WebRTC is a new specification that uses QUIC to offer an alternative to WebSocket. Conceptually, it can be considered WebSocket over QUIC.Learn about WebTransport and how it is used in libp2p." |
| 3 | +description: "WebRTC is a protocol for real-time communication and is used to establish connections between browsers and other applications." |
4 | 4 | weight: 110
|
5 | 5 | aliases:
|
6 | 6 | - "/concepts/transports/webrtc"
|
7 | 7 | ---
|
8 | 8 |
|
9 |
| -Coming soon! |
| 9 | +## What is WebRTC? |
| 10 | + |
| 11 | +WebRTC (Web Real-Time Communications) is a framework for real-time communication |
| 12 | +and is used to establish connections between browsers and other applications. |
| 13 | +WebRTC serves as a good choice for applications that need built-in support for media |
| 14 | +communication and do not have specific requirements for the underlying transport |
| 15 | +protocol. |
| 16 | + |
| 17 | +### Key features |
| 18 | + |
| 19 | +- Audio and video support: WebRTC provides built-in support via a media stream API |
| 20 | + that controls the multimedia activities of a device over the data consumed. This |
| 21 | + allows applications to incorporate real-time audio and video streams easily. |
| 22 | + |
| 23 | +- Peer-to-peer communication: WebRTC enables direct communication between browsers |
| 24 | + and other nodes without needing an intermediate server. This allows for faster |
| 25 | + and more efficient communication. Peers can also retrieve or consume the media and |
| 26 | + also produce it. |
| 27 | + |
| 28 | +- Data channel: WebRTC provides a data channel that allows applications to transfer |
| 29 | + arbitrary data between peers. This works on |
| 30 | + [SCTP (Stream Control Transmission Protocol)](https://en.wikipedia.org/wiki/Stream_Control_Transmission_Protocol) and reduces network congestion over UDP. |
| 31 | + |
| 32 | +- [NAT traversal](../nat/overview): WebRTC includes mechanisms (like |
| 33 | + [ICE](https://datatracker.ietf.org/doc/rfc5245/))to connect to nodes that live behind |
| 34 | + NATs and firewalls. |
| 35 | + |
| 36 | +- [Security](../secure-comm/overview): WebRTC includes built-in security features, and |
| 37 | + connections are always encrypted by using [DTLS](https://en.wikipedia.org/wiki/Datagram_Transport_Layer_Security) or [SRTP](https://en.wikipedia.org/wiki/Secure_Real-time_Transport_Protocol). |
| 38 | + |
| 39 | +WebRTC includes several APIs to help facilitate the creation of a secure connection |
| 40 | +over the web. |
| 41 | + |
| 42 | +The `RTCPeerConnection` API allows two applications on different |
| 43 | +endpoints to communicate using a peer-to-peer protocol. The `PeerConnection` API |
| 44 | +interacts closely with a `getUserMedia` API for accessing a node's media-based peripheral |
| 45 | +device and uses the `getDisplayMedia` API to capture screen content. WebRTC allows a node |
| 46 | +to send and receive streams that include media content and arbitrary binary data |
| 47 | +through the `DataChannel`. |
| 48 | + |
| 49 | +### WebRTC and WebTransport |
| 50 | + |
| 51 | +While WebRTC and WebTransport are both web-based approaches that enable real-time |
| 52 | +communication between nodes, there are key differences. WebRTC supports peer-to-peer |
| 53 | +connections, while WebTransport only supports client-server connections. |
| 54 | + |
| 55 | +The underlying protocols in WebRTC and WebTransport are different, although both |
| 56 | +protocols share many of the same properties. WebTransport is also an |
| 57 | +alternative to the data channels available in WebRTC. |
| 58 | + |
| 59 | +WebRTC is also more complex, as there are many underlying protocols involved in order |
| 60 | +to create an active transport, as opposed to WebTransport, that uses QUIC. |
| 61 | + |
| 62 | +When connecting to a WebSocket server or when using plain TCP or QUIC connections, |
| 63 | +browsers require the server to present a TLS certificate signed by a trusted CA |
| 64 | +(certificate authority). Few nodes have such a certificate. One method to overcome |
| 65 | +this is to use the [WebTransport](webtransport) browser API that offers a way to |
| 66 | +accept a server's certificate by checking the (SHA-256) hash of the certificate. |
| 67 | + |
| 68 | +However, a certificate is still needed, even if it is "just" self-signed. |
| 69 | +The browser must also know the certificate hash. WebRTC can overcome this and |
| 70 | +does not require a trusted certificate. |
| 71 | +> While WebRTC does not require the use of trusted certificates, it does not |
| 72 | +> eliminate their usage, as WebRTC relies on TLS to establish secure connections |
| 73 | +> between peers and to protect the data being transferred. |
| 74 | +
|
| 75 | +## WebRTC in libp2p |
| 76 | + |
| 77 | +Libp2p WebRTC enables browsers to connect to public server nodes (and eventually, |
| 78 | +browsers to connect to other browsers) without those endpoints providing a TLS |
| 79 | +certificate within the browser's trustchain. |
| 80 | + |
| 81 | +In libp2p: |
| 82 | + |
| 83 | +- the `RTCPeerConnection` API allows an application to establish peer-to-peer |
| 84 | + communications; |
| 85 | +- the `RTCDataChannel` API supports peer-to-peer data channels; |
| 86 | +- a WebRTC multiaddresses are composed of a standard UDP multiaddr, |
| 87 | + followed by `webrtc` and the `multihash` of the certificate that |
| 88 | + the node uses, as such: |
| 89 | + `/ip4/1.2.3.4/udp/1234/webrtc/certhash/<hash>/p2p/<peer-id>`. |
| 90 | +- The TLS certificate fingerprint in `/certhash` is a multibase encoded multihash. |
| 91 | +- WebRTC can support UDP and TCP, but implementations must always support UDP. |
| 92 | + |
| 93 | +### Browser-to-Server |
| 94 | + |
| 95 | +A browser can connect to a server node without needing a trusted TLS |
| 96 | +certificate. View [this example](https://github.com/libp2p/specs/blob/master/webrtc/README.md#browser-to-public-server) on browser-to-server connection establishment in the technical |
| 97 | +specification for reference. |
| 98 | + |
| 99 | +<!-- TO ADD: DIAGRAMS ONCE READY + CONTEXt --> |
| 100 | + |
| 101 | +### Coming soon: Browser-to-Browser |
| 102 | + |
| 103 | +Eventually, libp2p will have support for two-way communication between two |
| 104 | +browsers in real-time. |
| 105 | + |
| 106 | +The technical specification and initial implementations of WebRTC |
| 107 | +Browser-to-Browser connectivity is planned for release in early 2023. |
| 108 | +Track the progress [here](https://github.com/libp2p/specs/issues/475). |
| 109 | + |
| 110 | +{{< alert icon="💡" context="note" text="See the WebRTC <a class=\"text-muted\" href=\"https://github.com/libp2p/specs/blob/master/webrtc/README.md\">technical specification</a> for more details." />}} |
0 commit comments