How to use MediaKeySystemAccessProxy method in wpt

Best JavaScript code snippet using wpt

clearkey-polyfill.js

Source:clearkey-polyfill.js Github

copy

Full Screen

...38 for(var i = 0, l = stack.length; i < l; i++) {39 stack[i].call(this, event);40 }41 };42 function MediaKeySystemAccessProxy( keysystem, access, configuration )43 {44 this._keysystem = keysystem;45 this._access = access;46 this._configuration = configuration;47 }48 Object.defineProperties( MediaKeySystemAccessProxy.prototype, {49 keysystem: { get: function() { return this._keysystem; } }50 });51 MediaKeySystemAccessProxy.prototype.getConfiguration = function getConfiguration()52 {53 return this._configuration;54 };55 MediaKeySystemAccessProxy.prototype.createMediaKeys = function createMediaKeys()56 {57 return new Promise( function( resolve, reject ) {58 this._access.createMediaKeys()59 .then( function( mediaKeys ) { resolve( new MediaKeysProxy( mediaKeys ) ); })60 .catch( function( error ) { reject( error ); } );61 }.bind( this ) );62 };63 function MediaKeysProxy( mediaKeys )64 {65 this._mediaKeys = mediaKeys;66 this._sessions = [ ];67 this._videoelement = undefined;68 this._onTimeUpdateListener = MediaKeysProxy.prototype._onTimeUpdate.bind( this );69 }70 MediaKeysProxy.prototype._setVideoElement = function _setVideoElement( videoElement )71 {72 if ( videoElement !== this._videoelement )73 {74 if ( this._videoelement )75 {76 this._videoelement.removeEventListener( 'timeupdate', this._onTimeUpdateListener );77 }78 this._videoelement = videoElement;79 if ( this._videoelement )80 {81 this._videoelement.addEventListener( 'timeupdate', this._onTimeUpdateListener );82 }83 }84 };85 MediaKeysProxy.prototype._onTimeUpdate = function( event )86 {87 this._sessions.forEach( function( session ) {88 if ( session._sessionType === 'persistent-usage-record' )89 {90 session._onTimeUpdate( event );91 }92 } );93 };94 MediaKeysProxy.prototype._removeSession = function _removeSession( session )95 {96 var index = this._sessions.indexOf( session );97 if ( index !== -1 ) this._sessions.splice( index, 1 );98 };99 MediaKeysProxy.prototype.createSession = function createSession( sessionType )100 {101 if ( !sessionType || sessionType === 'temporary' ) return this._mediaKeys.createSession();102 var session = new MediaKeySessionProxy( this, sessionType );103 this._sessions.push( session );104 return session;105 };106 MediaKeysProxy.prototype.setServerCertificate = function setServerCertificate( certificate )107 {108 return this._mediaKeys.setServerCertificate( certificate );109 };110 function MediaKeySessionProxy( mediaKeysProxy, sessionType )111 {112 EventTarget.call( this );113 this._mediaKeysProxy = mediaKeysProxy114 this._sessionType = sessionType;115 this._sessionId = "";116 // MediaKeySessionProxy states117 // 'created' - After initial creation118 // 'loading' - Persistent license session waiting for key message to load stored keys119 // 'active' - Normal active state - proxy all key messages120 // 'removing' - Release message generated, waiting for ack121 // 'closed' - Session closed122 this._state = 'created';123 this._closed = new Promise( function( resolve ) { this._resolveClosed = resolve; }.bind( this ) );124 }125 MediaKeySessionProxy.prototype = Object.create( EventTarget.prototype );126 Object.defineProperties( MediaKeySessionProxy.prototype, {127 sessionId: { get: function() { return this._sessionId; } },128 expiration: { get: function() { return NaN; } },129 closed: { get: function() { return this._closed; } },130 keyStatuses:{ get: function() { return this._session.keyStatuses; } }, // TODO this will fail if examined too early131 _kids: { get: function() { return this._keys.map( function( key ) { return key.kid; } ); } },132 });133 MediaKeySessionProxy.prototype._createSession = function _createSession()134 {135 this._session = this._mediaKeysProxy._mediaKeys.createSession();136 this._session.addEventListener( 'message', MediaKeySessionProxy.prototype._onMessage.bind( this ) );137 this._session.addEventListener( 'keystatuseschange', MediaKeySessionProxy.prototype._onKeyStatusesChange.bind( this ) );138 };139 MediaKeySessionProxy.prototype._onMessage = function _onMessage( event )140 {141 switch( this._state )142 {143 case 'loading':144 this._session.update( toUtf8( { keys: this._keys } ) )145 .then( function() {146 this._state = 'active';147 this._loaded( true );148 }.bind(this)).catch( this._loadfailed );149 break;150 case 'active':151 this.dispatchEvent( event );152 break;153 default:154 // Swallow the event155 break;156 }157 };158 MediaKeySessionProxy.prototype._onKeyStatusesChange = function _onKeyStatusesChange( event )159 {160 switch( this._state )161 {162 case 'active' :163 case 'removing' :164 this.dispatchEvent( event );165 break;166 default:167 // Swallow the event168 break;169 }170 };171 MediaKeySessionProxy.prototype._onTimeUpdate = function _onTimeUpdate( event )172 {173 if ( !this._firstTime ) this._firstTime = Date.now();174 this._latestTime = Date.now();175 this._store();176 };177 MediaKeySessionProxy.prototype._queueMessage = function _queueMessage( messageType, message )178 {179 setTimeout( function() {180 var messageAsArray = toUtf8( message ).buffer;181 this.dispatchEvent( new MediaKeyMessageEvent( 'message', { messageType: messageType, message: messageAsArray } ) );182 }.bind( this ) );183 };184 function _storageKey( sessionId )185 {186 return sessionId;187 }188 MediaKeySessionProxy.prototype._store = function _store()189 {190 var data;191 if ( this._sessionType === 'persistent-usage-record' )192 {193 data = { kids: this._kids };194 if ( this._firstTime ) data.firstTime = this._firstTime;195 if ( this._latestTime ) data.latestTime = this._latestTime;196 }197 else198 {199 data = { keys: this._keys };200 }201 window.localStorage.setItem( _storageKey( this._sessionId ), JSON.stringify( data ) );202 };203 MediaKeySessionProxy.prototype._load = function _load( sessionId )204 {205 var store = window.localStorage.getItem( _storageKey( sessionId ) );206 if ( store === null ) return false;207 var data;208 try { data = JSON.parse( store ) } catch( error ) {209 return false;210 }211 if ( data.kids )212 {213 this._sessionType = 'persistent-usage-record';214 this._keys = data.kids.map( function( kid ) { return { kid: kid }; } );215 if ( data.firstTime ) this._firstTime = data.firstTime;216 if ( data.latestTime ) this._latestTime = data.latestTime;217 }218 else219 {220 this._sessionType = 'persistent-license';221 this._keys = data.keys;222 }223 return true;224 };225 MediaKeySessionProxy.prototype._clear = function _clear()226 {227 window.localStorage.removeItem( _storageKey( this._sessionId ) );228 };229 MediaKeySessionProxy.prototype.generateRequest = function generateRequest( initDataType, initData )230 {231 if ( this._state !== 'created' ) return Promise.reject( new InvalidStateError() );232 this._createSession();233 this._state = 'active';234 return this._session.generateRequest( initDataType, initData )235 .then( function() {236 this._sessionId = Math.random().toString(36).slice(2);237 }.bind( this ) );238 };239 MediaKeySessionProxy.prototype.load = function load( sessionId )240 {241 if ( this._state !== 'created' ) return Promise.reject( new InvalidStateError() );242 return new Promise( function( resolve, reject ) {243 try244 {245 if ( !this._load( sessionId ) )246 {247 resolve( false );248 return;249 }250 this._sessionId = sessionId;251 if ( this._sessionType === 'persistent-usage-record' )252 {253 var msg = { kids: this._kids };254 if ( this._firstTime ) msg.firstTime = this._firstTime;255 if ( this._latestTime ) msg.latestTime = this._latestTime;256 this._queueMessage( 'license-release', msg );257 this._state = 'removing';258 resolve( true );259 }260 else261 {262 this._createSession();263 this._state = 'loading';264 this._loaded = resolve;265 this._loadfailed = reject;266 var initData = { kids: this._kids };267 this._session.generateRequest( 'keyids', toUtf8( initData ) );268 }269 }270 catch( error )271 {272 reject( error );273 }274 }.bind( this ) );275 };276 MediaKeySessionProxy.prototype.update = function update( response )277 {278 return new Promise( function( resolve, reject ) {279 switch( this._state ) {280 case 'active' :281 var message = fromUtf8( response );282 // JSON Web Key Set283 this._keys = message.keys;284 this._store();285 resolve( this._session.update( response ) );286 break;287 case 'removing' :288 this._state = 'closed';289 this._clear();290 this._mediaKeysProxy._removeSession( this );291 this._resolveClosed();292 delete this._session;293 resolve();294 break;295 default:296 reject( new InvalidStateError() );297 }298 }.bind( this ) );299 };300 MediaKeySessionProxy.prototype.close = function close()301 {302 if ( this._state === 'closed' ) return Promise.resolve();303 this._state = 'closed';304 this._mediaKeysProxy._removeSession( this );305 this._resolveClosed();306 var session = this._session;307 if ( !session ) return Promise.resolve();308 this._session = undefined;309 return session.close();310 };311 MediaKeySessionProxy.prototype.remove = function remove()312 {313 if ( this._state !== 'active' || !this._session ) return Promise.reject( new DOMException('InvalidStateError('+this._state+')') );314 this._state = 'removing';315 this._mediaKeysProxy._removeSession( this );316 return this._session.close()317 .then( function() {318 var msg = { kids: this._kids };319 if ( this._sessionType === 'persistent-usage-record' )320 {321 if ( this._firstTime ) msg.firstTime = this._firstTime;322 if ( this._latestTime ) msg.latestTime = this._latestTime;323 }324 this._queueMessage( 'license-release', msg );325 }.bind( this ) )326 };327 HTMLMediaElement.prototype.setMediaKeys = function setMediaKeys( mediaKeys )328 {329 if ( mediaKeys instanceof MediaKeysProxy )330 {331 mediaKeys._setVideoElement( this );332 return _setMediaKeys.call( this, mediaKeys._mediaKeys );333 }334 else335 {336 return _setMediaKeys.call( this, mediaKeys );337 }338 };339 navigator.requestMediaKeySystemAccess = function( keysystem, configurations )340 {341 // First, see if this is supported by the platform342 return new Promise( function( resolve, reject ) {343 _requestMediaKeySystemAccess( keysystem, configurations )344 .then( function( access ) { resolve( access ); } )345 .catch( function( error ) {346 if ( error instanceof TypeError ) reject( error );347 if ( keysystem !== 'org.w3.clearkey' ) reject( error );348 if ( !configurations.some( is_persistent_configuration ) ) reject( error );349 // Shallow copy the configurations, swapping out the labels and omitting the sessiontypes350 var configurations_copy = configurations.map( function( config, index ) {351 var config_copy = copy_configuration( config );352 config_copy.label = index.toString();353 return config_copy;354 } );355 // And try again with these configurations356 _requestMediaKeySystemAccess( keysystem, configurations_copy )357 .then( function( access ) {358 // Create the supported configuration based on the original request359 var configuration = access.getConfiguration(),360 original_configuration = configurations[ configuration.label ];361 // If the original configuration did not need persistent session types, then we're done362 if ( !is_persistent_configuration( original_configuration ) ) resolve( access );363 // Create the configuration that we will return364 var returned_configuration = copy_configuration( configuration );365 if ( original_configuration.label )366 returned_configuration.label = original_configuration;367 else368 delete returned_configuration.label;369 returned_configuration.sessionTypes = original_configuration.sessionTypes;370 resolve( new MediaKeySystemAccessProxy( keysystem, access, returned_configuration ) );371 } )372 .catch( function( error ) { reject( error ); } );373 } );374 } );375 };376 function is_persistent_configuration( configuration )377 {378 return configuration.sessionTypes &&379 ( configuration.sessionTypes.indexOf( 'persistent-usage-record' ) !== -1380 || configuration.sessionTypes.indexOf( 'persistent-license' ) !== -1 );381 }382 function copy_configuration( src )383 {384 var dst = {};...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var video = document.createElement('video');2var config = {3 audioCapabilities: [{4 contentType: 'audio/mp4; codecs="mp4a.40.2"',5 }],6 videoCapabilities: [{7 contentType: 'video/mp4; codecs="avc1.4d400d"',8 }],9};10navigator.requestMediaKeySystemAccess('org.w3.clearkey', [config]).then(function(access) {11 return access.createMediaKeys();12}).then(function(keys) {13 return video.setMediaKeys(keys);14}).then(function() {15 return video.mediaKeys.createSession('temporary');16}).then(function(session) {17 return session.generateRequest('cenc', new Uint8Array([0]));18}).then(function() {19 test.done();20});21import os22import subprocess23import sys24def run_command(command):25 print("Running command: %s" % command)26 process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)27 stdout, stderr = process.communicate()28 print(stdout)29 print(stderr)30def main():31 #run_command("sudo apt-get update")32 #run_command("sudo apt-get install -y python-pip python-dev build-essential")33 #run_command("sudo pip install --upgrade pip")34 #run_command("sudo pip install --upgrade virtualenv")35 #run_command("sudo pip install --upgrade virtualenvwrapper")36 #run_command("sudo pip install --upgrade setuptools")37 #run_command("sudo pip install --upgrade requests")38 #run_command("sudo pip install --upgrade pyvirtualdisplay")39 #run_command("sudo pip install --upgrade selenium")40 #run_command("sudo pip install --upgrade pyvirtualdisplay")41 #run_command("sudo pip install --upgrade xvfbwrapper")42 #run_command("sudo pip install --upgrade nose")43 #run_command("sudo pip install --upgrade nose2")44 #run_command("sudo pip install --upgrade nose2[coverage_plugin]")45 #run_command("sudo pip install --upgrade nose2[unittest_plugin]")46 #run_command("sudo pip install --upgrade nose2[xml_reporter]")47 #run_command("sudo pip install --upgrade nose2[html_reporter]")48 #run_command("sudo pip install --upgrade nose2[profile_plugin]")49 #run_command("sudo pip

Full Screen

Using AI Code Generation

copy

Full Screen

1import { MediaKeySystemAccessProxy } from 'wpt-runner';2import { MediaKeySystemAccessProxy } from 'wpt-runner';3import { MediaKeySystemAccessProxy } from 'wpt-runner';4import { MediaKeySystemAccessProxy } from 'wpt-runner';5import { MediaKeySystemAccessProxy } from 'wpt-runner';6import { MediaKeySystemAccessProxy } from 'wpt-runner';7import { MediaKeySystemAccessProxy } from 'wpt-runner';8import { MediaKeySystemAccessProxy } from 'wpt-runner';9import { MediaKeySystemAccessProxy } from 'wpt-runner';10import { MediaKeySystemAccessProxy } from 'wpt-runner';11import { MediaKeySystemAccessProxy } from 'wpt-runner';12import { MediaKeySystemAccessProxy } from 'wpt-runner';13import { MediaKeySystemAccessProxy } from 'wpt-runner';14import { MediaKeySystemAccessProxy } from 'wpt-runner';15import { MediaKeySystemAccessProxy } from 'wpt-runner';

Full Screen

Using AI Code Generation

copy

Full Screen

1const wptRunner = require('wpt-runner');2const { MediaKeySystemAccessProxy } = wptRunner;3const wptRunner = require('wpt-runner');4const { MediaKeySystemAccessProxy } = wptRunner;5const wptRunner = require('wpt-runner');6const { MediaKeySystemAccessProxy } = wptRunner;7const wptRunner = require('wpt-runner');8const { MediaKeySystemAccessProxy } = wptRunner;9const wptRunner = require('wpt-runner');10const { MediaKeySystemAccessProxy } = wptRunner;11const wptRunner = require('wpt-runner');12const { MediaKeySystemAccessProxy } = wptRunner;13const wptRunner = require('wpt-runner');14const { MediaKeySystemAccessProxy } = wptRunner;15const wptRunner = require('wpt-runner');16const { MediaKeySystemAccessProxy } = wptRunner;17const wptRunner = require('wpt-runner');18const { MediaKeySystemAccessProxy } = wptRunner;19const wptRunner = require('wpt-runner');20const { MediaKeySystemAccessProxy } = wptRunner;21const wptRunner = require('wpt-runner');22const { MediaKeySystemAccessProxy } = wptRunner;23const wptRunner = require('wpt-runner');24const { MediaKeySystemAccessProxy } = wptRunner;25const wptRunner = require('wpt-runner');26const { MediaKeySystemAccessProxy } = wptRunner;

Full Screen

Using AI Code Generation

copy

Full Screen

1function runTest(config,qualifier) {2 var testname = testnamePrefix(qualifier, config.keysystem)3 + /video\/([^;]*)/.exec( config.videoType )[ 1 ]4 + config.initDataType;5 var configuration = { initDataTypes: [ config.initDataType ],6 audioCapabilities: [ { contentType: config.audioType } ],7 videoCapabilities: [ { contentType: config.videoType } ],8 sessionTypes: [ 'temporary' ] };9 async_test( function( test ) {10 _mediaSource;11 function onFailure(error) {12 forceTestFailureFromPromise(test, error);13 }14 function onMessage(event) {15 assert_equals(event.target, _mediaKeySession);16 assert_equals(event.messageType, 'license-request');17 var xhr = new XMLHttpRequest();18 xhr.open('POST', config.messagehandler);19 xhr.responseType = 'arraybuffer';20 xhr.onload = function(event) {21 assert_equals(xhr.status, 200);22 assert_equals(xhr.response.byteLength, 0);23 _mediaKeySession.update(new Uint8Array()).then(function() {24 test.done();25 }).catch(onFailure);26 };27 xhr.send(new Uint8Array(event.message));28 }29 function onMessageError(event) {30 forceTestFailureFromPromise(test, 'Unexpected messageerror event');31 }32 function onSessionClosed(event) {33 assert_equals(event.target, _mediaKeySession);34 assert_equals(event.type, 'keystatuseschange');35 test.done();36 }37 function onSessionError(event) {38 forceTestFailureFromPromise(test, 'Unexpected keyerror event');39 }40 function onSessionMessage(event) {41 assert_unreached('Unexpected message event');42 }43 function onSessionReady(event) {

Full Screen

Using AI Code Generation

copy

Full Screen

1importScripts('/resources/testharness.js');2importScripts('/resources/testharnessreport.js');3importScripts('/encrypted-media/util/utils.js');4importScripts('/encrypted-media/util/fetch.js');5importScripts('/encrypted-media/util/testmediasource.js');6importScripts('/encrypted-media/util/testmediasourcehandler.js');7importScripts('/encrypted-media/util/testmediasourcehelper.js');8importScripts('/encrypted-media/util/testmediasourcehandler.js');9importScripts('/encrypted-media/util/utf8.js');10importScripts('/encrypted-media/util/utf16.js');11importScripts('/encrypted-media/util/utf8decoder.js');12importScripts('/encrypted-media/util/utf8encoder.js');13importScripts('/encrypted-media/util/utf16decoder.js');14importScripts('/encrypted-media/util/utf16encoder.js');15importScripts('/encrypted-media/util/utf8decoder.js');16importScripts('/encrypted-media/util/utf8encoder.js');17importScripts('/encrypted-media/util/utf16decoder.js');18importScripts('/encrypted-media/util/utf16encoder.js');19importScripts('/encrypted-media/util/utf8decoder.js');20importScripts('/encrypted-media/util/utf8encoder.js');21importScripts('/encrypted-media/util/utf16decoder.js');22importScripts('/encrypted-media/util/utf16encoder.js');23importScripts('/encrypted-media/util/utf8decoder.js');24importScripts('/encrypted-media/util/utf8encoder.js');25importScripts('/encrypted-media/util/utf16decoder.js');26importScripts('/encrypted-media/util/utf16encoder.js');27importScripts('/encrypted-media/util/utf8decoder.js');28importScripts('/encrypted-media/util/utf8encoder.js');29importScripts('/encrypted-media/util/utf16decoder.js');30importScripts('/encrypted-media/util/utf16encoder.js');31importScripts('/encrypted-media/util/utf8decoder.js');32importScripts('/encrypted-media/util/utf8encoder.js');33importScripts('/encrypted-media/util/utf16decoder.js');34importScripts('/encrypted-media/util/utf16encoder.js');35importScripts('/encrypted-media/util/utf8decoder.js');36importScripts('/encrypted-media/util/utf8encoder.js');37importScripts('/encrypted-media/util/utf16decoder.js');38importScripts('/encrypted-media/util/utf16encoder.js');39importScripts('/encrypted-media/util/utf8decoder.js');40importScripts('/encrypted-media/util/utf8encoder.js');

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful