Although mediasoup does not implement a signaling protocol, both the client (mediasoup-client) and the server (mediasoup) must exchange messages. Those messages can be request/response pairs or notifications, and can be sent in both directions.
Those messages can be serialized to JSON bodies for network transmission, but may be converted into JavaScripts Objects (JSON.parse()
) before they are given to the corresponding API methods in both mediasoup and mediasoup-client.
The exact definition of the message payloads that must be exchanged is documented in the MEDIASOUP_PROTOCOL.md file included in the mediasoup-client source code.
The application developer does not need to know in depth about these messages, but can intercept them for advanced usages.
mediasoup-client can generate both requests and notifications to be sent to mediasoup, while mediasoup just generates notifications and responses for mediasoup-client.
notification: true
key/value and does NOT require a response.It's up to the application how to correlate those requests and their associated responses, for example by enveloping the request and its response into a signaling transaction that uses a id
field to match them.
Both requests and notifications sent by mediasoup-client have a target
key whose value can be “room” or “peer”:
target: "room"
means that the request or notification must be delivered to the corresponding server side Room.
Room
just accepts requests by calling to its room.receiveRequest() method.target: "peer"
means that the request or notification must be delivered to the corresponding server side Peer.
Peer
accepts requests by calling to its peer.receiveRequest() method.Peer
accepts notifications by calling to its peer.receiveNotification() method.It's up to the application how to correlate those requests and their associated responses, for example by enveloping the request and its response into a signaling transaction that uses a id
field to match them.
Those real messages are directly taken from the MEDIASOUP_PROTOCOL.md file included in the mediasoup-client source code. Here they are represented in JSON format.
{
"method": "queryRoom",
"target": "room"
}
{
"rtpCapabilities": {},
"mandatoryCodecPayloadTypes": []
}
{
"method": "createTransport",
"target": "peer",
"id": 1111,
"options": {},
"dtlsParameters": {},
"appData": "foo"
}
{
"iceParameters": {},
"iceCandidates": [],
"dtlsParameters": {}
}
{
"method": "leave",
"target": "peer",
"notification": true,
"appData": 1234
}
{
"method": "transportStats",
"target": "peer",
"notification": true,
"id": 3333,
"stats": []
}