The main C++ namespace exposed by the libmediasoupclient library.
#include "libmediasoupclient/mediasoupclient.hpp"
The Device
class.
@returns
Device
auto* device = new mediasoupclient::Device();
The libmediasoupclient version.
@returns
std::string
mediasoupclient::Version();
// "1.0.0"
libmediasoupclient initialization. Initializes libwebrtc.
mediasoupclient::Initialize();
libmediasoupclient cleanup. Cleans up libwebrtc.
mediasoupclient::Cleanup();
Parses the given scalabilityMode
string according to the rules in webrtc-svc.
Argument | Type | Description | Required | Default |
---|---|---|---|---|
scalabilityMode |
const std::string& | Scalability mode. | Yes |
@returns
nlohmann::json:
spatialLayers
{@type
uint16_t} Number of spatial layers (by default 1).
temporalLayers
{@type
uint16_t} Number of temporal layers (by default 1).
mediasoupclient::parseScalabilityMode("L2T3");
// => { spatialLayers: 2, temporalLayers: 3 }
mediasoupclient::parseScalabilityMode("L4T7_KEY_SHIFT");
// => { spatialLayers: 4, temporalLayers: 7 }
A device represents an endpoint that connects to a mediasoup Router to send and/or receive media.
This is the entry point for C++ client side applications.
Field | Type | Description | Required | Default |
---|---|---|---|---|
config |
webrtc::PeerConnectionInterface::RTCConfiguration | PeerConnection configuration. | No | |
factory |
webrtc::PeerConnectionFactoryInterface* | PeerConnection factory. | No |
Creates a new device.
auto* device = new mediasoupclient::Device();
The device RTP capabilities, generated by combining both the underlying WebRTC capabilities and the router RTP capabilities (see the Load() method).
@async
blocks current thread
@returns
const nlohmann::json& RtpCapabilities
@throws
mediasoupclient::Exception, if device not loaded
These RTP capabilities must be given to the mediasoup router in order to consume a remote stream. Check the Communication Between Client and Server section for more details.
Whether the device has been loaded (see the Load() method).
@returns
bool
Loads the device with the RTP capabilities of the mediasoup router. This is how the device knows about the allowed media codecs and other settings.
Argument | Type | Description | Required | Default |
---|---|---|---|---|
routerRtpCapabilities |
const nlohmann::json& RtpCapabilities | The mediasoup router RTP capabilities. | Yes | |
peerConnectionOptions |
PeerConnection::Options* | PeerConnection options. | No |
@throws
mediasoupclient::Exception, if device already loaded
The router RTP capabilities are exposed via the router.rtpCapabilities getter. Check the Communication Between Client and Server section for more details.
See also how to filter those server-side capabilities before applying them to the libmediasoupclient device.
device.Load(routerRtpCapabilities);
// Now the device is ready.
Whether the device can produce media of the given kind. This depends on the media codecs enabled in the mediasoup router and the media capabilities of libwebrtc.
Argument | Type | Description | Required | Default |
---|---|---|---|---|
kind |
const std::string& | “audio” or “video”. | Yes |
@returns
bool
@throws
mediasoupclient::Exception, if device not loaded
@throws
mediasoupclient::Exception, if invalid kind
if (device.CanProduce("video"))
{
// Produce video.
}
Creates a new WebRTC transport to send media. The transport must be previously created in the mediasoup router via router.createWebRtcTransport().
Argument | Type | Description | Required | Default |
---|---|---|---|---|
listener |
SendTransport::Listener | The identifier of the server side transport. | Yes | |
id |
const std::string& | The identifier of the server side transport. | Yes | |
iceParameters |
const nlohmann::json& IceParameters | ICE parameters of the server side transport. | Yes | |
iceCandidates |
const nlohmann::json& Array<IceCandidate> | ICE candidates of the server side transport. | Yes | |
dtlsParameters |
const nlohmann::json& DtlsParameters | DTLS parameters of the server side transport. | Yes | |
peerConnectionOptions |
PeerConnection::Options* | PeerConnection options. | No | |
appData |
nlohmann::json | Custom application data. | No | { } |
@returns
SendTransport*
auto* sendTransportListener = new MySendTransportListener();
// This will block the current thread until completion.
auto* sendTransport = device.CreateSendTransport(
sendTransportListener,
id,
iceParameters,
iceCandidates,
dtlsParameters);
Creates a new WebRTC transport to receive media. The transport must be previously created in the mediasoup router via router.createWebRtcTransport().
Argument | Type | Description | Required | Default |
---|---|---|---|---|
listener |
RecvTransport::Listener | The identifier of the server side transport. | Yes | |
id |
const std::string& | The identifier of the server side transport. | Yes | |
iceParameters |
const nlohmann::json& IceParameters | ICE parameters of the server side transport. | Yes | |
iceCandidates |
const nlohmann::json& Array<IceCandidate> | ICE candidates of the server side transport. | Yes | |
dtlsParameters |
const nlohmann::json& DtlsParameters | DTLS parameters of the server side transport. | Yes | |
peerConnectionOptions |
PeerConnection::Options | PeerConnection options. | No | |
appData |
nlohmann::json | Custom application data. | No | { } |
@returns
RecvTransport*
auto* recvTransportListener = new MyRecvTransportListener();
// This will block the current thread until completion.
auto* recvTransport = device.CreateRecvTransport(
recvTransportListener,
id,
iceParameters,
iceCandidates,
dtlsParameters);
A Transport
instance in libmediasoupclient represents the local side of a WebRtcTransport in mediasoup server. A WebRTC transport connects a mediasoupclient Device with a mediasoup Router at media level and enables the sending of media (by means of Producer instances) or the receiving of media (by means of Consumer instances).
Internally, the transport holds a WebRTC RTCPeerConnection instance.
Transport identifier. It matches the id
of the server side transport.
@returns
const std::string&
The current connection state of the local peerconnection.
@returns
const std::string& RTCPeerConnectionState
Gets the local transport statistics by calling getStats()
in the underlying RTCPeerConnection
instance.
@async
blocks current thread
@returns
nlohmann::json& RTCStatsReport
Custom data Object provided by the application in the transport constructor. The app can modify its content at any time.
@returns
const nlohmann::json&
Whether the transport is closed.
@returns
bool
Closes the transport, including all its producers and consumers.
This method should be called when the server side transport has been closed (and vice-versa).
Instructs the underlying peerconnection to restart ICE by providing it with new remote ICE parameters.
Argument | Type | Description | Required | Default |
---|---|---|---|---|
iceParameters |
const nlohmann::json& IceParameters | New ICE parameters of the server side transport. | Yes |
@async
blocks current thread
This method must be called after restarting ICE in server side via webRtcTransport.restartIce().
transport.RestartIce(iceParameters);
Provides the underlying peerconnection with a new list of TURN servers.
Argument | Type | Description | Required | Default |
---|---|---|---|---|
iceServers |
const nlohmann::json& Array<RTCIceServer> | List of TURN servers to provide the local peerconnection with. | No | [ ] |
This method is specially useful if the TURN server credentials have changed.
transport.updateIceServers(iceServers);
@abstract
This is an abstract class inherited by SendTransport::Listener and RecvTransport::Listener.
Called when the transport is about to establish the ICE+DTLS connection and needs to exchange information with the associated server side transport.
Argument | Type | Description |
---|---|---|
transport |
Transport* | Transport instance. |
dtlsParameters |
const nlohmann::json& DtlsParameters | Local DTLS parameters. |
@returns
std::future<void> when the transport is created in server side mediasoup
In server side, the application should call webRtcTransport.connect().
std::future<void> MyTransportListener::OnConnect(
mediasoupclient::Transport transport,
const json& dtlsParameters
)
{
std::promise<void> promise;
json body =
{
{ "transportId", transport->GetId() },
{ "dtlsParameters", dtlsParameters }
};
// Signal local DTLS parameters to the server side transport.
mySignaling.send("transport-connect", body);
// [...] Let's assume code execution continues once we get a success response
// from the server.
// Fulfil the promise and return its future.
promise.set_value();
return promise.get_future();
}
Emitted when the local transport connection state changes.
Argument | Type | Description |
---|---|---|
transport |
Transport* | Transport instance. |
connectionState |
const std::string& RTCPeerConnectionState | Transport connection state. |
@inherits
Transport
A WebRTC send transport connects a mediasoupclient Device with a mediasoup Router at media level and enables the sending of media (by means of Producer instances).
Internally, the transport holds a WebRTC RTCPeerConnection instance.
Instructs the transport to send an audio or video track to the mediasoup router.
Argument | Type | Description | Required | Default |
---|---|---|---|---|
listener |
Producer::Listener | Producer listener. | Yes | |
track |
webrtc::MediaStreamTrackInterface* | An audio or video track. | Yes | |
encodings |
const std::vector<webrtc::RtpEncodingParameters>* | Encoding settings. | No | |
codecOptions |
ProducerCodecOptions* | Per codec specific options. | No | [ ] |
appData |
nlohmann::json | Custom application data. | No | { } |
@async
blocks current thread
@returns
Producer
If video simulcast is desired, encodings
array must be filled with more than one encodings. Each encoding represents a simulcast RTP stream:
maxBitrate
, maxFramerate
or scaleResolutionDownBy
.rid
field must not be set. The library will internally add it if the underlying browser supports RID.active
field must not be set. The library will internally set it to true
.// Send opus audio track with specific codec options.
if (device.CanProduce("audio"))
{
auto* audioTrack = myUtils::createAudioTrack();
json codecOptions =
{
{ "opusStereo", true },
{ "opusDtx", true }
};
auto* audioProducerListener = new MyProducerListener();
auto* audioProducer = sendTransport->Produce(
audioProducerListener,
audioTrack,
nullptr,
&codecOptions);
}
// Send video track with 3 simulcast streams.
if (device.CanProduce("video"))
{
auto* videoTrack = myUtils::createVideoTrack();
std::vector<webrtc::RtpEncodingParameters> encodings;
encodings.emplace_back(webrtc::RtpEncodingParameters());
encodings.emplace_back(webrtc::RtpEncodingParameters());
encodings.emplace_back(webrtc::RtpEncodingParameters());
auto* videoProducerListener = new MyProducerListener();
// This will block the current thread until completion.
auto* videoProducer = sendTransport->Produce(
videoProducerListener,
videoTrack,
&encodings,
nullptr);
}
Before this method completes, the local transport will call “OnProduce” method in the listener. The application must define this method, signal those parameters to the server, and invoke transport.produce() on the corresponding WebRTC transport.
Check the Communication Between Client and Server section for more details.
Instructs the transport to send data via DataChannel to the mediasoup router.
Argument | Type | Description | Required | Default |
---|---|---|---|---|
listener |
DataProducer::Listener* | DataProducer listener. | Yes | |
label |
const std::string& | A label which can be used to distinguish this DataChannel from others. | No | |
protocol |
const std::string& | Name of the sub-protocol used by this DataChannel. | No | |
ordered |
bool | Whether data messages must be received in order. if true the messages will be sent reliably. | No | true |
maxPacketLifeTime |
int | When ordered is false indicates the time (in milliseconds) after which a SCTP packet will stop being retransmitted. |
No | |
maxRetransmits |
int | When ordered is false indicates the maximum number of times a packet will be retransmitted. |
No | |
appData |
const nlohmann::json& | Custom application data. | No | { } |
@async
blocks current thread
@returns
DataProducer
Before this method completes, the local transport will call “OnProduceData” method in the listener. The application must define this method, signal those parameters to the server, and invoke transport.produce() on the corresponding WebRTC transport.
Check the Communication Between Client and Server section for more details.
@inherits
Transport::Listener
@abstract
This is an abstract class which must be implemented and used according to the API.
Emitted when the transport needs to transmit information about a new producer to the associated server side transport. This event occurs before the produce() method completes.
Argument | Type | Description |
---|---|---|
transport |
SendTransport* | SendTransport instance. |
kind |
const std::string& | Producer's media kind (“audio” or “video”). |
rtpParameters |
nlohmann::json RtpSendParameters | Producer's RTP parameters. |
appData |
const nlohmann::json& | Custom application data as given in the transport.produce() method. |
@returns
std::future<std::string> ID of the producer created in server side mediasoup
In server side, the application should call transport.produce().
std::future<std::string> MySendTransportListener::OnProduce(
mediasoupclient::Transport* transport,
const std::string& kind,
json rtpParameters,
const json& appData
)
{
std::promise<std::string> promise;
json body =
{
{ "transportId", transport->GetId() },
{ "kind", kind },
{ "rtpParameters", rtpParameters },
{ "appData", appData }
};
json response = mySignaling.send("transport-produce", body);
// [...] Let's assume code execution continues once we get a success response
// from the server.
// Read the id in the response.
auto idIt = response.find("id");
if (idIt == response.end() || !idIt->is_string())
{
promise.set_exception(
std::make_exception_ptr("'id' missing/invalid in response"));
}
// Fulfil the promise with the id in the response and return its future.
promise.set_value(idIt->get<std::string>());
return promise.get_future();
}
Emitted when the transport needs to transmit information about a new data producer to the associated server side transport. This event occurs before the produceData() method completes.
Argument | Type | Description | |
---|---|---|---|
transport |
SendTransport* | SendTransport instance. | |
sctpStreamParameters |
const SctpStreamParameters& | ||
label |
const std::string& | A label which can be used to distinguish this DataChannel from others. | No |
protocol |
const std::string& | Name of the sub-protocol used by this DataChannel. | No |
appData |
const nlohmann::json& | Custom application data as given in the transport.produceData() method. |
@returns
std::future<std::string> ID of the data producer created in server side mediasoup
In server side, the application should call transport.produceData().
std::future<std::string> MySendTransportListener::OnProduceData(
SendTransport* transport,
const nlohmann::json& sctpStreamParameters,
const std::string& label,
const std::string& protocol,
const nlohmann::json& appData);
)
{
std::promise<std::string> promise;
json body =
{
{ "transportId", transport->GetId() },
{ "sctpStreamParameters", sctpStreamParameters },
{ "label", label },
{ "protocol", protocol },
{ "appData", appData }
};
json response = mySignaling.send("transport-produce-data", body);
// [...] Let's assume code execution continues once we get a success response
// from the server.
// Read the id in the response.
auto idIt = response.find("id");
if (idIt == response.end() || !idIt->is_string())
{
promise.set_exception(
std::make_exception_ptr("'id' missing/invalid in response"));
}
// Fulfil the promise with the id in the response and return its future.
promise.set_value(idIt->get<std::string>());
return promise.get_future();
}
@inherits
Transport
A WebRTC receive transport connects a mediasoupclient Device with a mediasoup Router at media level and enables the reception of media (by means of Consumer instances).
Internally, the transport holds a WebRTC RTCPeerConnection instance.
Instructs the transport to receive an audio or video track to the mediasoup router.
Argument | Type | Description | Required | Default |
---|---|---|---|---|
listener |
Consumer::Listener | Consumer listener. | Yes | |
id |
const std::string& | The identifier of the server side consumer. | Yes | |
producerId |
const std::string& | The identifier of the server side producer being consumed. | Yes | |
kind |
const std::string& | Media kind (“audio” or “video”). | Yes | |
rtpParameters |
const nlohmann::json* RtpReceiveParameters | Receive RTP parameters. | Yes | |
appData |
nlohmann::json | Custom application data. | No | { } |
@async
blocks current thread
@returns
Consumer
auto* consumerListener = new MyConsumerListener();
// This will block the current thread until completion.
auto* consumer = recvTransport->Consume(
consumerListener,
id,
producerId,
kind,
rtpParameters);
Instructs the transport to receive data via DataChannel from the mediasoup router.
Argument | Type | Description | Required | Default |
---|---|---|---|---|
listener |
DataConsumer::Listener | Consumer listener. | Yes | |
id |
const std::string& | The identifier of the server side consumer. | Yes | |
producerId |
const std::string& | The identifier of the server side producer being consumed. | Yes | |
label |
const std::string& | A label which can be used to distinguish this DataChannel from others. | Yes | |
protocol |
const std::string& | Name of the sub-protocol used by this DataChannel. | No | |
appData |
nlohmann::json | Custom application data. | No | { } |
@async
blocks current thread
@returns
DataConsumer
auto* consumerListener = new MyConsumerListener();
// This will block the current thread until completion.
auto* consumer = recvTransport->Consume(
consumerListener,
id,
"dataChannelLabel",
"dataChannelProtocol");
@inherits
Transport::Listener
@abstract
This is an abstract class which must be implemented and used according to the API.
A producer represents an audio or video source that will be transmitted to the mediasoup router through a WebRTC transport.
@type
nlohmann::json
Field | Type | Description | Required | Default |
---|---|---|---|---|
opusStereo |
bool | Enable OPUS stereo (if the audio source is stereo). | No | libwebrtc default. |
opusFec |
bool | Enable OPUS in band FEC. | No | libwebrtc default. |
opusDtx |
bool | Enable OPUS discontinuous transmission. | No | libwebrtc default. |
opusMaxPlaybackRate |
Unsigned number | Set OPUS maximum playbak rate. | No | libwebrtc default. |
videoGoogleStartBitrate |
Unsigned number | Set video initial bitrate. | No | |
videoGoogleMaxBitrate |
Unsigned number | Set video maximum bitrate. | No | |
videoGoogleMinBitrate |
Unsigned number | Set video minimum bitrate. | No | |
opusPtime |
Unsigned number | Set OPUS frame size. | No | libwebrtc default. |
Producer identifier.
@returns
const std::string&
The media kind (“audio” or “video”).
@returns
std::string MediaKind
The audio or video track being transmitted.
@returns
webrtc::MediaStreamTrackInterface*
Producer RTP parameters. These parameters are internally built by the library and conform to the syntax and requirements of mediasoup, thus they can be transmitted to the server to invoke transport.produce() with them.
@returns
const nlohmann::json& RtpSendParameters
Check the Communication Between Client and Server section for more details.
In case of simulcast, this value determines the highest stream (from 0 to N-1) being transmitted. See the SetMaxSpatialLayer() method for more about this.
@returns
const uint8_t
Gets the local RTP sender statistics by calling getStats()
in the underlying RTCRtpSender
instance.
@async
blocks current thread
@returns
nlohmann::json RTCStatsReport
Custom data Object provided by the application in the producer factory method. The app can modify its content at any time.
@returns
const nlohmann::json&
Whether the producer is closed.
@returns
bool
Whether the producer is paused.
@returns
bool
Closes the producer. No more media is transmitted.
This method should be called when the server side producer has been closed (and vice-versa).
Pauses the producer (no RTP is sent to the server).
This method should be called when the server side producer has been paused (and vice-versa).
Resumes the producer (RTP is sent again to the server).
This method should be called when the server side producer has been resumed (and vice-versa).
Replaces the audio or video track being transmitted. No negotiation with the server is needed.
Argument | Type | Description | Required | Default |
---|---|---|---|---|
track |
webrtc::MediaStreamTrackInterface* | An audio or video track. | Yes |
producer.ReplaceTrack(newVideoTrack);
In case of simulcast, this method limits the highest RTP stream being transmitted to the server.
Argument | Type | Description | Required | Default |
---|---|---|---|---|
spatialLayer |
uint8_t | The index of the entry in encodings representing the highest RTP stream that will be transmitted. |
Yes |
// Assuming `encodings` array has 3 entries, let's enable just the first and
// second streams (indexes 0 and 1).
producer.setMaxSpatialLayer(1);
@abstract
This is an abstract class which must be implemented and used according to the API.
Executed when the transport this producer belongs to is closed for whatever reason. The producer itself is also closed.
Argument | Type | Description | Required | Default |
---|---|---|---|---|
producer |
Producer* | The producer instance executing this method. | Yes |
void MyProducerListener::OnTransportClose(mediasoupclient::Producer* producer)
{
std::cout << "transport closed" << std::endl;
}
A consumer represents an audio or video remote source being transmitted from the mediasoup router to the client application through a WebRTC transport.
Consumer identifier.
@returns
const std::string&
The associated producer identifier.
@returns
const std::string&
The media kind (“audio” or “video”).
@returns
const std::string& MediaKind
Consumer RTP parameters.
@returns
const nlohmann::json& RtpReceiveParameters
Check the Communication Between Client and Server section for more details.
The remote audio or video track.
@returns
webrtc::MediaStreamTrackInterface*
Gets the local RTP receiver statistics by calling getStats()
in the underlying RTCRtpReceiver
instance.
@async
blocks current thread
@returns
nlohmann::json RTCStatsReport
Custom data Object provided by the application in the consumer factory method. The app can modify its content at any time.
@returns
const nlohmann::json&
Whether the consumer is closed.
@returns
bool
Whether the consumer is paused.
@returns
bool
Closes the consumer.
This method should be called when the server side consumer has been closed (and vice-versa).
Pauses the consumer. Internally the library executes track->set_enabled(false)
in the remote track.
This method should be called when the server side consumer has been paused (and vice-versa).
Resumes the consumer Internally the library executes track->set_enabled(true)
in the remote track.
This method should be called when the server side consumer has been resumed (and vice-versa).
@abstract
This is an abstract class which must be implemented and used according to the API.
Executed when the transport this consumer belongs to is closed for whatever reason. The consumer itself is also closed.
Argument | Type | Description | Required | Default |
---|---|---|---|---|
consumer |
Consumer* | The consumer instance executing this method. | Yes |
void MyConsumerListener::OnTransportClose(mediasoupclient::Consumer* consumer)
{
std::cout << "transport closed" << std::endl;
}
A data producer represents a data source that will be transmitted to the mediasoup router through a WebRTC transport.
Producer identifier.
@returns
const std::string&
The SCTP stream parameters.
@returns
const SctpStreamParameters.
The DataChannel ready state.
@type
webrtc::DataChannelInterface::DataState
The DataChannel label.
@returns
std::string, read only
The DataChannel sub-protocol.
@returns
std::string, read only
The number of bytes of application data (UTF-8 text and binary data) that have been queued using send()
.
@returns
uint64_t, read only
Custom data Object provided by the application in the data producer factory method. The app can modify its content at any time.
@returns
const nlohmann::json&
Whether the data producer is closed.
@returns
bool
Closes the data producer. No more data is transmitted.
This method should be called when the server side producer has been closed (and vice-versa).
Sends the given data over the corresponding DataChannel. If the data can't be sent at the SCTP level (due to congestion control), it's buffered at the data channel level, up to a maximum of 16MB. If Send is called while this buffer is full, the data channel will be closed abruptly.
So, it's important to use GetBufferedAmount and OnBufferedAmountChange to ensure the data channel is used efficiently but without filling this buffer.
Argument | Type | Description | Required | Default |
---|---|---|---|---|
buffer |
webrtc::DataBuffer& | Data message to be sent. | No |
@abstract
This is an abstract class which must be implemented and used according to the API.
Executed when the underlying DataChannel is open.
Argument | Type | Description | Required | Default |
---|---|---|---|---|
producer |
DataProducer* | The producer instance executing this method. | Yes |
Executed when the underlying DataChannel is closed for unknown reasons.
Argument | Type | Description | Required | Default |
---|---|---|---|---|
producer |
DataProducer* | The producer instance executing this method. | Yes |
Executed when the DataChannel buffered amount of bytes changes.
Argument | Type | Description | Required | Default |
---|---|---|---|---|
producer |
DataProducer* | The producer instance executing this method. | Yes | |
sentDataSize |
uint64_t | The amount of data sent. | Yes |
Executed when the transport this producer belongs to is closed for whatever reason. The producer itself is also closed.
Argument | Type | Description | Required | Default |
---|---|---|---|---|
producer |
DataProducer* | The producer instance executing this method. | Yes |
void MyProducerListener::OnTransportClose(mediasoupclient::Producer* producer)
{
std::cout << "transport closed" << std::endl;
}
A data consumer represents a data source being transmitted from the mediasoup router to the client application through a WebRTC transport.
Consumer identifier.
@returns
const std::string&
The associated data producer identifier.
@returns
const std::string&
The SCTP stream parameters.
@returns
const SctpStreamParameters.
The DataChannel ready state.
@type
webrtc::DataChannelInterface::DataState
The DataChannel label.
@returns
std::string, read only
The DataChannel sub-protocol.
@returns
std::string, read only
Custom data Object provided by the application in the consumer factory method. The app can modify its content at any time.
@returns
const nlohmann::json&
Whether the consumer is closed.
@returns
bool
Closes the dataConsumer.
This method should be called when the server side consumer has been closed (and vice-versa).
@abstract
This is an abstract class which must be implemented and used according to the API.
Executed when the underlying DataChannel is connecting.
Argument | Type | Description | Required | Default |
---|---|---|---|---|
producer |
DataConsumer* | The producer instance executing this method. | Yes |
Executed when the underlying DataChannel is open.
Argument | Type | Description | Required | Default |
---|---|---|---|---|
producer |
DataConsumer* | The producer instance executing this method. | Yes |
Executed when the underlying DataChannel is closing.
Argument | Type | Description | Required | Default |
---|---|---|---|---|
producer |
DataConsumer* | The producer instance executing this method. | Yes |
Executed when the underlying DataChannel is closed for unknown reasons.
Argument | Type | Description | Required | Default |
---|---|---|---|---|
producer |
DataConsumer* | The producer instance executing this method. | Yes |
Executed when the transport this consumer belongs to is closed for whatever reason. The consumer itself is also closed.
Argument | Type | Description | Required | Default |
---|---|---|---|---|
consumer |
DataConsumer* | The consumer instance executing this method. | Yes |
void MyConsumerListener::OnTransportClose(mediasoupclient::DataConsumer* consumer)
{
std::cout << "transport closed" << std::endl;
}
Executed when a DataChannel message is received.
Argument | Type | Description | Required | Default |
---|---|---|---|---|
consumer |
DataConsumer* | The consumer instance executing this method. | Yes | |
buffer |
webrtc::DataBuffer& | Data message received. | No |
void MyConsumerListener::OnMessage(DataConsumer* dataConsumer, const webrtc::DataBuffer& buffer)
{
if (dataConsumer->GetLabel() == "chat")
{
std::string message = std::string(buffer.data.data<char>(), buffer.data.size());
std::cout << "received chat message: " << message << std::endl;
}
}
C++ namespace (within the mediasoupclient
namespace) responsible for logging.
Value | Description |
---|---|
“LOG_DEBUG” | Logs debug level and above. |
“LOG_WARN” | Logs warning level and above. |
“LOG_ERROR” | Logs error level. |
“LOG_NONE” | Logs nothing. |
LogLevel
is “LOG_DEBUG”.See LogHandlerInterface.
Sets log level.
Argument | Type | Description | Required | Default |
---|---|---|---|---|
level |
LogLevel | The log level to be used for logging. | Yes |
Sets log handler.
Argument | Type | Description | Required | Default |
---|---|---|---|---|
level |
LogHandlerInterface* | The log handler to be used. | Yes |
Sets the default log handler, which prints all log messages to stdout
.
@abstract
This is an abstract class which can be implemented and provided to libmediasoupclient via Logger::SetHandler().
Executed for every log.
Argument | Type | Description | Required | Default |
---|---|---|---|---|
level |
LogLevel | The level this log message belongs to. | Yes | |
payload |
char* | The log message. | Yes | |
len |
size_t | The log message length. | Yes |
void MyLogHandler::OnLog(LogLevel level, char* payload, size_t len)
{
std::cout << payload << std::endl;
}
libmediasoupclient uses the JSON for Modern C++ library and exposes its nlohmann::json
C++ namespace.
The application must use it to construct JSON objects and pass them to the libmediasoupclient API when required.
#include "nlohmann/json.hpp"