mediasoup

/ home / Documentation / v2 / mediasoup / API

mediasoup v2 API

mediasoup

The top-level module exported by the mediasoup module.

const mediasoup = require("mediasoup");

Properties

mediasoup.errors

Provides access to the errors module.

Functions

mediasoup.Server(settings)

Returns a new Server instance.

Argument Type Description Required Default
settings ServerSettings Server settings. No  

Usage example:

const server = mediasoup.Server(
  {
    logLevel            : "warn",
    rtcIPv4             : "1.2.3.4",
    rtcIPv6             : false,
    dtlsCertificateFile : "/home/foo/dtls-cert.pem",
    dtlsPrivateKeyFile  : "/home/foo/dtls-key.pem"
  });

Server

A server runs and manages a set of mediasoup worker child processes that handle media realtime-communications (ICE, DTLS, RTP, RTCP, DataChannel, etc.).

Dictionaries

ServerSettings

Field Type Description Required Default
numWorkers Number Number of child worker processes. No Number of CPU cores in the host
logLevel String Logging level for logs generated by the media worker subprocesses (check the Debugging documentation). Valid values are “debug”, “warn”, “error”. No “error”
logTags Array Log tags for debugging. Check the list of available tags in Debugging documentation. No [ ]
rtcIPv4 String|Boolean IPv4 for RTC. Valid values are a IPv4, true (auto-detect) and false (disabled). No true
rtcIPv6 String|Boolean IPv6 for RTC. Valid values are a IPv6, true (auto-detect) and false (disabled). No true
rtcAnnouncedIPv4 String Announced IPv4 for RTC. Useful for deployments in server with private IP such as AWS. Valid values are a IPv4. No  
rtcAnnouncedIPv6 String Announced IPv6 for RTC. Useful for deployments in server with private IP such as AWS. Valid values are a IPv6. No  
rtcMinPort Number Minimun RTC port. No 10000
rtcMaxPort Number Maximum RTC port. No 59999
dtlsCertificateFile String Path to the DTLS certificate. If unset, a random certificate is generated. No  
dtlsPrivateKeyFile String Path to the DTLS private key. If unset, a random certificate is generated. No  

ServerUpdateableSettings

Field Type Description Required Default
logLevel String Logging level for logs generated by the media worker subprocesses (check the Debugging documentation). Valid values are “debug”, “warn”, “error”. No  
logTags Array Log tags for debugging. Check the list of available tags in Debugging documentation. No  

Properties

server.closed

  • Read only

A boolean indicating whether the server has been closed.

server.numWorkers

  • Read only

The number of available workers (it matches numWorkers in ServerSettings if given).

Methods

server.close()

Closes the server, including all its rooms, and triggers a close event.

server.updateSettings(settings)

Updates the server settings in runtime. Just a subset of the full ServerSettings can be updated.

Argument Type Description Required Default
settings ServerUpdateableSettings Server settings. No  

server.Room(mediaCodecs, [options])

Creates and returns a new Room instance.

Argument Type Description Required Default
mediaCodecs sequence<RoomMediaCodec> Room media codecs. Yes  
options Object Optional room options No  

options allows the following items:

Field Type Description Required Default
workerIdx Number Worker index (from 0 to server.numWorkers - 1) to let the app select a specific worker to handle this room. If unset, the worker is chosen incrementally. No  

Usage example:

const mediaCodecs =
[
  {
    kind        : "audio",
    name        : "opus",
    clockRate   : 48000,
    channels    : 2,
    parameters  :
    {
      useinbandfec : 1
    }
  },
  {
    kind      : "video",
    name      : "VP8",
    clockRate : 90000
  },
  {
    kind       : "video",
    name       : "H264",
    clockRate  : 90000,
    parameters :
    {
      "packetization-mode"      : 1,
      "profile-level-id"        : "42e01f",
      "level-asymmetry-allowed" : 1
    }
  }
];

const room = server.Room(mediaCodecs);

Events

The Server class inherits from EventEmitter.

server.on(“close”)

Emitted when the server is closed.

server.on(“newroom”, fn(room))

Emitted when a new room is created.

Argument Type Description
room Room New room.

Room

