tor-browser

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

drm-retrieve-persistent-license.html (2852B)


      1 <!doctype html>
      2 <html>
      3  <head>
      4    <meta charset=utf-8>
      5    <title>Encrypted Media Extensions: persistent-license, retrieve and playback, DRM</title>
      6    <link rel="help" href="https://w3c.github.io/encrypted-media/">
      7 
      8    <!-- Helper scripts for Encrypted Media Extensions tests  -->
      9    <script src=/encrypted-media/util/utils.js></script>
     10    <script src=/encrypted-media/util/utf8.js></script>
     11    <script src=/encrypted-media/util/testmediasource.js></script>
     12  </head>
     13  <body>
     14    <div id='log'></div>
     15 
     16    <div id='video'>
     17      <video id="videoelement" width="200px"></video>
     18    </div>
     19 
     20    <script>
     21    // Wait for a message from the main window with details of our task
     22    window.addEventListener( 'message', function( event ) {
     23 
     24        var config = event.data.config,
     25            configuration = {   initDataTypes: [ config.initDataType ],
     26                                audioCapabilities: [ { contentType: config.audioType } ],
     27                                videoCapabilities: [ { contentType: config.videoType } ],
     28                                sessionTypes: [ 'persistent-license' ] },
     29            assertions = [ ];
     30 
     31        var _mediaKeySession;
     32        config.video = document.getElementById('videoelement');
     33 
     34        function onComplete() {
     35            window.opener.postMessage({ testResult: assertions }, '*');
     36        }
     37 
     38        function onFailure(error) {
     39            assertions.push( { actual: false, expected: true, message: error.toString() } );
     40            onComplete();
     41        }
     42 
     43        function onTimeupdate(event) {
     44            if ( config.video.currentTime > ( config.duration || 1 ) ) {
     45                config.video.removeEventListener('timeupdate', onTimeupdate);
     46                config.video.pause();
     47 
     48                _mediaKeySession.closed
     49                    .then(onComplete)
     50                    .catch(onFailure);
     51                _mediaKeySession.close()
     52                    .catch(onFailure);
     53            }
     54        }
     55 
     56        navigator.requestMediaKeySystemAccess(config.keysystem, [ configuration ] )
     57        .then(function(access) {
     58            return access.createMediaKeys();
     59        }).then(function(mediaKeys) {
     60            return config.video.setMediaKeys(mediaKeys);
     61        }).then(function() {
     62            config.video.addEventListener('timeupdate', onTimeupdate);
     63            _mediaKeySession = config.video.mediaKeys.createSession( 'persistent-license' );
     64            return _mediaKeySession.load(event.data.sessionId);
     65        }).then(function( success ) {
     66            if ( !success ) throw new DOMException( 'Could not load session' );
     67            return testmediasource(config);
     68        }).then(function(source) {
     69            config.video.src = URL.createObjectURL(source);
     70            config.video.play();
     71        })
     72        .catch(onFailure);
     73    } );
     74 
     75    </script>
     76  </body>
     77 </html>