Close Track
Overview
The close track API is used indicate to the SFU that you are not longer publishing the track. To close the track, you should remove the track from the peerConnection, generate a new sdp and send the sdp and trackId you want to close to the close track API. In the response you will get the remote sdp that you should add to the peerConnection.
Authentication
You must provide bearer token in the Authorization
header. The bearer token in the secret of the SFU App that you have created in the dashboard. When you create an SFU app, you will get the SFU App Id and the Secret.
- Header:
Authorization: Bearer {secret}
HTTP Request
POST
https://global.sfu.metered.ca/api/sfu/:sfu_app_id/session/:session_id/track/close
URL Parameters
Parameter Name | Type | Description |
---|---|---|
sfu_app_id | string | The unique identifier of your SFU app. This parameter is required to specify which SFU app the session should be created for. You can find the SFU app ID in the dashboard after creating the SFU app. |
session_id | string | The unique identifier of the session. This parameter is required to specify which session the track should be closed for. You can find the session ID in the response of the session creation API. |
Headers
Header | Value | Description |
---|---|---|
Authorization | Bearer {secret} | The bearer token which is the secret of the SFU App created in the dashboard. |
Content-Type | application/json | Indicates that the request body format is JSON. |
Request Body
The request body contains an array of trackIds
that you have removed from the peerConnection and the sdp.
{
tracks: [
{
"trackId": id
}
],
sessionDescription: offer
}
Field | Type | Required | Description |
---|---|---|---|
tracks | array | Yes | An array of track objects to be closed. Each object should contain trackId . |
sessionDescription | object | Yes | The SDP (Session Description Protocol) information from the peerConnection. |
Response
{
"sessionId": "..",
"success": true,
"sessionDescription": {},
}
Code Example
peerConnection.removeTrack(sender);
const offer = await peerConnection.createOffer();
await peerConnection.setLocalDescription(offer);
const response = await fetch(`${HOST}/api/sfu/${SFU_APP_ID}/session/${SESSION_ID}/track/close`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${SECRET}`
},
body: JSON.stringify({
tracks: [
{
"trackId": id
}
],
sessionDescription: offer
})
});
const json = await response.json();
console.log("Close track response", json);
await peerConnection.setRemoteDescription(new RTCSessionDescription(json.sessionDescription));