libdatachannel Documentation

repository·master·Indexed 25 days ago

https://github.com/paullouisageneau/libdatachannel

A lightweight C/C++ library providing WebRTC Data Channels, Media Transport, and WebSockets. It serves as a simple alternative to the Google WebRTC reference library for native-to-browser connectivity. The library includes examples for signaling servers (Node.js, Python, Rust), benchmarking tools, and media streaming implementations such as media-receiver, media-sender, and media-sfu.

Tokens
14.9K
Snippets
35
Records
104
Agent score
80%

What's inside libdatachannel

  1. Overview of client-benchmark

    master

    The client-benchmark is a native client designed to open Data Channels using WebSocket signaling via libdatachannel. It provides three primary benchmarking functionalities:

    1. Benchmark: Performs bi-directional data transfer testing (also supports one-way testing).
    2. Constant Throughput Set: Sends a specific, desired amount of data per second.
    3. Multiple Data Channel: Creates a specified number of data channels to test scale.
  2. Overview of libdatachannel

    master
    libdatachannel is a standalone C/C++ implementation of WebRTC Data Channels, WebRTC Media Transport, and WebSockets. It provides C bindings and is designed to be lightweight with minimal external dependencies, making it suitable for connecting native applications directly to web browsers. It supports multiple platforms including GNU/Linux, Android, FreeBSD, Apple macOS, iOS, and Microsoft Windows.
  3. Clone and initialize libdatachannel repository

    master

    To build from source, clone the repository and initialize submodules. Note that initializing submodules is optional if you plan to use the PREFER_SYSTEM_LIB CMake option to link against system libraries instead.

    $ git clone https://github.com/paullouisageneau/libdatachannel.git
    $ cd libdatachannel
    $ git submodule update --init --recursive --depth 1
  4. Implement WebRTC Data Channels with native and web clients

    master

    To test Data Channel connectivity, you can use the following client implementations:

    • Native C++ Client: Use the client directory for a native client that opens Data Channels using WebSocket signaling via libdatachannel.
    • Benchmarking: Use client-benchmark for a native client that includes benchmarking functionalities.
    • Web Browser: Use the web directory for a JavaScript client equivalent to the native client, suitable for web browsers.
  5. Use signaling servers for WebRTC connectivity

    master

    WebRTC requires a signaling mechanism to exchange connection metadata. The repository provides several signaling server implementations:

    • Node.js: signaling-server-nodejs
    • Python: signaling-server-python
    • Rust: signaling-server-rust (Note: see lerouxrgd/datachannel-rs for Rust wrappers)
  6. Initialize and clean up libdatachannel global resources

    master

    Use rtcPreload and rtcCleanup to manage global library resources.

    • rtcPreload(): Preloads global resources. This prevents the first PeerConnection from experiencing high latency due to lazy-loading. This call blocks until finished.
    • rtcCleanup(): Unloads global resources. This call blocks until unloading is done.

    Warning: rtcCleanup destroys any existing Peer Connections, Data Channels, Tracks, or WebSockets. It must never be called from within a callback, as it requires all callbacks to return before it can complete.

  7. Stream local RTP to a browser using the media-sender example

    master

    The media-sender example allows you to forward a local RTP stream to a web browser.

    Setup Steps:

    1. Open the Web Interface: Open main.html in your web browser.
    2. Start the Application: Run the media-sender application.
    3. Exchange SDP Offers/Answers:
      • Copy the offer generated by the application and paste it into the text box on the web page.
      • Copy the answer generated by the web page and paste it back into the application.

    RTP Stream Requirements:

    • Payload Type: 96 (H.264 video).
    • Target Address: localhost:6000.

    Linux GStreamer Demo Pipeline:

    To capture video from a V4L2 webcam and send it as an RTP H.264 stream to the application, use the following command (ensure /dev/video0 matches your device):