libmediasoupclient

repository·v3·Indexed 43 days ago

https://github.com/versatica/libmediasoupclient

A C++ client-side library for building mediasoup-based applications, leveraging Google's libwebrtc for WebRTC capabilities. It provides client-side primitives to interact with a mediasoup media server, including the RoomClient class for managing media sessions, tracks, and data channels.

Tokens
1.5K
Snippets
7
Records
10
Agent score
55%

What's inside libmediasoupclient

  1. Manually build the mediasoupclient demo with CMake

    v3

    If you prefer not to use run.sh, you can build the demo manually using CMake. You must specify the libwebrtc paths and enable the demo build via -DMEDIASOUPCLIENT_BUILD_DEMO=ON.

    # Configure
    cmake . -Bbuild \
      -DLIBWEBRTC_INCLUDE_PATH=/path/to/libwebrtc/src \
      -DLIBWEBRTC_BINARY_PATH=/path/to/libwebrtc/out/Release \
      -DMEDIASOUPCLIENT_BUILD_DEMO=ON
    
    # Build
    cmake --build build --target mediasoupclient_demo
  2. Build and run the mediasoupclient demo

    v3

    The mediasoupclient demo is a client application that connects to a mediasoup-demo server, sends microphone audio and camera video, and receives audio/video from other participants.

    To run the demo, use the provided run.sh script. This script automatically handles configuration and building. You must provide the paths to your libwebrtc sources and binary as environment variables.

    # Incremental build + run
    PATH_TO_LIBWEBRTC_SOURCES=/path/to/libwebrtc/src \
    PATH_TO_LIBWEBRTC_BINARY=/path/to/libwebrtc/out/Release \
    ./demo/run.sh --url wss://<server>:4443 --origin https://<server>:4443
  3. Perform a clean rebuild of the demo

    v3

    If you need to wipe the build/ directory and start a fresh configuration and build, pass the rebuild argument as the first argument to run.sh.

    # Full clean reconfigure + build + run
    PATH_TO_LIBWEBRTC_SOURCES=/path/to/libwebrtc/src \
    PATH_TO_LIBWEBRTC_BINARY=/path/to/libwebrtc/out/Release \
    ./demo/run.sh rebuild --url wss://<server>:4443 --origin https://<server>:4443
  4. Configure mediasoupclient demo options

    v3

    The mediasoupclient_demo binary accepts the following command-line options:

    OptionDefaultDescription
    --ws-url(required)Protoo WebSocket URL, e.g. wss://localhost:4443
    --origin(required)HTTP Origin header sent during the WebSocket handshake
    --room-iddemo-roomRoom ID to join
  5. Use RoomClient to manage media sessions

    v3

    The RoomClient class is used to join a room, manage media tracks (mic, camera), and handle data channels (chat).

    Constructor Signature (Simplified):

    RoomClient(
      const std::string& url,
      const std::string& origin,
      const std::string& appName,
      webrtc::PeerConnectionFactoryInterface* factory,
      const RoomOptions& options,
      std::function<void(const std::string&, webrtc::VideoTrackInterface*)> onVideoTrack,
      std::function<void(const std::string&)> onPeerLeft,
      std::function<void(const std::string&)> onDataMessage
    );

    Key Methods:

    • Join(): Connects to the room. Throws std::exception on failure.
    • EnableMic(): Enables the local microphone track.
    • EnableCamera(webrtc::VideoTrackInterface* videoTrack): Enables a specific local video track.
    • EnableChat(): Enables the data channel for text messaging.
    • Close(): Gracefully closes the connection to the room.
    // Example usage pattern
    RoomClient room(
      url,
      origin,
      "mediasoupclient-demo",
      factory.get(),
      { /* options */ },
      [](const std::string& peerId, webrtc::VideoTrackInterface* track) { /* on video track */ },
      [](const std::string& peerId) { /* on peer left */ },
      [](const std::string& msg) { /* on data message */ }
    );
    
    room.Join();
    room.EnableMic();
    room.Close();
  6. Run the mediasoupclient demo CLI

    v3

    The mediasoupclient_demo application connects to a mediasoup-demo server to send microphone audio and camera video, and receive media from other participants. It requires a Protoo WebSocket URL and an HTTP Origin.

    Usage:

    mediasoupclient_demo --ws-url [serverUrl] --origin [origin]

    Options:

    • --ws-url: The Protoo WebSocket URL (e.g., wss://localhost:4443). Required.
    • --origin: The HTTP Origin header (e.g., https://myserver:4443). Required.
    • --room-id: The Room ID to join. Defaults to demo-room.
    mediasoupclient_demo --ws-url wss://localhost:4443 --origin https://localhost:4443