A room holds a multiparty RTC (Real-Time Communication) conference.

For more information, check the Glossary section.

Dictionaries

RoomMediaCodec

Field Type Description Required Default
kind String Media kind (“audio” or “video”). Yes  
name String The codec MIME subtype. Valid values are listed in IANA-RTP-2. Examples: “opus”, “VP8”, “H264”. Yes  
mimetype String The codec MIME type, i.e. “audio/opus”, “video/VP8”, etc. The list of mediasoup supported codecs is the mediasoup/lib/supportedRtpCapabilities.js file. Yes  
clockRate Number Codec clock rate expressed in Hertz. Yes  
channels Number The number of channels (mono=1, stereo=2) for audio codecs. No 1
parameters Dictionary Codec-specific parameters available for signaling. No  

Feature codecs such as RTX or FEC must NOT be placed into Room mediaCodecs.

AudioLevelInfo

Field Type Description Required Default
producer Producer producer generating audio. Yes  
audioLevel Number Audio level in dBov (0 means maximum level, -127 means no audio). Yes  

Properties

room.id

  • Read only

Unique identifier (Number).

room.closed

  • Read only

A Boolean indicating whether the room has been closed.

room.rtpCapabilities

  • Read only.

An Object with the RTP capabilities of the room, miming the syntax of RTCRtpCapabilities in ORTC.

room.peers

  • Read only

An Array with the list of Peer instances in the room.

Methods

room.close([appData])

Closes the room, including all its peers, and triggers a close event.

Argument Type Description Required Default
appData Any Custom app data. No  

room.getPeerByName(name)

Retrieves the Peer with the given name, or undefined if not found.

Argument Type Description Required Default
name String Peer name. Yes  

room.receiveRequest(request)

Provide the room with a mediasoup protocol request payload (commonly generated by mediasoup-client).

Argument Type Description Required Default
request Object mediasoup protocol request. Yes  

Just mediasoup protocol requests with “room” target must be given to this method, meaning that the mediasoup protocol payload:

  • must have target: "room", and
  • must NOT have notification: true.

The method returns a Promise resolving to a mediasoup protocol response payload that must be sent back to the request originator.

Usage example:

// Here we assume a custom WebSocket based signaling protocol.
// * request: A mediasoup protocol request payload with target: "room".
// * accept: A function to tell our signaling protocol to accept the request.
// * reject: A function to tell our signaling protocol to reject the request.
function handleRequestFromMediasoupClient(request, accept, reject)
{
  switch (request.method)
  {
    case "queryRoom":
    {
      mediasoupRoom.receiveRequest(request)
        .then((response) => accept(response))
        .catch((error) => reject(500, error.toString()));

      break;
    }

    case "join":
    {
      const { peerName, spy } = request;

      // Here we may want to check whether `spy` is `true` and allow or reject
      // this join request based on app logic/policy.

      mediasoupRoom.receiveRequest(request)
        .then((response) =>
        {
          // Get the new mediasoup Peer instance.
          const peer = mediasoupRoom.getPeerByName(peerName);

          console.info("new peer joined the room: %o", peer);

          accept(response);
        })
        .catch((error) => reject(500, error.toString()));

      break;
    }
  }
}

room.createActiveSpeakerDetector()

Creates and returns a new ActiveSpeakerDetector.

room.createRtpStreamer(producer, options)

Returns a Promise resolving to a new RtpStreamer associated to the given producer.

Argument Type Description Required Default
producer Producer Associated producer. Yes  
options RtpStreamerOptions Options for the rtpStreamer. Yes  

Events

The Room class inherits from EventEmitter.

room.on(“close”, fn(appData))

Emitted when the room is closed.

Argument Type Description
appData Any Custom app data.

room.on(“newpeer”, fn(peer))

Emitted when a new peer is created.

Argument Type Description
peer Peer New peer.

room.on(“audiolevels”, fn(audioLevelInfos))

Emitted every few milliseconds. It provides information regarding the audio level of each audio producer in the room.

Argument Type Description
audioLevelInfos sequence<AudioLevelInfo> Audio level information entries ordered by audioLevel (higher first).

Peer

