libmediasoupclient
repository·v3·Indexed 43 days ago
https://github.com/versatica/libmediasoupclientA 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.
What's inside libmediasoupclient
- libmediasoupclient is a C++ client-side library designed for building applications based on mediasoup. It is built on top of Google's libwebrtc C++ library, providing the necessary client-side primitives to interact with a mediasoup media server.
Manually build the mediasoupclient demo with CMake
v3If you prefer not to use
run.sh, you can build the demo manually using CMake. You must specify thelibwebrtcpaths 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_demoBuild and run the mediasoupclient demo
v3The
mediasoupclient demois a client application that connects to amediasoup-demoserver, sends microphone audio and camera video, and receives audio/video from other participants.To run the demo, use the provided
run.shscript. This script automatically handles configuration and building. You must provide the paths to yourlibwebrtcsources 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>:4443Prerequisites for the mediasoupclient demo
v3Before building or running the demo, ensure you have the following:
- CMake ≥ 3.14
- A C++20-capable compiler
- (Optional) A running
mediasoup-demoserver
Perform a clean rebuild of the demo
v3If you need to wipe the
build/directory and start a fresh configuration and build, pass therebuildargument as the first argument torun.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>:4443Connect to the official mediasoup demo
v3You can test the client by connecting to the official public mediasoup demo server using the
run.shscript../run.sh --ws-url wss://v3demo.mediasoup.org:4443 --origin https://v3demo.mediasoup.org --room-id foobarConfigure mediasoupclient demo options
v3The
mediasoupclient_demobinary accepts the following command-line options:Option Default Description --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 Initialize mediasoupclient
v3Before using any
mediasoupclientfunctionality, you must callmediasoupclient::Initialize()to set up the necessary environment.mediasoupclient::Initialize();Use RoomClient to manage media sessions
v3The
RoomClientclass 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. Throwsstd::exceptionon 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();Run the mediasoupclient demo CLI
v3The
mediasoupclient_demoapplication connects to amediasoup-demoserver 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 todemo-room.
mediasoupclient_demo --ws-url wss://localhost:4443 --origin https://localhost:4443