Const
While set a property to a SDP object representation is possible directly, we could prefer add a new property without overload a possible already existing value. This function allows to add a property to our SDP representation:
the SDP object representation on which added the attribute
the string attribut in a format "key:value" or just "key" to add an attribute without value
the key part of the attribute added (or if value is empty it returns the same attribute as passed in argument)
Unserialize SDP string to a manipulable JS object representation It's an object with:
SDP string reprensentation
SDP object representation, iterable through media description
[
group: "DUNBLE 0 1",
o: "- 1699450751193623 0 IN IP4 0.0.0.0",
s: "-",
t: "0 0",
v: "0",
ice-lite: "",
length: 2,
{
m: "audio 9 UDP/TLS/RTP/SAVPF 111",
c: "IN IP4 0.0.0.0",
rtcp: "9",
sendonly: "",
setup: "passive",
fingerprint: "sha-256 51:36:ED:78:A4:9F:25:8C:39:9A:0E:A0:B4:9B:6E:04:37:FF:AD:96:93:71:43:88:2C:0B:0F:AB:6F:9A:52:B8",
ice-ufrag: "fa37",
ice-pwd: "JncCHryDsbzayy4cBWDxS2",
rtcp-mux: "",
rtcp-rsize: "",
rtpmap: "111 opus/48000/2",
rtcp-fb: "111 nack",
id: "0",
fmtp: "111 minptime=10;useinbandfec=1",
candidate: "1 1 udp 2130706431 89.105.221.108 56643 typ host",
end-of-candidates: ""
},
{
m: "video 9 UDP/TLS/RTP/SAVPF 106",
c: "IN IP4 0.0.0.0",
rtcp: "9",
sendonly: "",
setup: "passive",
fingerprint: "sha-256 51:36:ED:78:A4:9F:25:8C:39:9A:0E:A0:B4:9B:6E:04:37:FF:AD:96:93:71:43:88:2C:0B:0F:AB:6F:9A:52:B8",
ice-ufrag: "fa37",
ice-pwd: "JncCHryDsbzayy4cBWDxS2",
rtcp-mux: "",
rtcp-rsize: "",
rtpmap: "106 H264/90000",
rtcp-fb: [
"106 nack",
"106 goog-remb"
],
mid: "1",
fmtp: "106 profile-level-id=42e01f;level-asymmetry-allowed=1;packetization-mode=1",
candidate: "1 1 udp 2130706431 89.105.221.108 56643 typ host",
end-of-candidates: ""
}
]
Parse an attribute in a format "key:value"
string attribute to parse
the {key, value} result, with value undefined if attribute was a "key" without value
While it's possible to delete a attribute manually on the SDP object representation with a delete sdp.key, we could prefer remove only a value in a sdp.key array containing multiple values. Like opposite to addAttribute this method allows to remove an unique attribute value.
the SDP object representation on which removed the attribute
the string attribut in a format "key:value" or just "key" to remove the whole attribute and all its values
the key part of the attribute removed (or if value is empty it returns the same attribute as passed in argument)
const peerConnection = new RTCPeerConnection();
peerConnection.createOffer()
.then( offer =>
// Change offer.sdp string to a JS manipulable object
const sdp = SDP.fromString(offer.sdp || '');
// Change a property of SDP
sdp.v = 2; // change SDP version
// Reserialize to the legal SDP string format
offer.sdp = SDP.toString(sdp);
// Set SDP offer to peerConnection
peerConnection.setLocalDescription(offer);
)
Generated using TypeDoc
Toolkit to deal with Session Description Protocol (SDP), mainly to tranform a SDP string Offer/Answer to a manipulable JS object representation