A peer is the local representation of a remote media endpoint that connects to mediasoup and sends/receives media streams.

For more information, check the Glossary section.

Properties

peer.name

  • Read only

The name (String) of the peer.

peer.closed

  • Read only

A Boolean indicating whether the peer has been closed.

peer.appData

  • Read-write

Custom data set by the application. When the peer is created via the mediasoup protocol, the appData is filled with the corresponding field in the join request.

peer.rtpCapabilities

  • Read only

An Object with the RTP capabilities of the peer, miming the syntax of RTCRtpCapabilities in ORTC.

peer.transports

  • Read only

An Array with the list of WebRtcTransport instances associated to the peer in the order in which they were created.

peer.producers

  • Read only

An Array with the list of Producer instances associated to the peer in the order in which they were created.

peer.consumers

  • Read only

An Array with the list of Consumer instances associated to the peer in the order in which they were created.

Methods

peer.close([appData])

Closes the peer, including all its transports, producers and consumers, and triggers a close event.

Argument Type Description Required Default
appData Any Custom app data. No  

peer.getTransportById(id)

Retrieves the WebRtcTransport with the given id, or undefined if not found.

Argument Type Description Required Default
id Number WebRtcTransport id. Yes  

peer.getProducerById(id)

Retrieves the Producer with the given id, or undefined if not found.

Argument Type Description Required Default
id Number Producer id. Yes  

peer.getConsumerById(id)

Retrieves the Consumer with the given id, or undefined if not found.

Argument Type Description Required Default
id Number Consumer id. Yes  

peer.receiveRequest(request)

Provide the peer with a mediasoup protocol request payload (commonly generated by mediasoup-client).

Argument Type Description Required Default
request Object mediasoup protocol request. Yes  

Just mediasoup protocol requests with “peer” target must be given to this method, meaning that the mediasoup protocol payload:

  • must have target: "peer", and
  • must NOT have notification: true.

The method returns a Promise resolving to a mediasoup protocol response payload that must be sent back to the request originator.

peer.receiveNotification(notification)

Provide the peer with a mediasoup protocol notification payload (commonly generated by mediasoup-client).

Argument Type Description Required Default
notification Object mediasoup protocol notification. Yes  

Just mediasoup protocol notifications with “peer” target must be given to this method, meaning that the mediasoup protocol payload:

  • must have target: "peer", and
  • must have notification: true.

The method does not return anything.

Events

The Peer class inherits from EventEmitter.

peer.on(“close”, fn(originator, appData))

Emitted when the peer is closed.

Argument Type Description
originator String “local” or “remote”.
appData Any Custom app data.

peer.on(“notify”, fn(notification))

Emitted when a new mediasoup protocol notification must be sent by the Node.js application to the associated mediasoup-client.

Argument Type Description
notification Object mediasoup protocol notification.

peer.on(“newtransport”, fn(webrtcTransport))

Emitted when a new webrtcTransport is created.

Argument Type Description
webrtcTransport WebRtcTransport New webrtcTransport.

peer.on(“newproducer”, fn(producer))

Emitted when a new producer is created.

Argument Type Description
producer Producer New producer.

peer.on(“newconsumer”, fn(consumer))

Emitted when a new consumer is created.

Argument Type Description
consumer Consumer New consumer.

Transport

A transport represents a path for sending or receiving audio/video RTP.

For more information, check the Glossary section.

Currently mediasoup implements two transport types:

Dictionaries

IceParameters

Field Type Description Required Default
usernameFragment String ICE username fragment. No  
password String ICE password. No  
iceLite Boolean ICE Lite. No  

IceCandidate

Field Type Description Required Default
foundation String Unique identifier that allows ICE to correlate candidates that appear on multiple transports. Yes  
priority Number The assigned priority of the candidate. Yes  
ip String The IP address of the candidate. Yes  
protocol String The protocol of the candidate (“udp” / “tcp”). Yes  
port Number The port for the candidate. Yes  
type String The type of candidate (always “host”). Yes  
tcpType String The type of TCP candidate (always “passive”). No  

IceSelectedTuple

