tor-browser

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

simplecall-no-ssrcs.https.html (4064B)


      1 <!doctype html>
      2 <html>
      3 <head>
      4  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      5  <title>RTCPeerConnection Connection Test</title>
      6  <script src="RTCPeerConnection-helper.js"></script>
      7 </head>
      8 <body>
      9  <div id="log"></div>
     10  <div>
     11    <video id="local-view" muted autoplay="autoplay"></video>
     12    <video id="remote-view" muted autoplay="autoplay"></video>
     13  </div>
     14 
     15  <!-- These files are in place when executing on W3C. -->
     16  <script src="/resources/testharness.js"></script>
     17  <script src="/resources/testharnessreport.js"></script>
     18  <script type="text/javascript">
     19  var test = async_test('Can set up a basic WebRTC call without announcing ssrcs.');
     20 
     21  var gFirstConnection = null;
     22  var gSecondConnection = null;
     23 
     24  // if the remote video gets video data that implies the negotiation
     25  // as well as the ICE and DTLS connection are up.
     26  document.getElementById('remote-view')
     27      .addEventListener('loadedmetadata', function() {
     28    // Call negotiated: done.
     29    test.done();
     30  });
     31 
     32  function getNoiseStreamOkCallback(localStream) {
     33    gFirstConnection = new RTCPeerConnection(null);
     34    test.add_cleanup(() => gFirstConnection.close());
     35    gFirstConnection.onicecandidate = onIceCandidateToFirst;
     36    localStream.getTracks().forEach(function(track) {
     37      gFirstConnection.addTrack(track, localStream);
     38    });
     39    gFirstConnection.createOffer().then(onOfferCreated, failed('createOffer'));
     40 
     41    var videoTag = document.getElementById('local-view');
     42    videoTag.srcObject = localStream;
     43  };
     44 
     45  var onOfferCreated = test.step_func(function(offer) {
     46    gFirstConnection.setLocalDescription(offer);
     47 
     48    // remove all a=ssrc: lines and the (obsolete) msid-semantic line.
     49    var sdp = offer.sdp.replace(/^a=ssrc:.*$\r\n/gm, '')
     50      .replace(/^a=msid-semantic.*$\r\n/gm, '');
     51 
     52    // This would normally go across the application's signaling solution.
     53    // In our case, the "signaling" is to call this function.
     54    receiveCall(sdp);
     55  });
     56 
     57  function receiveCall(offerSdp) {
     58    gSecondConnection = new RTCPeerConnection(null);
     59    test.add_cleanup(() => gSecondConnection.close());
     60    gSecondConnection.onicecandidate = onIceCandidateToSecond;
     61    gSecondConnection.ontrack = onRemoteTrack;
     62 
     63    var parsedOffer = new RTCSessionDescription({ type: 'offer',
     64                                                  sdp: offerSdp });
     65    gSecondConnection.setRemoteDescription(parsedOffer);
     66 
     67    gSecondConnection.createAnswer().then(onAnswerCreated,
     68                                   failed('createAnswer'));
     69  };
     70 
     71  var onAnswerCreated = test.step_func(function(answer) {
     72    gSecondConnection.setLocalDescription(answer);
     73 
     74    // remove all a=ssrc: lines, the msid-semantic line and any a=msid:.
     75    var sdp = answer.sdp.replace(/^a=ssrc:.*$\r\n/gm, '')
     76      .replace(/^a=msid-semantic.*$\r\n/gm, '')
     77      .replace(/^a=msid:.*$\r\n/gm, '');
     78 
     79    // Similarly, this would go over the application's signaling solution.
     80    handleAnswer(sdp);
     81  });
     82 
     83  function handleAnswer(answerSdp) {
     84    var parsedAnswer = new RTCSessionDescription({ type: 'answer',
     85                                                   sdp: answerSdp });
     86    gFirstConnection.setRemoteDescription(parsedAnswer);
     87  };
     88 
     89  var onIceCandidateToFirst = test.step_func(function(event) {
     90    gSecondConnection.addIceCandidate(event.candidate);
     91  });
     92 
     93  var onIceCandidateToSecond = test.step_func(function(event) {
     94    gFirstConnection.addIceCandidate(event.candidate);
     95  });
     96 
     97  var onRemoteTrack = test.step_func(function(event) {
     98    var videoTag = document.getElementById('remote-view');
     99    if (!videoTag.srcObject) {
    100      videoTag.srcObject = event.streams[0];
    101    }
    102  });
    103 
    104  // Returns a suitable error callback.
    105  function failed(function_name) {
    106    return test.unreached_func('WebRTC called error callback for ' + function_name);
    107  }
    108 
    109  // This function starts the test.
    110  test.step(function() {
    111    getNoiseStream({ video: true, audio: true })
    112      .then(test.step_func(getNoiseStreamOkCallback), failed('getNoiseStream'));
    113  });
    114 </script>
    115 
    116 </body>
    117 </html>