Skip to main content

Re-negotiate

Overview

This API renegotiates an existing session with the Metered Global Cloud SFU. You need to renegotiate a session when the Session Description Protocol (SDP) information needs to be updated, for example when subscribing to a new track.

Authentication

You must provide a bearer token in the Authorization header. This bearer token is the secret of the SFU App that you created in the dashboard.

Header

Authorization: Bearer {secret}

HTTP Request

PUT https://global.sfu.metered.ca/api/sfu/:sfu_app_id/session/:session_id/renegotiate

URL Parameters

Parameter NameTypeDescription
sfu_app_idstringThe unique identifier of your SFU app. This parameter is required to specify which SFU app the session belongs to. You can find the SFU app ID in the dashboard after creating the SFU app.
session_idstringThe unique identifier representing the peerConnection. This parameter is required to specify which session to renegotiate. This ID is returned in the response when creating a session.

Headers

HeaderValueDescription
AuthorizationBearer {secret}The bearer token which is the secret of the SFU App created in the dashboard.
Content-Typeapplication/jsonIndicates that the request body format is JSON.

Request Body

{
"sessionDescription": <sdp>
}
FieldTypeRequireddescription
sessionDescriptionstringYesThe updated SDP (Session Description Protocol) information from the peerConnection.

Response

Success Response

The API will return a 200 status code if the renegotiation is successful.

Code Example

Here is an example of how to call the renegotiate API after subscribing to a track:

// jsonUserB  contains the response from the subscribe track api
await peerConnectionUserB.setRemoteDescription(
new RTCSessionDescription(jsonUserB.sessionDescription)
);
// Create a new answer SDP
const answerUserB = await peerConnectionUserB.createAnswer();
await peerConnectionUserB.setLocalDescription(answerUserB);
// Renegotiate the session for userB
await fetch(`${host}/api/sfu/${sfuAppId}/session/${sessionIdUserB}/renegotiate`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${secret}`,
},
body: JSON.stringify({
sessionDescription: answerUserB,
}),
});