Field Type Description Required Default
localIP String Local IP of the tuple. Yes  
localPort Number Local port of the tuple. Yes  
remoteIP String Remote IP of the tuple. Yes  
remotePort Number Remote port of the tuple. Yes  
protocol String The protocol of the tuple (“udp” / “tcp”). Yes  

LocalDtlsParameters

Field Type Description Required Default
role DtlsRole Local DTLS role. No “auto”
fingerprints LocalDtlsFingerprints Local DTLS fingerprints. Yes  

LocalDtlsFingerprints

Map of DTLS algorithms (as defined in the “Hash function Textual Names” registry initially specified in RFC 4572 Section 8) and their corresponding certificate fingerprint values (in lowercase hex string as expressed utilizing the syntax of “fingerprint” in RFC 4572 Section 5).

Field Type Description Required Default
sha-1 String SHA-1 certificate fingerprint. Yes  
sha-224 String SHA-224 certificate fingerprint. Yes  
sha-256 String SHA-256 certificate fingerprint. Yes  
sha-384 String SHA-384 certificate fingerprint. Yes  
sha-512 String SHA-512 certificate fingerprint. Yes  

RemoteDtlsParameters

Field Type Description Required Default
role DtlsRole Remote DTLS role. No “auto”
fingerprint RemoteDtlsFingerprint Remote DTLS fingerprint. Yes  

RemoteDtlsFingerprint

Field Type Description Required Default
algorithm String Hash function algorithm (“sha-1” / “sha-224” / “sha-256” / “sha-384” / “sha-512”). Yes  
value String Certificate fingerprint in lowercase hex. Yes  

Enums

IceState

Value Description
“new” No ICE Binding Requests have been received yet.
“connected” Valid ICE Binding Request have been received, but none with USE-CANDIDATE attribute. Outgoing media is allowed.
“completed” ICE Binding Request with USE_CANDIDATE attribute has been received. Media in both directions is now allowed.
“disconnected” ICE was “connected” or “completed” but it has suddenly failed (currently this can just happen if the selected tuple has “tcp” protocol).
“closed” ICE state when the transport has been closed.

DtlsRole

Value Description
“auto” The DTLS role is determined based on the resolved ICE role (the “controlled” role acts as DTLS client, the “controlling” role acts as DTLS server”). Since mediasoup is a ICE Lite implementation it always behaves as ICE “controlled”.
“client” DTLS client role.
“server” DTLS server role.

DtlsState

Value Description
“new” DTLS procedures not yet initiated.
“connecting” DTLS connecting.
“connected” DTLS successfully connected (SRTP keys already extracted).
“failed” DTLS connection failed.
“closed” DTLS state when the transport has been closed.

WebRtcTransport

A webrtcTransport represents a network path negotiated by both, mediasoup-client and mediasoup, via ICE and DTLS.

For more information, check the Glossary section.

mediasoup is a ICE Lite implementation, meaning that it will never initiate ICE connections but expect ICE Binding Requests on its open ports.

Dictionaries

MirroringOptions

Field Type Description Required Default
remoteIP String Destination IP. Yes  
remotePort Number Destination port. Yes  
localIP String Local IP. No rtcIPv4 or rtcIPv6 given in ServerSettings
sendRtp Boolean Whether RTP sent to the client must be mirrored. No true
sendRtcp Boolean Whether RTCP sent to the client must be mirrored. No true
recvRtp Boolean Whether RTP received from the client must be mirrored. No true
recvRtcp Boolean Whether RTCP received from the client must be mirrored. No true

If localIP is given, the RTP port range given in ServerSettings (rtcMinPort - rtcMaxPort) is not honored and, instead, any available random port will be used.

Properties

webrtcTransport.id

  • Read only

Unique identifier (Number).

webrtcTransport.closed

  • Read only

A Boolean indicating whether the webrtcTransport has been closed.

webrtcTransport.appData

  • Read-write

Custom data set by the application. When the webrtcTransport is created via the mediasoup protocol, the appData is filled with the corresponding field in the createTransport request.

webrtcTransport.direction

  • Read only

A String (“send” or “recv”) representing the direction of the media over this webrtcTransport.

webrtcTransport.iceRole

  • Read only

