tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_peerConnection_basicAudioVerifyRtpHeaderExtensions.html (2174B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <script type="application/javascript" src="pc.js"></script>
      5  <script type="application/javascript" src="parser_rtp.js"></script>
      6  <script type="application/javascript" src="sdpUtils.js"></script>
      7 </head>
      8 <body>
      9 <pre id="test">
     10 <script type="application/javascript">
     11  createHTML({
     12    bug: "1416932",
     13    title: "Basic audio-only peer connection and verify rtp header extensions"
     14  });
     15 
     16  var test;
     17  runNetworkTest(function (options) {
     18    test = new PeerConnectionTest(options);
     19    test.setMediaConstraints([{audio: true}], [{audio: true}]);
     20    // pc.js uses video elements by default, we want to test audio elements here
     21    test.pcLocal.audioElementsOnly = true;
     22 
     23    let getRtpPacket = (pc) => {
     24      // we only examine received packets
     25      let sending = false;
     26      pc.mozEnablePacketDump(0, "rtp", sending);
     27      return new Promise((res, rej) =>
     28        pc.mozSetPacketCallback((...args) => {
     29          res([...args]);
     30          pc.mozSetPacketCallback(() => {});
     31          pc.mozDisablePacketDump(0, "rtp", sending);
     32        })
     33      );
     34    }
     35 
     36    const pc = SpecialPowers.wrap(test.pcRemote._pc);
     37    const haveFirstPacket = getRtpPacket(pc);
     38 
     39    test.chain.insertBefore('PC_REMOTE_WAIT_FOR_MEDIA_FLOW', [
     40      async function PC_REMOTE_CHECK_RTP_HEADER_EXTS_AGAINST_SDP() {
     41 
     42        const sdpExtmapIds = sdputils.findExtmapIds(test.originalAnswer.sdp);
     43 
     44        const [level, type, sending, data] = await haveFirstPacket;
     45        const extensions = ParseRtpPacket(data).header.extensions;
     46 
     47        // make sure we got the same number of rtp header extensions in
     48        // the received packet as were negotiated in the sdp.  Then
     49        // check to make sure each of the received extension ids were in
     50        // the sdp.
     51        is(sdpExtmapIds.length, extensions.length, "number of received ids match sdp ids");
     52        // note, we are comparing a number (from the parsed rtp packet)
     53        // and a string (from the answer sdp)
     54        ok(extensions.every((ext) => sdpExtmapIds.includes(""+ext.id)), "extension id arrays equivalent");
     55      }
     56    ]);
     57 
     58    return test.run();
     59  });
     60 </script>
     61 </pre>
     62 </body>
     63 </html>