tor-browser

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

simplecall.https.html (3653B)


      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.');
     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    // This would normally go across the application's signaling solution.
     49    // In our case, the "signaling" is to call this function.
     50    receiveCall(offer.sdp);
     51  });
     52 
     53  function receiveCall(offerSdp) {
     54    gSecondConnection = new RTCPeerConnection(null);
     55    test.add_cleanup(() => gSecondConnection.close());
     56    gSecondConnection.onicecandidate = onIceCandidateToSecond;
     57    gSecondConnection.ontrack = onRemoteTrack;
     58 
     59    var parsedOffer = new RTCSessionDescription({ type: 'offer',
     60                                                  sdp: offerSdp });
     61    gSecondConnection.setRemoteDescription(parsedOffer);
     62 
     63    gSecondConnection.createAnswer().then(onAnswerCreated,
     64                                   failed('createAnswer'));
     65  };
     66 
     67  var onAnswerCreated = test.step_func(function(answer) {
     68    gSecondConnection.setLocalDescription(answer);
     69 
     70    // Similarly, this would go over the application's signaling solution.
     71    handleAnswer(answer.sdp);
     72  });
     73 
     74  function handleAnswer(answerSdp) {
     75    var parsedAnswer = new RTCSessionDescription({ type: 'answer',
     76                                                   sdp: answerSdp });
     77    gFirstConnection.setRemoteDescription(parsedAnswer);
     78  };
     79 
     80  var onIceCandidateToFirst = test.step_func(function(event) {
     81    gSecondConnection.addIceCandidate(event.candidate);
     82  });
     83 
     84  var onIceCandidateToSecond = test.step_func(function(event) {
     85    gFirstConnection.addIceCandidate(event.candidate);
     86  });
     87 
     88  var onRemoteTrack = test.step_func(function(event) {
     89    var videoTag = document.getElementById('remote-view');
     90    if (!videoTag.srcObject) {
     91      videoTag.srcObject = event.streams[0];
     92    }
     93  });
     94 
     95  // Returns a suitable error callback.
     96  function failed(function_name) {
     97    return test.unreached_func('WebRTC called error callback for ' + function_name);
     98  }
     99 
    100  // This function starts the test.
    101  test.step(function() {
    102    getNoiseStream({ video: true, audio: true })
    103      .then(test.step_func(getNoiseStreamOkCallback), failed('getNoiseStream'));
    104  });
    105 </script>
    106 
    107 </body>
    108 </html>