String indicating the ICE role of the webrtcTransport. Due to the ICE Lite design, this is always “controlled”.

webrtcTransport.iceLocalParameters

  • Read only

Local IceParameters of the webrtcTransport.

webrtcTransport.iceLocalCandidates

  • Read only

Sequence of local IceCandidate Objects associated to this webrtcTransport.

webrtcTransport.iceState

  • Read only

The current IceState of the webrtcTransport.

webrtcTransport.iceSelectedTuple

  • Read only

The selected IceSelectedTuple indicating information about the selected ICE candidate pair.

It is undefined if ICE is not yet established (no working candidate pair was found).

webrtcTransport.dtlsLocalParameters

  • Read only

LocalDtlsParameters of the webrtcTransport.

webrtcTransport.dtlsState

  • Read only

The current DtlsState of the webrtcTransport.

webrtcTransport.dtlsRemoteCert

  • Read only

The remote certificate in PEM format (String). It is set once dtlsState becomes “connected”.

The application may want to inspect the remote certificate for authorization purposes by using some certificates utility such as the Node pem module.

Methods

webrtcTransport.close([appData])

Closes the webrtcTransport and triggers a close event.

Argument Type Description Required Default
appData Any Custom app data. No  

webrtcTransport.setMaxBitrate(bitrate)

Set maximum bitrate for media streams sent by the remote endpoint over this webrtcTransport. Returns a Promise that resolves to this webrtcTransport.

Argument Type Description Required Default
bitrate Number Maximum sending bitrate in bps. Yes 0 (no limit)

This method can just be called on open webrtcTransports with direction: "send" (it will throw otherwise).

Usage example:

peer.on('newtransport', (webrtcTransport) =>
{
  if (webrtcTransport.direction === 'send')
    webrtcTransport.setMaxBitrate(250000);
});

webrtcTransport.getStats()

Returns a Promise resolving to an array of Objects containing RTC stats related to the webrtcTransport.

Check the RTC stats section for more details.

webrtcTransport.startMirroring(options)

Enables RTP/RTCP mirroring. The selected RTP/RTCP over this webrtcTransport will be sent to the given address (see options).

Argument Type Description Required Default
options MirroringOptions Options. Yes  

webrtcTransport.stopMirroring()

Stops RTP/RTCP mirroring.

Events

The WebRtcTransport class inherits from EventEmitter.

webrtcTransport.on(“close”, fn(originator, appData))

Emitted when the webrtcTransport is closed.

Argument Type Description
originator String “local” or “remote”.
appData Any Custom app data.

webrtcTransport.on(“iceselectedtuplechange”, fn(iceSelectedTuple))

Emitted when the ICE selected tuple changes.

Argument Type Description
iceSelectedTuple IceSelectedTuple The new ICE selected tuple.

webrtcTransport.on(“icestatechange”, fn(iceState))

Emitted when the ICE state changes.

Argument Type Description
iceState IceState The new ICE state.

webrtcTransport.on(“dtlsstatechange”, fn(dtlsState))

Emitted when the DTLS state changes.

Argument Type Description
dtlsState DtlsState The new DTLS state.

PlainRtpTransport

A plainRtpTransport represents a network path negotiated on which plain RTP and RTCP (no ICE nor DTLS) is carried.

Dictionaries

RemoteParameters

Field Type Description Required Default
ip String Destination IP. Yes  
port Number Destination port. Yes  

Properties

plainRtpTransport.id

  • Read only

Unique identifier (Number).

plainRtpTransport.closed

  • Read only

A Boolean indicating whether the plainRtpTransport has been closed.

plainRtpTransport.tuple

  • Read only

The 5-Tuple indicating information about the connection.

plainRtpTransport.localIP

  • Read only

The local IP address (String) of the transport.

plainRtpTransport.localPort

  • Read only

The local port (Number) of the transport.

Methods

plainRtpTransport.close()

Closes the plainRtpTransport.

plainRtpTransport.setRemoteParameters(parameters)

Set the remote IP address and port for the plainRtpTransport.

Argument Type Description Required Default
parameters PlainRtpRemoteParameters Remote parameters. Yes  

Producer

A producer represents an audio/video media track sent to the room.

