DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (d5efb485c09c)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
<!doctype html>
<meta charset=utf-8>
<title>RTCPeerConnection Set Session Description - Transceiver Tests</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="RTCPeerConnection-helper.js"></script>
<script>
  'use strict';

  // Test is based on the following editor draft:
  // https://w3c.github.io/webrtc-pc/archives/20170605/webrtc.html

  // The following helper functions are called from RTCPeerConnection-helper.js:
  //   generateAnswer

  /*
    4.3.2.  Interface Definition

      [Constructor(optional RTCConfiguration configuration)]
      interface RTCPeerConnection : EventTarget {
        Promise<void>                      setLocalDescription(
            RTCSessionDescriptionInit description);

        Promise<void>                      setRemoteDescription(
            RTCSessionDescriptionInit description);
        ...
      };

    4.6.2.  RTCSessionDescription Class
      dictionary RTCSessionDescriptionInit {
        required RTCSdpType type;
                 DOMString  sdp = "";
      };

    4.6.1.  RTCSdpType
      enum RTCSdpType {
        "offer",
        "pranswer",
        "answer",
        "rollback"
      };

    5.4.  RTCRtpTransceiver Interface

      interface RTCRtpTransceiver {
        readonly attribute DOMString?                  mid;
        [SameObject]
        readonly attribute RTCRtpSender                sender;
        [SameObject]
        readonly attribute RTCRtpReceiver              receiver;
        readonly attribute RTCRtpTransceiverDirection  direction;
        readonly attribute RTCRtpTransceiverDirection? currentDirection;
        ...
      };
   */

  /*
    4.3.1.6.  Set the RTCSessionSessionDescription
      7.  If description is set as a local description, then run the following steps for
          each media description in description that is not yet associated with an
          RTCRtpTransceiver object:
        1.  Let transceiver be the RTCRtpTransceiver used to create the media
            description.
        2.  Set transceiver's mid value to the mid of the corresponding media
            description.
   */
  promise_test(t => {
    const pc = new RTCPeerConnection();
    t.add_cleanup(() => pc.close());
    const transceiver = pc.addTransceiver('audio');
    assert_equals(transceiver.mid, null);

    return pc.createOffer()
    .then(offer => {
      assert_equals(transceiver.mid, null,
        'Expect transceiver.mid to still be null after createOffer');

      return pc.setLocalDescription(offer)
      .then(() => {
        assert_equals(typeof transceiver.mid, 'string',
          'Expect transceiver.mid to set to valid string value');

        assert_equals(offer.sdp.includes(`\r\na=mid:${transceiver.mid}`), true,
          'Expect transceiver mid to be found in offer SDP');
      });
    });
  }, 'setLocalDescription(offer) with m= section should assign mid to corresponding transceiver');

  /*
    4.3.1.6.  Set the RTCSessionSessionDescription
      8.  If description is set as a remote description, then run the following steps
          for each media description in description:
        2.  If no suitable transceiver is found (transceiver is unset), run the following
            steps:
          1.  Create an RTCRtpSender, sender, from the media description.
          2.  Create an RTCRtpReceiver, receiver, from the media description.
          3.  Create an RTCRtpTransceiver with sender, receiver and direction, and let
              transceiver be the result.
        3.  Set transceiver's mid value to the mid of the corresponding media description.
   */
  promise_test(t => {
    const pc1 = new RTCPeerConnection();
    t.add_cleanup(() => pc1.close());
    const pc2 = new RTCPeerConnection();

    t.add_cleanup(() => pc2.close());

    const transceiver1 = pc1.addTransceiver('audio');
    assert_array_equals(pc1.getTransceivers(), [transceiver1]);
    assert_array_equals(pc2.getTransceivers(), []);

    return pc1.createOffer()
    .then(offer => {
      return Promise.all([
        pc1.setLocalDescription(offer),
        pc2.setRemoteDescription(offer)
      ])
      .then(() => {
        const transceivers = pc2.getTransceivers();
        assert_equals(transceivers.length, 1,
          'Expect new transceiver added to pc2 after setRemoteDescription');

        const [ transceiver2 ] = transceivers;

        assert_equals(typeof transceiver2.mid, 'string',
          'Expect transceiver2.mid to be set');

        assert_equals(transceiver1.mid, transceiver2.mid,
          'Expect transceivers of both side to have the same mid');

        assert_equals(offer.sdp.includes(`\r\na=mid:${transceiver2.mid}`), true,
          'Expect transceiver mid to be found in offer SDP');
      });
    });
  }, 'setRemoteDescription(offer) with m= section and no existing transceiver should create corresponding transceiver');

  /*
    4.3.1.6.  Set the RTCSessionSessionDescription
      9.  If description is of type "rollback", then run the following steps:
        1.  If the mid value of an RTCRtpTransceiver was set to a non-null value by
            the RTCSessionDescription that is being rolled back, set the mid value
            of that transceiver to null, as described by [JSEP] (section 4.1.8.2.).
   */
  promise_test(t => {
    const pc = new RTCPeerConnection();
    t.add_cleanup(() => pc.close());
    const transceiver = pc.addTransceiver('audio');
    assert_equals(transceiver.mid, null);

    return pc.createOffer()
    .then(offer => {
      assert_equals(transceiver.mid, null);
      return pc.setLocalDescription(offer);
    })
    .then(() => {
      assert_not_equals(transceiver.mid, null);
      return pc.setLocalDescription({ type: 'rollback' });
    })
    .then(() => {
      assert_equals(transceiver.mid, null,
      'Expect transceiver.mid to become null again after rollback');
    });
  }, 'setLocalDescription(rollback) should unset transceiver.mid');

  promise_test(t => {
    const pc = new RTCPeerConnection();
    t.add_cleanup(() => pc.close());
    const transceiver1 = pc.addTransceiver('audio');
    assert_equals(transceiver1.mid, null);

    return pc.createOffer()
    .then(offer =>
       pc.setLocalDescription(offer)
       .then(() => generateAnswer(offer)))
    .then(answer => pc.setRemoteDescription(answer))
    .then(() => {
      // pc is back to stable state
      // create another transceiver
      const transceiver2 = pc.addTransceiver('video');

      assert_not_equals(transceiver1.mid, null);
      assert_equals(transceiver2.mid, null);

      return pc.createOffer()
      .then(offer => pc.setLocalDescription(offer))
      .then(() => {
        assert_not_equals(transceiver1.mid, null);
        assert_not_equals(transceiver2.mid, null,
          'Expect transceiver2.mid to become set');

        return pc.setLocalDescription({ type: 'rollback' });
      })
      .then(() => {
        assert_not_equals(transceiver1.mid, null,
          'Expect transceiver1.mid to stay set');

        assert_equals(transceiver2.mid, null,
          'Expect transceiver2.mid to be rolled back to null');
      });
    })
  }, 'setLocalDescription(rollback) should only unset transceiver mids associated with current round');

  /*
    4.3.1.6.  Set the RTCSessionSessionDescription
      9.  If description is of type "rollback", then run the following steps:
        2.  If an RTCRtpTransceiver was created by applying the RTCSessionDescription
            that is being rolled back, and a track has not been attached to it via
            addTrack, remove that transceiver from connection's set of transceivers,
            as described by [JSEP] (section 4.1.8.2.).
   */
  promise_test(t => {
    const pc1 = new RTCPeerConnection();
    t.add_cleanup(() => pc1.close());
    const pc2 = new RTCPeerConnection();

    t.add_cleanup(() => pc2.close());

    pc1.addTransceiver('audio');

    return pc1.createOffer()
    .then(offer => pc2.setRemoteDescription(offer))
    .then(() => {
      const transceivers = pc2.getTransceivers();
      assert_equals(transceivers.length, 1);
      const [ transceiver ] = transceivers;

      assert_equals(typeof transceiver.mid, 'string',
        'Expect transceiver.mid to be set');

      return pc2.setRemoteDescription({ type: 'rollback' })
      .then(() => {
        assert_equals(transceiver.mid, null,
          'Expect transceiver.mid to be unset');

        assert_array_equals(pc2.getTransceivers(), [],
          `Expect transceiver to be removed from pc2's transceiver list`);
      });
    });
  }, 'setRemoteDescription(rollback) should remove newly created transceiver from transceiver list');

  promise_test(async t => {
    const pc1 = new RTCPeerConnection();
    t.add_cleanup(() => pc1.close());
    const pc2 = new RTCPeerConnection();
    t.add_cleanup(() => pc2.close());

    pc1.addTransceiver('audio');
    const offer = await pc1.createOffer();
    await pc1.setLocalDescription(offer);

    assert_false(pc1.getTransceivers()[0].stopped, 'Transceiver is not stopped');

    await pc2.setRemoteDescription(offer);
    pc2.getTransceivers()[0].stop();
    const answer = await pc2.createAnswer();

    await pc1.setRemoteDescription(answer);

    assert_true(pc1.getTransceivers()[0].stopped, 'Transceiver is stopped');
    assert_equals(pc1.getReceivers().length, 0, 'getReceivers does not expose a receiver of a stopped transceiver');
    assert_equals(pc1.getSenders().length, 0, 'getSenders does not expose a sender of a stopped transceiver');
  }, 'setRemoteDescription should stop the transceiver if its corresponding m section is rejected');

  /*
    TODO
      - Steps for transceiver direction is added to tip of tree draft, but not yet
        published as editor's draft

    4.3.1.6.  Set the RTCSessionSessionDescription
      8.  If description is set as a remote description, then run the following steps
          for each media description in description:
        1.  As described by [JSEP] (section 5.9.), attempt to find an existing
            RTCRtpTransceiver object, transceiver, to represent the media description.
        3.  If the media description has no MID, and transceiver's mid is unset, generate
            a random value as described in [JSEP] (section 5.9.).
        4.  If the direction of the media description is sendrecv or sendonly, and
            transceiver.receiver.track has not yet been fired in a track event, process
            the remote track for the media description, given transceiver.
        5.  If the media description is rejected, and transceiver is not already stopped,
            stop the RTCRtpTransceiver transceiver.

    [JSEP]
    5.9.  Applying a Remote Description
      - If the m= section is not associated with any RtpTransceiver
        (possibly because it was dissociated in the previous step),
        either find an RtpTransceiver or create one according to the
        following steps:

        - If the m= section is sendrecv or recvonly, and there are
          RtpTransceivers of the same type that were added to the
          PeerConnection by addTrack and are not associated with any
          m= section and are not stopped, find the first (according to
          the canonical order described in Section 5.2.1) such
          RtpTransceiver.

        - If no RtpTransceiver was found in the previous step, create
          one with a recvonly direction.
   */
</script>