How to use MediaKeySystemAccess method in wpt

Best JavaScript code snippet using wpt

index.js

Source:index.js Github

copy

Full Screen

...164 await EmeEncryptionSchemePolyfill.originalRMKSA_.call(165 this, keySystem, filteredSupportedConfigurations);166 // Wrap the MKSA object in ours to provide the missing field in the167 // returned configuration.168 return new EmeEncryptionSchemePolyfillMediaKeySystemAccess(169 mediaKeySystemAccess, supportedScheme);170 }171 /**172 * Filters out capabilities that don't match the supported encryption scheme.173 *174 * @param {!Array.<!MediaKeySystemMediaCapability>|undefined} capabilities175 * An array of capabilities, or null or undefined.176 * @param {?string} supportedScheme The encryption scheme that we think is177 * supported by the key system.178 * @return {!Array.<!MediaKeySystemMediaCapability>|undefined} A filtered179 * array of capabilities based on |supportedScheme|. May be undefined if180 * the input was undefined.181 * @private182 */183 static filterCapabilities_(capabilities, supportedScheme) {184 if (!capabilities) {185 return capabilities;186 }187 return capabilities.filter((capability) => {188 // No specific scheme always works. In addition, accept the specific189 // scheme we guessed for this UA.190 return !capability['encryptionScheme'] ||191 capability['encryptionScheme'] == supportedScheme;192 });193 }194}195/**196 * A polyfill to add support for EncryptionScheme queries in MediaCapabilities.197 *198 * Because this polyfill can't know what schemes the UA or CDM actually support,199 * it assumes support for the historically-supported schemes of each well-known200 * key system.201 *202 * In source form, this is compatible with the Closure Compiler, CommonJS, and203 * AMD module formats. It can also be directly included via a script tag.204 *205 * The minified bundle is a standalone module compatible with the CommonJS and206 * AMD module formats, and can also be directly included via a script tag.207 *208 * @see https://wicg.github.io/encrypted-media-encryption-scheme/209 * @see https://github.com/w3c/encrypted-media/pull/457210 * @export211 */212class McEncryptionSchemePolyfill {213 /**214 * Installs the polyfill. To avoid the possibility of extra user prompts,215 * this will shim MC so long as it exists, without checking support for216 * encryptionScheme upfront. The support check will happen on-demand the217 * first time MC is used.218 *219 * @export220 */221 static install() {222 if (McEncryptionSchemePolyfill.originalDecodingInfo_) {223 console.debug('McEncryptionSchemePolyfill: Already installed.');224 return;225 }226 if (!navigator.mediaCapabilities) {227 console.debug('McEncryptionSchemePolyfill: MediaCapabilities not found');228 // No MediaCapabilities.229 return;230 }231 // Save the original.232 McEncryptionSchemePolyfill.originalDecodingInfo_ =233 navigator.mediaCapabilities.decodingInfo;234 // Patch in a method which will check for support on the first call.235 console.debug('McEncryptionSchemePolyfill: ' +236 'Waiting to detect encryptionScheme support.');237 navigator.mediaCapabilities.decodingInfo =238 McEncryptionSchemePolyfill.probeDecodingInfo_;239 }240 /**241 * A shim for mediaCapabilities.decodingInfo to check for encryptionScheme242 * support. Only used until we know if the browser has native support for the243 * encryptionScheme field.244 *245 * @this {MediaCapabilities}246 * @param {!MediaDecodingConfiguration} requestedConfiguration The requested247 * decoding configuration.248 * @return {!Promise.<!MediaCapabilitiesDecodingInfo>} A Promise to a result249 * describing the capabilities of the browser in the request configuration.250 * @private251 */252 static async probeDecodingInfo_(requestedConfiguration) {253 console.assert(this == navigator.mediaCapabilities,254 'bad "this" for decodingInfo');255 // Call the original version. If the call succeeds, we look at the result256 // to decide if the encryptionScheme field is supported or not.257 const capabilities =258 await McEncryptionSchemePolyfill.originalDecodingInfo_.call(259 this, requestedConfiguration);260 if (!requestedConfiguration.keySystemConfiguration) {261 // This was not a query regarding encrypted content. The results are262 // valid, but won't tell us anything about native support for263 // encryptionScheme. Just return the results.264 return capabilities;265 }266 const mediaKeySystemAccess = capabilities.keySystemAccess;267 if (mediaKeySystemAccess && hasEncryptionScheme(mediaKeySystemAccess)) {268 // The browser supports the encryptionScheme field!269 // No need for a patch. Revert back to the original implementation.270 console.debug('McEncryptionSchemePolyfill: ' +271 'Native encryptionScheme support found.');272 // eslint-disable-next-line require-atomic-updates273 navigator.mediaCapabilities.decodingInfo =274 McEncryptionSchemePolyfill.originalDecodingInfo_;275 // Return the results, which are completely valid.276 return capabilities;277 }278 // If we land here, either the browser does not support the279 // encryptionScheme field, or the browser does not support EME-related280 // fields in MCap _at all_.281 // First, install a patch to check the mediaKeySystemAccess or282 // encryptionScheme field in future calls.283 console.debug('McEncryptionSchemePolyfill: ' +284 'No native encryptionScheme support found. '+285 'Patching encryptionScheme support.');286 // eslint-disable-next-line require-atomic-updates287 navigator.mediaCapabilities.decodingInfo =288 McEncryptionSchemePolyfill.polyfillDecodingInfo_;289 // Second, if _none_ of the EME-related fields of MCap are supported, fill290 // them in now before returning the results.291 if (!mediaKeySystemAccess) {292 capabilities.keySystemAccess =293 await McEncryptionSchemePolyfill.getMediaKeySystemAccess_(294 requestedConfiguration);295 return capabilities;296 }297 // If we land here, it's only the encryption scheme field that is missing.298 // The results we have may not be valid, since they didn't account for299 // encryption scheme. Run the query again through our polyfill.300 return McEncryptionSchemePolyfill.polyfillDecodingInfo_.call(301 this, requestedConfiguration);302 }303 /**304 * A polyfill for mediaCapabilities.decodingInfo to handle the305 * encryptionScheme field in browsers that don't support it. It uses the306 * user-agent string to guess what encryption schemes are supported, then307 * those guesses are used to reject unsupported schemes.308 *309 * @this {MediaCapabilities}310 * @param {!MediaDecodingConfiguration} requestedConfiguration The requested311 * decoding configuration.312 * @return {!Promise.<!MediaCapabilitiesDecodingInfo>} A Promise to a result313 * describing the capabilities of the browser in the request configuration.314 * @private315 */316 static async polyfillDecodingInfo_(requestedConfiguration) {317 console.assert(this == navigator.mediaCapabilities,318 'bad "this" for decodingInfo');319 let supportedScheme = null;320 if (requestedConfiguration.keySystemConfiguration) {321 const keySystemConfig = requestedConfiguration.keySystemConfiguration;322 const keySystem = keySystemConfig.keySystem;323 const audioScheme = keySystemConfig.audio &&324 keySystemConfig.audio.encryptionScheme;325 const videoScheme = keySystemConfig.video &&326 keySystemConfig.video.encryptionScheme;327 supportedScheme = guessSupportedScheme(keySystem);328 const notSupportedResult = {329 powerEfficient: false,330 smooth: false,331 supported: false,332 keySystemAccess: null,333 configuration: requestedConfiguration,334 };335 if (audioScheme && audioScheme != supportedScheme) {336 return notSupportedResult;337 }338 if (videoScheme && videoScheme != supportedScheme) {339 return notSupportedResult;340 }341 }342 // At this point, either it's unencrypted or we assume the encryption scheme343 // is supported. So delegate to the original decodingInfo() method.344 const capabilities =345 await McEncryptionSchemePolyfill.originalDecodingInfo_.call(346 this, requestedConfiguration);347 if (capabilities.keySystemAccess) {348 // If the result is supported and encrypted, this will be a349 // MediaKeySystemAccess instance. Wrap the MKSA object in ours to provide350 // the missing field in the returned configuration.351 capabilities.keySystemAccess =352 new EmeEncryptionSchemePolyfillMediaKeySystemAccess(353 capabilities.keySystemAccess, supportedScheme);354 } else if (requestedConfiguration.keySystemConfiguration) {355 // If the result is supported and the content is encrypted, we should have356 // a MediaKeySystemAccess instance as part of the result. If we land357 // here, the browser doesn't support the EME-related fields of MCap.358 capabilities.keySystemAccess =359 await McEncryptionSchemePolyfill.getMediaKeySystemAccess_(360 requestedConfiguration);361 }362 return capabilities;363 }364 /**365 * Call navigator.requestMediaKeySystemAccess to get the MediaKeySystemAccess366 * information.367 *368 * @param {!MediaDecodingConfiguration} requestedConfiguration The requested369 * decoding configuration.370 * @return {!Promise.<!MediaKeySystemAccess>} A Promise to a371 * MediaKeySystemAccess instance.372 * @private373 */374 static async getMediaKeySystemAccess_(requestedConfiguration) {375 const mediaKeySystemConfig =376 McEncryptionSchemePolyfill.convertToMediaKeySystemConfig_(377 requestedConfiguration);378 const keySystemAccess =379 await navigator.requestMediaKeySystemAccess(380 requestedConfiguration.keySystemConfiguration.keySystem,381 [mediaKeySystemConfig]);382 return keySystemAccess;383 }384 /**385 * Convert the MediaDecodingConfiguration object to a386 * MediaKeySystemConfiguration object.387 *388 * @param {!MediaDecodingConfiguration} decodingConfig The decoding389 * configuration.390 * @return {!MediaKeySystemConfiguration} The converted MediaKeys391 * configuration.392 */393 static convertToMediaKeySystemConfig_(decodingConfig) {...