For more information, check the Glossary section.

Properties

producer.id

  • Read only

Unique identifier (Number).

producer.closed

  • Read only

A Boolean indicating whether the producer has been closed.

producer.appData

  • Read-write

Custom data set by the application. When the producer is created via the mediasoup protocol, the appData is filled with the corresponding field in the createProducer request.

producer.kind

  • Read only

The media kind (“audio” or “video”) handled by the producer.

producer.peer

  • Read only

The Peer owner of this producer.

producer.transport

  • Read only

The Transport assigned to this producer.

producer.rtpParameters

  • Read only

An Object with the effective RTP parameters of the producer, miming the syntax of RTCRtpParameters in ORTC.

producer.locallyPaused

  • Read only

Boolean indicating whether this producer has been locally paused (in mediasoup).

producer.remotelyPaused

  • Read only

Boolean indicating whether this producer has been remotely paused (by the remote client).

producer.paused

  • Read only

Boolean indicating whether this producer has been locally or remotely paused.

producer.preferredProfile

  • Read only

String indicating the preferred RTP profile set via producer.setPreferredProfile().

Methods

producer.close([appData])

Closes the producer and triggers a close event.

Argument Type Description Required Default
appData Any Custom app data. No  

producer.pause([appData])

Pauses the producer locally, meaning that no RTP will be relayed to its associated consumers.

Argument Type Description Required Default
appData Any Custom app data sent to the remote client. No  

producer.resume([appData])

Resumes the producer locally, meaning that RTP will be relayed again to its associated consumers (unless the producer was also remotely paused).

Argument Type Description Required Default
appData Any Custom app data sent to the remote client. No  

producer.setPreferredProfile(profile)

Set the given RTP profile as the desired profile for all its associated consumers.

For more information, check the Glossary section.

Argument Type Description Required Default
profile String Preffered RTP profile. Yes  

producer.getStats()

Returns a Promise resolving to an array of Objects containing RTC stats related to the producer.

Check the RTC stats section for more details.

Events

The Producer class inherits from EventEmitter.

producer.on(“close”, fn(originator, appData))

Emitted when the producer is closed.

Argument Type Description
originator String “local” or “remote”.
appData Any Custom app data.

producer.on(“pause”, fn(originator, appData))

Emitted when the producer is locally or remotely paused.

Argument Type Description
originator String “local” or “remote”.
appData Any Custom app data.

producer.on(“resume”, fn(originator, appData))

Emitted when the producer is locally or remotely resumed.

Argument Type Description
originator String “local” or “remote”.
appData Any Custom app data.

Consumer

A consumer represents an audio/video media track sent to a remote client.

For more information, check the Glossary section.

Properties

consumer.id

  • Read only

Unique identifier (Number).

consumer.closed

  • Read only

A Boolean indicating whether the consumer has been closed.

consumer.appData

  • Read-write

Custom data set by the application.

consumer.kind

  • Read only

The media kind (“audio” or “video”) handled by the consumer.

consumer.peer

  • Read only

The Peer owner of this consumer (if any).

consumer.transport

  • Read only

The Transport assigned to this consumer.

consumer.rtpParameters

  • Read only

An Object with the effective RTP parameters of the consumer, miming the syntax of RTCRtpParameters in ORTC.

consumer.source

  • Read only

The RTP source of this consumer. Typically it corresponds to a Producer.

consumer.enabled

  • Read only

Boolean indicating whether this consumer has been enabled (so the endpoint can receive RTP). Being enabled also means that a transport has been assigned to this consumer.

consumer.locallyPaused

  • Read only

Boolean indicating whether this consumer has been locally paused (in mediasoup).

consumer.remotelyPaused

  • Read only

Boolean indicating whether this consumer has been remotely paused (by the remote client).

consumer.sourcePaused

  • Read only

Boolean indicating whether the source of this consumer has been paused.

consumer.paused

  • Read only

Boolean indicating whether this consumer has been locally or remotely paused, or its source has been paused.

consumer.preferredProfile

  • Read only

String indicating the preferred RTP profile set via consumer.setPreferredProfile().

consumer.effectiveProfile

  • Read only

String indicating the effective current RTP profile of this consumer.

