@ceeblue/web-utils
    Preparing search index...

    Variable SDPConst

    SDP: {
        addAttribute(sdp: object, attribute: string): string;
        fromString(lines: string): any;
        parseAttribute(
            attribute: string,
        ): { key: string; value: string | undefined };
        removeAttribute(sdp: object, attribute: string): string;
        toString(sdp: any): string;
    } = ...

    Toolkit to deal with Session Description Protocol (SDP), mainly to tranform a SDP string Offer/Answer to a manipulable JS object representation

    Type Declaration

    • addAttribute: function
      • 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:

        • if the key's attribute doesn't exists yet it adds it like a simple JS property sdp[key] = value
        • if the key's attribute exists already it morphs the value to a Array and push it inside

        Parameters

        • sdp: object

          the SDP object representation on which added the attribute

        • attribute: string

          the string attribut in a format "key:value" or just "key" to add an attribute without value

        Returns string

        the key part of the attribute added (or if value is empty it returns the same attribute as passed in argument)

    • fromString: function
      • Unserialize SDP string to a manipulable JS object representation It's an object with:

        • root SDP properties
        • media description iterable

        Parameters

        • lines: string

          SDP string reprensentation

        Returns any

        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: ""
        }
        ]
    • parseAttribute: function
      • Parse an attribute in a format "key:value"

        Parameters

        • attribute: string

          string attribute to parse

        Returns { key: string; value: string | undefined }

        the {key, value} result, with value undefined if attribute was a "key" without value

    • removeAttribute: function
      • 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.

        Parameters

        • sdp: object

          the SDP object representation on which removed the attribute

        • attribute: string

          the string attribut in a format "key:value" or just "key" to remove the whole attribute and all its values

        Returns string

        the key part of the attribute removed (or if value is empty it returns the same attribute as passed in argument)

    • toString: function
      • Serialize SDP JS object to a SDP string legal representation

        Parameters

        • sdp: any

          SDP object reprensetation

        Returns string

        SDP string reprensentation

    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);
    )