Full Screen

Full Screen

eme_interception.js

Source:eme_interception.js Github

copy

Full Screen

1/**2 * Hooks EME calls and forwards them for analysis and decryption.3 * 4 * Most of the code here was borrowed from https://github.com/google/eme_logger/blob/master/eme_listeners.js5 */67 var lastReceivedLicenseRequest = null;8 var lastReceivedLicenseResponse = null;910 /** Set up the EME listeners. */11function startEMEInterception() 12{13 var listener = new EmeInterception();14 listener.setUpListeners();15}1617 /**18 * Gets called whenever an EME method is getting called or an EME event fires19 */20EmeInterception.onOperation = function(operationType, args) 21{22 if (operationType == "GenerateRequestCall")23 {24 // got initData25 // console.log(args);26 }27 else if (operationType == "MessageEvent")28 {29 var licenseRequest = args.message;30 lastReceivedLicenseRequest = licenseRequest;31 }32 else if (operationType == "UpdateCall")33 {34 var licenseResponse = args[0];35 lastReceivedLicenseResponse = licenseResponse;3637 // OK, let's try to decrypt it, assuming the response correlates to the request38 WidevineCrypto.decryptContentKey(lastReceivedLicenseRequest, lastReceivedLicenseResponse);39 }40};414243/**44 * Manager for EME event and method listeners.45 * @constructor46 */47function EmeInterception() 48{49 this.unprefixedEmeEnabled = Navigator.prototype.requestMediaKeySystemAccess ? true : false;50 this.prefixedEmeEnabled = HTMLMediaElement.prototype.webkitGenerateKeyRequest ? true : false;51}525354/**55 * The number of types of HTML Media Elements to track.56 * @const {number}57 */58EmeInterception.NUM_MEDIA_ELEMENT_TYPES = 3;596061/**62 * Sets up EME listeners for whichever type of EME is enabled.63 */64EmeInterception.prototype.setUpListeners = function() 65{66 if (!this.unprefixedEmeEnabled && !this.prefixedEmeEnabled) {67 // EME is not enabled, just ignore68 return;69 }70 if (this.unprefixedEmeEnabled) {71 this.addListenersToNavigator_();72 }73 if (this.prefixedEmeEnabled) {74 // Prefixed EME is enabled75 }76 this.addListenersToAllEmeElements_();77};787980/**81 * Adds listeners to the EME methods on the Navigator object.82 * @private83 */84EmeInterception.prototype.addListenersToNavigator_ = function() 85{86 if (navigator.listenersAdded_) 87 return;8889 var originalRequestMediaKeySystemAccessFn = EmeInterception.extendEmeMethod(90 navigator,91 navigator.requestMediaKeySystemAccess,92 "RequestMediaKeySystemAccessCall");9394 navigator.requestMediaKeySystemAccess = function() 95 {96 var options = arguments[1];9798 // slice "It is recommended that a robustness level be specified" warning99 var modifiedArguments = arguments;100 var modifiedOptions = EmeInterception.addRobustnessLevelIfNeeded(options);101 modifiedArguments[1] = modifiedOptions;102103 var result = originalRequestMediaKeySystemAccessFn.apply(null, modifiedArguments);104 // Attach listeners to returned MediaKeySystemAccess object105 return result.then(function(mediaKeySystemAccess) 106 {107 this.addListenersToMediaKeySystemAccess_(mediaKeySystemAccess);108 return Promise.resolve(mediaKeySystemAccess);109 }.bind(this));110111 }.bind(this);112113 navigator.listenersAdded_ = true;114};115116117/**118 * Adds listeners to the EME methods on a MediaKeySystemAccess object.119 * @param {MediaKeySystemAccess} mediaKeySystemAccess A MediaKeySystemAccess120 * object to add listeners to.121 * @private122 */123EmeInterception.prototype.addListenersToMediaKeySystemAccess_ = function(mediaKeySystemAccess) 124{125 if (mediaKeySystemAccess.listenersAdded_) {126 return;127 }128 mediaKeySystemAccess.originalGetConfiguration = mediaKeySystemAccess.getConfiguration;129 mediaKeySystemAccess.getConfiguration = EmeInterception.extendEmeMethod(130 mediaKeySystemAccess,131 mediaKeySystemAccess.getConfiguration,132 "GetConfigurationCall");133134 var originalCreateMediaKeysFn = EmeInterception.extendEmeMethod(135 mediaKeySystemAccess,136 mediaKeySystemAccess.createMediaKeys,137 "CreateMediaKeysCall");138139 mediaKeySystemAccess.createMediaKeys = function() 140 {141 var result = originalCreateMediaKeysFn.apply(null, arguments);142 // Attach listeners to returned MediaKeys object143 return result.then(function(mediaKeys) {144 mediaKeys.keySystem_ = mediaKeySystemAccess.keySystem;145 this.addListenersToMediaKeys_(mediaKeys);146 return Promise.resolve(mediaKeys);147 }.bind(this));148149 }.bind(this);150151 mediaKeySystemAccess.listenersAdded_ = true;152};153154155/**156 * Adds listeners to the EME methods on a MediaKeys object.157 * @param {MediaKeys} mediaKeys A MediaKeys object to add listeners to.158 * @private159 */160EmeInterception.prototype.addListenersToMediaKeys_ = function(mediaKeys) 161{162 if (mediaKeys.listenersAdded_) {163 return;164 }165 var originalCreateSessionFn = EmeInterception.extendEmeMethod(mediaKeys, mediaKeys.createSession, "CreateSessionCall");166 mediaKeys.createSession = function() 167 {168 var result = originalCreateSessionFn.apply(null, arguments);169 result.keySystem_ = mediaKeys.keySystem_;170 // Attach listeners to returned MediaKeySession object171 this.addListenersToMediaKeySession_(result);172 return result;173 }.bind(this);174175 mediaKeys.setServerCertificate = EmeInterception.extendEmeMethod(mediaKeys, mediaKeys.setServerCertificate, "SetServerCertificateCall");176 mediaKeys.listenersAdded_ = true;177};178179180/** Adds listeners to the EME methods and events on a MediaKeySession object.181 * @param {MediaKeySession} session A MediaKeySession object to add182 * listeners to.183 * @private184 */185EmeInterception.prototype.addListenersToMediaKeySession_ = function(session) 186{187 if (session.listenersAdded_) {188 return;189 }190191 session.generateRequest = EmeInterception.extendEmeMethod(session,session.generateRequest, "GenerateRequestCall");192 session.load = EmeInterception.extendEmeMethod(session, session.load, "LoadCall");193 session.update = EmeInterception.extendEmeMethod(session,session.update, "UpdateCall");194 session.close = EmeInterception.extendEmeMethod(session, session.close, "CloseCall");195 session.remove = EmeInterception.extendEmeMethod(session, session.remove, "RemoveCall");196197 session.addEventListener('message', function(e) 198 {199 e.keySystem = session.keySystem_;200 EmeInterception.interceptEvent("MessageEvent", e);201 });202203 session.addEventListener('keystatuseschange', EmeInterception.interceptEvent.bind(null, "KeyStatusesChangeEvent"));204205 session.listenersAdded_ = true;206};207208209/**210 * Adds listeners to all currently created media elements (audio, video) and sets up a211 * mutation-summary observer to add listeners to any newly created media212 * elements.213 * @private214 */215EmeInterception.prototype.addListenersToAllEmeElements_ = function() 216{217 this.addEmeInterceptionToInitialMediaElements_();218219 // TODO: Use MutationObserver directry220 // var observer = new MutationSummary({221 // callback: function(summaries) {222 // applyListeners(summaries);223 // },224 // queries: [{element: 'video'}, {element: 'audio'}, {element: 'media'}]225 // });226227 // var applyListeners = function(summaries) {228 // for (var i = 0; i < EmeInterception.NUM_MEDIA_ELEMENT_TYPES; i++) {229 // var elements = summaries[i];230 // elements.added.forEach(function(element) {231 // this.addListenersToEmeElement_(element, true);232 // }.bind(this));233 // }234 // }.bind(this);235};236237238/**239 * Adds listeners to the EME elements currently in the document.240 * @private241 */242EmeInterception.prototype.addEmeInterceptionToInitialMediaElements_ = function() 243{244 var audioElements = document.getElementsByTagName('audio');245 for (var i = 0; i < audioElements.length; ++i) {246 this.addListenersToEmeElement_(audioElements[i], false);247 }248 var videoElements = document.getElementsByTagName('video');249 for (var i = 0; i < videoElements.length; ++i) {250 this.addListenersToEmeElement_(videoElements[i], false);251 }252 var mediaElements = document.getElementsByTagName('media');253 for (var i = 0; i < mediaElements.length; ++i) {254 this.addListenersToEmeElement_(mediaElements[i], false);255 }256};257258259/**260 * Adds method and event listeners to media element.261 * @param {HTMLMediaElement} element A HTMLMedia element to add listeners to.262 * @private263 */264EmeInterception.prototype.addListenersToEmeElement_ = function(element) 265{266 this.addEmeEventListeners_(element);267 this.addEmeMethodListeners_(element);268 console.info('EME listeners successfully added to:', element);269};270271272/**273 * Adds event listeners to a media element.274 * @param {HTMLMediaElement} element A HTMLMedia element to add listeners to.275 * @private276 */277EmeInterception.prototype.addEmeEventListeners_ = function(element) 278{279 if (element.eventListenersAdded_) {280 return;281 }282283 if (this.prefixedEmeEnabled) 284 {285 element.addEventListener('webkitneedkey', EmeInterception.interceptEvent.bind(null, "NeedKeyEvent"));286 element.addEventListener('webkitkeymessage', EmeInterception.interceptEvent.bind(null, "KeyMessageEvent"));287 element.addEventListener('webkitkeyadded', EmeInterception.interceptEvent.bind(null, "KeyAddedEvent"));288 element.addEventListener('webkitkeyerror', EmeInterception.interceptEvent.bind(null, "KeyErrorEvent"));289 }290291 element.addEventListener('encrypted', EmeInterception.interceptEvent.bind(null, "EncryptedEvent"));292 element.addEventListener('play', EmeInterception.interceptEvent.bind(null, "PlayEvent"));293294 element.addEventListener('error', function(e) {295 console.error('Error Event');296 EmeInterception.interceptEvent("ErrorEvent", e);297 });298299 element.eventListenersAdded_ = true;300};301302303/**304 * Adds method listeners to a media element.305 * @param {HTMLMediaElement} element A HTMLMedia element to add listeners to.306 * @private307 */308EmeInterception.prototype.addEmeMethodListeners_ = function(element) 309{310 if (element.methodListenersAdded_) {311 return;312 }313314 element.play = EmeInterception.extendEmeMethod(element, element.play, "PlayCall");315316 if (this.prefixedEmeEnabled) {317 element.canPlayType = EmeInterception.extendEmeMethod(element, element.canPlayType, "CanPlayTypeCall");318319 element.webkitGenerateKeyRequest = EmeInterception.extendEmeMethod(element, element.webkitGenerateKeyRequest, "GenerateKeyRequestCall");320 element.webkitAddKey = EmeInterception.extendEmeMethod(element, element.webkitAddKey, "AddKeyCall");321 element.webkitCancelKeyRequest = EmeInterception.extendEmeMethod(element, element.webkitCancelKeyRequest, "CancelKeyRequestCall");322323 }324325 if (this.unprefixedEmeEnabled) {326 element.setMediaKeys = EmeInterception.extendEmeMethod(element, element.setMediaKeys, "SetMediaKeysCall");327 }328329 element.methodListenersAdded_ = true;330};331332333/**334 * Creates a wrapper function that logs calls to the given method.335 * @param {!Object} element An element or object whose function336 * call will be logged.337 * @param {!Function} originalFn The function to log.338 * @param {!Function} type The constructor for a logger class that will339 * be instantiated to log the originalFn call.340 * @return {!Function} The new version, with logging, of orginalFn.341 */342EmeInterception.extendEmeMethod = function(element, originalFn, type) 343{344 return function() 345 {346 try347 {348 var result = originalFn.apply(element, arguments);349 var args = [].slice.call(arguments);350 EmeInterception.interceptCall(type, args, result, element);351 }352 catch (e)353 {354 console.error(e);355 }356 357358 return result;359 };360};361362363/**364 * Intercepts a method call to the console and a separate frame.365 * @param {!Function} constructor The constructor for a logger class that will366 * be instantiated to log this call.367 * @param {Array} args The arguments this call was made with.368 * @param {Object} result The result of this method call.369 * @param {!Object} target The element this method was called on.370 * @return {!eme.EmeMethodCall} The data that has been logged.371 */372EmeInterception.interceptCall = function(type, args, result, target) 373{374 EmeInterception.onOperation(type, args);375 return args;376};377378/**379 * Intercepts an event to the console and a separate frame.380 * @param {!Function} constructor The constructor for a logger class that will381 * be instantiated to log this event.382 * @param {!Event} event An EME event.383 * @return {!eme.EmeEvent} The data that has been logged.384 */385EmeInterception.interceptEvent = function(type, event) 386{387 EmeInterception.onOperation(type, event);388 return event;389};390391EmeInterception.addRobustnessLevelIfNeeded = function(options)392{393 for (var i = 0; i < options.length; i++)394 {395 var option = options[i];396 var videoCapabilities = option["videoCapabilities"];397 var audioCapabilties = option["audioCapabilities"];398 if (videoCapabilities != null)399 {400 for (var j = 0; j < videoCapabilities.length; j++)401 if (videoCapabilities[j]["robustness"] == undefined) videoCapabilities[j]["robustness"] = "SW_SECURE_CRYPTO";402 }403404 if (audioCapabilties != null)405 {406 for (var j = 0; j < audioCapabilties.length; j++)407 if (audioCapabilties[j]["robustness"] == undefined) audioCapabilties[j]["robustness"] = "SW_SECURE_CRYPTO";408 }409 410 option["videoCapabilities"] = videoCapabilities;411 option["audioCapabilities"] = audioCapabilties;412 options[i] = option;413 }414415 return options;416}417 ...

Full Screen

Full Screen

patchedmediakeys_nop.js

Source:patchedmediakeys_nop.js Github

copy

Full Screen

1/**2 * @license3 * Copyright 2016 Google Inc.4 *5 * Licensed under the Apache License, Version 2.0 (the "License");6 * you may not use this file except in compliance with the License.7 * You may obtain a copy of the License at8 *9 * http://www.apache.org/licenses/LICENSE-2.010 *11 * Unless required by applicable law or agreed to in writing, software12 * distributed under the License is distributed on an "AS IS" BASIS,13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14 * See the License for the specific language governing permissions and15 * limitations under the License.16 */17goog.provide('shaka.polyfill.PatchedMediaKeysNop');18goog.require('goog.asserts');19goog.require('shaka.log');20goog.require('shaka.polyfill.register');21/**22 * @namespace shaka.polyfill.PatchedMediaKeysNop23 *24 * @summary A polyfill to stub out25 * {@link https://bit.ly/EmeMar15 EME draft 12 March 2015} on browsers without26 * EME.27 * All methods will fail.28 */29/**30 * Installs the polyfill if needed.31 */32shaka.polyfill.PatchedMediaKeysNop.install = function() {33 if (!window.HTMLVideoElement ||34 (navigator.requestMediaKeySystemAccess &&35 MediaKeySystemAccess.prototype.getConfiguration)) {36 return;37 }38 shaka.log.info('EME not available.');39 // Alias.40 const PatchedMediaKeysNop = shaka.polyfill.PatchedMediaKeysNop;41 // Install patches.42 navigator.requestMediaKeySystemAccess =43 PatchedMediaKeysNop.requestMediaKeySystemAccess;44 // Delete mediaKeys to work around strict mode compatibility issues.45 delete HTMLMediaElement.prototype['mediaKeys'];46 // Work around read-only declaration for mediaKeys by using a string.47 HTMLMediaElement.prototype['mediaKeys'] = null;48 HTMLMediaElement.prototype.setMediaKeys = PatchedMediaKeysNop.setMediaKeys;49 // These are not usable, but allow Player.isBrowserSupported to pass.50 window.MediaKeys = PatchedMediaKeysNop.MediaKeys;51 window.MediaKeySystemAccess = PatchedMediaKeysNop.MediaKeySystemAccess;52};53/**54 * An implementation of navigator.requestMediaKeySystemAccess.55 * Retrieves a MediaKeySystemAccess object.56 *57 * @this {!Navigator}58 * @param {string} keySystem59 * @param {!Array.<!MediaKeySystemConfiguration>} supportedConfigurations60 * @return {!Promise.<!MediaKeySystemAccess>}61 */62shaka.polyfill.PatchedMediaKeysNop.requestMediaKeySystemAccess =63 function(keySystem, supportedConfigurations) {64 shaka.log.debug('PatchedMediaKeysNop.requestMediaKeySystemAccess');65 goog.asserts.assert(this == navigator,66 'bad "this" for requestMediaKeySystemAccess');67 return Promise.reject(new Error(68 'The key system specified is not supported.'));69};70/**71 * An implementation of HTMLMediaElement.prototype.setMediaKeys.72 * Attaches a MediaKeys object to the media element.73 *74 * @this {!HTMLMediaElement}75 * @param {MediaKeys} mediaKeys76 * @return {!Promise}77 */78shaka.polyfill.PatchedMediaKeysNop.setMediaKeys = function(mediaKeys) {79 shaka.log.debug('PatchedMediaKeysNop.setMediaKeys');80 goog.asserts.assert(this instanceof HTMLMediaElement,81 'bad "this" for setMediaKeys');82 if (mediaKeys == null) {83 return Promise.resolve();84 }85 return Promise.reject(new Error('MediaKeys not supported.'));86};87/**88 * An unusable constructor for MediaKeys.89 * @constructor90 * @struct91 * @implements {MediaKeys}92 */93shaka.polyfill.PatchedMediaKeysNop.MediaKeys = function() {94 throw new TypeError('Illegal constructor.');95};96/** @override */97shaka.polyfill.PatchedMediaKeysNop.MediaKeys.prototype.createSession =98 function() {};99/** @override */100shaka.polyfill.PatchedMediaKeysNop.MediaKeys.prototype.setServerCertificate =101 function() {};102/**103 * An unusable constructor for MediaKeySystemAccess.104 * @constructor105 * @struct106 * @implements {MediaKeySystemAccess}107 */108shaka.polyfill.PatchedMediaKeysNop.MediaKeySystemAccess = function() {109 throw new TypeError('Illegal constructor.');110};111/** @override */112shaka.polyfill.PatchedMediaKeysNop.MediaKeySystemAccess.prototype.113 getConfiguration = function() {};114/** @override */115shaka.polyfill.PatchedMediaKeysNop.MediaKeySystemAccess.prototype.116 createMediaKeys = function() {};117/** @override */118shaka.polyfill.PatchedMediaKeysNop.MediaKeySystemAccess.prototype.119 keySystem;120// A low priority ensures this is the last and acts as a fallback....

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var test = async_test('MediaKeySystemAccess method of wpt runner');2test.step(function() {3 var video = document.createElement('video');4 navigator.requestMediaKeySystemAccess('org.w3.clearkey', [{5 audioCapabilities: [{6 contentType: 'audio/webm; codecs="opus"'7 }],8 videoCapabilities: [{9 contentType: 'video/webm; codecs="vp9"'10 }]11 }]).then(function(access) {12 test.done();13 }).catch(function(error) {14 assert_unreached(error);15 });16});

Full Screen

Using AI Code Generation

copy

Full Screen

1var _video = document.querySelector('video');2var _mediaKeys;3var _mediaKeySession;4var _mediaKeySystemAccess;5var _mediaKeySystemConfigurations = [{6 videoCapabilities: [{7 contentType: 'video/mp4; codecs="avc1.640029"'8 }]9}];10function getMediaKeySystemAccess() {11 navigator.requestMediaKeySystemAccess('org.w3.clearkey', _mediaKeySystemConfigurations)12 .then(function (mediaKeySystemAccess) {13 _mediaKeySystemAccess = mediaKeySystemAccess;14 console.log('mediaKeySystemAccess = ' + mediaKeySystemAccess);15 return mediaKeySystemAccess.createMediaKeys();16 })17 .then(function (mediaKeys) {18 _mediaKeys = mediaKeys;19 console.log('mediaKeys = ' + mediaKeys);20 _video.setMediaKeys(mediaKeys);21 return _mediaKeys.createSession();22 })23 .then(function (mediaKeySession) {24 _mediaKeySession = mediaKeySession;25 console.log('mediaKeySession = ' + mediaKeySession);26 return _mediaKeySession.generateRequest('cenc', new Uint8Array([0, 1, 2, 3]));27 })28 .then(function () {29 console.log('generateRequest succeeded');30 _mediaKeySession.addEventListener('message', function (event) {31 console.log('message event: ' + event.messageType);32 console.log('message event: ' + event.message);33 });34 })35 .catch(function (error) {36 console.log('error: ' + error);37 });38}39getMediaKeySystemAccess();40var _video = document.querySelector('video');41var _mediaKeys;42var _mediaKeySession;43var _mediaKeySystemAccess;44var _mediaKeySystemConfigurations = [{45 videoCapabilities: [{46 contentType: 'video/mp4; codecs="avc1.640029"'47 }]48}];49function getMediaKeySystemAccess() {50 navigator.requestMediaKeySystemAccess('org.w3.clearkey', _mediaKeySystemConfigurations)51 .then(function (mediaKeySystemAccess) {52 _mediaKeySystemAccess = mediaKeySystemAccess;53 console.log('mediaKeySystemAccess = '

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptRunner = require('wpt-runner');2var test = require('tape');3test('test', function(t) {4 t.error(err);5 t.ok(results);6 t.end();7 });8});

Full Screen

Using AI Code Generation

copy

Full Screen

1var test = async_test('MediaKeySystemAccess method of wpt-runner');2var wptRunner = new WptRunner();3wptRunner.runTest('encrypted-media', 'mediakeysystemaccess-method.html', function(results) {4 test.step(function() {5 assert_equals(results.status, 'OK');6 });7 test.done();8});9var test = async_test('MediaKeySystemAccess method of wpt-runner');10var wptRunner = new WptRunner();11wptRunner.runTest('encrypted-media', 'mediakeysystemaccess-method.html', function(results) {12 test.step(function() {13 assert_equals(results.status, 'OK');14 });15 test.done();16});17var test = async_test('MediaKeySystemAccess method of wpt-runner');18var wptRunner = new WptRunner();19wptRunner.runTest('encrypted-media', 'mediakeysystemaccess-method.html', function(results) {20 test.step(function() {21 assert_equals(results.status, 'OK');22 });23 test.done();24});25var test = async_test('MediaKeySystemAccess method of wpt-runner');26var wptRunner = new WptRunner();27wptRunner.runTest('encrypted-media', 'mediakeysystemaccess-method.html', function(results) {28 test.step(function() {29 assert_equals(results.status, 'OK');30 });31 test.done();32});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptRunner = new WptRunner();2});3var wptRunner = new WptRunner();4});5var wptRunner = new WptRunner();6});7var wptRunner = new WptRunner();8});9var wptRunner = new WptRunner();10});11var wptRunner = new WptRunner();12});13var wptRunner = new WptRunner();14});15var wptRunner = new WptRunner();16});17var wptRunner = new WptRunner();18});19var wptRunner = new WptRunner();20});