Methods

consumer.close([appData])

Closes the consumer and triggers a close event.

Argument Type Description Required Default
appData Any Custom app data. No  

consumer.pause([appData])

Pauses the consumer locally, meaning that no RTP will be relayed to the remote client.

Argument Type Description Required Default
appData Any Custom app data sent to the remote client. No  

consumer.resume([appData])

Resumes the consumer locally, meaning that RTP will be relayed again to the remote client (unless the consumer was also remotely paused).

Argument Type Description Required Default
appData Any Custom app data sent to the remote client. No  

consumer.setPreferredProfile(profile)

Set the given RTP profile as the desired profile. No profile higher than the given one will become effective profile for this consumer.

For more information, check the Glossary section.

Argument Type Description Required Default
profile String Preffered RTP profile. Yes  

If no preferred profile is set into a consumer (meaning that “default” will be used) and the associated source (producer) has a preferred profile, that will be used in the consumer.

consumer.requestKeyFrame()

Request a RTCP PLI to the RTP source (if supported).

consumer.getStats()

Returns a Promise resolving to an array of Objects containing RTC stats related to the consumer.

Check the RTC stats section for more details.

Events

The Consumer class inherits from EventEmitter.

consumer.on(“close”, fn(originator, appData))

Emitted when the consumer is closed.

Argument Type Description
originator String “local” or “remote”.
appData Any Custom app data.

consumer.on(“pause”, fn(originator, appData))

Emitted when the consumer is locally or remotely paused.

Argument Type Description
originator String “local” or “remote”.
appData Any Custom app data.

consumer.on(“resume”, fn(originator, appData))

Emitted when the consumer is locally or remotely resumed.

Argument Type Description
originator String “local” or “remote”.
appData Any Custom app data.

consumer.on(“effectiveprofilechange”, fn(profile))

Emitted when the effective profile changes.

Argument Type Description
profile String Current effective RTP profile.

consumer.on(“handled”, fn())

Emitted when a transport is given to this consumer.

consumer.on(“unhandled”, fn())

Emitted when the associated transport is closed.

ActiveSpeakerDetector

An activeSpeakerDetector provides the room with the highest audio volume level.

The ActiveSpeakerDetector mechanism is based on the audiolevels event of the room.

Methods

activeSpeakerDetector.close()

Closes the activeSpeakerDetector and triggers a close event.

Events

The ActiveSpeakerDetector class inherits from EventEmitter.

activeSpeakerDetector.on(“close”, fn())

Emitted when the activeSpeakerDetector is closed.

activeSpeakerDetector.on(“activespeakerchange”, fn(peer, producer))

Emitted when a new active speaker is detected.

Argument Type Description
peer Peer Associated peer.
producer Producer Associated audio producer.

Both peer and producer can be undefined when no active speaker is detected.

RtpStreamer

An rtpStreamer represents both a specialized Consumer and a PlainRtpTransport. It's created by calling the room.createRtpStreamer() by passing a Producer and RtpStreamOptions.

The RTP and RTCP received by the producer will be relayed/mirrored to the given IP and port using plain RTP/RTCP.

Dictionaries

RtpStreamerOptions

Field Type Description Required Default
remoteIP String Destination IP. Yes  
remotePort Number Destination port. Yes  
localIP String Local IP. No rtcIPv4 or rtcIPv6 given in ServerSettings

If localIP is given, the RTP port range given in ServerSettings (rtcMinPort - rtcMaxPort) is not honored and, instead, any available random port will be used.

Properties

rtpStreamer.consumer

  • Read only

The generated Consumer instance.

rtpStreamer.transport

  • Read only

The generated PlainRtpTransport instance.

Methods

rtpStreamer.close()

Closes the rtpStreamer, including its consumer and transport, and triggers a close event.

Events

The RtpStreamer class inherits from EventEmitter.

rtpStreamer.on(“close”, fn())

Emitted when the rtpStreamer is closed.

errors

The errors module (exported via mediasoup.errors) holds custom Error classes internally used by mediasoup.

Classes

errors.InvalidStateError

This error happens when an API method is called on an Object in invalid state (for example when such an Object is closed).