The goal is to simplify and abstract feature logic detection. Currently lots of places depend on various calls to `shaka.util.Platform` and mainteinance of this is hard & not easy to read. By introducing device API ideally rest of the player logic would look into device features instead of directly checking platform. Additionally we can more easily cache needed values, so we won't have to parse user agent several times anymore. --------- Co-authored-by: Álvaro Velad Galván <[email protected]>
55 lines
1.4 KiB
JavaScript
55 lines
1.4 KiB
JavaScript
/*! @license
|
|
* Shaka Player
|
|
* Copyright 2016 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
goog.provide('shaka.polyfill.PatchedMediaKeysCert');
|
|
|
|
goog.require('shaka.device.DeviceFactory');
|
|
goog.require('shaka.log');
|
|
goog.require('shaka.polyfill');
|
|
|
|
|
|
/**
|
|
* @summary A polyfill to fix setServerCertificate implementation on
|
|
* older platforms which claim to support modern EME.
|
|
* @export
|
|
*/
|
|
shaka.polyfill.PatchedMediaKeysCert = class {
|
|
/**
|
|
* Installs the polyfill if needed.
|
|
* @export
|
|
*/
|
|
static install() {
|
|
if (!window.MediaKeys) {
|
|
// No MediaKeys available
|
|
return;
|
|
}
|
|
const device = shaka.device.DeviceFactory.getDevice();
|
|
// eslint-disable-next-line no-restricted-syntax
|
|
if (MediaKeys.prototype.setServerCertificate &&
|
|
device.supportsServerCertificate()) {
|
|
// setServerCertificate is there and userAgent seems to be valid.
|
|
return;
|
|
}
|
|
|
|
shaka.log.info('Patching MediaKeys.setServerCertificate');
|
|
// eslint-disable-next-line no-restricted-syntax
|
|
MediaKeys.prototype.setServerCertificate =
|
|
shaka.polyfill.PatchedMediaKeysCert.setServerCertificate_;
|
|
}
|
|
|
|
/**
|
|
* @param {!BufferSource} certificate
|
|
* @return {!Promise<boolean>}
|
|
* @private
|
|
*/
|
|
static setServerCertificate_(certificate) {
|
|
shaka.log.debug('PatchedMediaKeysCert.setServerCertificate');
|
|
return Promise.resolve(false);
|
|
}
|
|
};
|
|
|
|
shaka.polyfill.register(shaka.polyfill.PatchedMediaKeysCert.install);
|