Full Screen

Using AI Code Generation

copy

Full Screen

1var mediaKeySystemAccess = null;2var mediaKeys = null;3var mediaKeySession = null;4var initData = null;5var keySystem = "com.widevine.alpha";6var keySystemConfig = {7 videoCapabilities: [{8 contentType: 'video/mp4; codecs="avc1.42E01E"'9 }],10 audioCapabilities: [{11 contentType: 'audio/mp4; codecs="mp4a.40.2"'12 }],13};14function onMessage(event) {15 console.log("onMessage: " + event.messageType);16 if (event.messageType == "license-request") {17 var licenseRequest = event.message;18 console.log("licenseRequest: " + licenseRequest);19 var licenseResponse = getLicenseResponse(licenseRequest);20 console.log("licenseResponse: " + licenseResponse);21 mediaKeySession.update(licenseResponse);22 }23}24function getLicenseResponse(licenseRequest) {25 var licenseResponse = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);26 return licenseResponse;27}28function onKeyStatusesChange(event) {29 console.log("onKeyStatusesChange");30 var keyStatuses = mediaKeySession.keyStatuses;31 console.log(keyStatuses);32}33function onKeyAdded(event) {34 console.log("onKeyAdded");35 var keyStatuses = mediaKeySession.keyStatuses;36 console.log(keyStatuses);37}38function onKeyError(event) {39 console.log("onKeyError: " + event.errorCode.code);40 var keyStatuses = mediaKeySession.keyStatuses;41 console.log(keyStatuses);42}43function onKeyMessage(event) {

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