Source: lib/polyfill/patchedmediakeys_cert.js

  1. /*! @license
  2. * Shaka Player
  3. * Copyright 2016 Google LLC
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. goog.provide('shaka.polyfill.PatchedMediaKeysCert');
  7. goog.require('shaka.device.DeviceFactory');
  8. goog.require('shaka.log');
  9. goog.require('shaka.polyfill');
  10. /**
  11. * @summary A polyfill to fix setServerCertificate implementation on
  12. * older platforms which claim to support modern EME.
  13. * @export
  14. */
  15. shaka.polyfill.PatchedMediaKeysCert = class {
  16. /**
  17. * Installs the polyfill if needed.
  18. * @export
  19. */
  20. static install() {
  21. if (!window.MediaKeys) {
  22. // No MediaKeys available
  23. return;
  24. }
  25. const device = shaka.device.DeviceFactory.getDevice();
  26. // eslint-disable-next-line no-restricted-syntax
  27. if (MediaKeys.prototype.setServerCertificate &&
  28. device.supportsServerCertificate()) {
  29. // setServerCertificate is there and userAgent seems to be valid.
  30. return;
  31. }
  32. shaka.log.info('Patching MediaKeys.setServerCertificate');
  33. // eslint-disable-next-line no-restricted-syntax
  34. MediaKeys.prototype.setServerCertificate =
  35. shaka.polyfill.PatchedMediaKeysCert.setServerCertificate_;
  36. }
  37. /**
  38. * @param {!BufferSource} certificate
  39. * @return {!Promise<boolean>}
  40. * @private
  41. */
  42. static setServerCertificate_(certificate) {
  43. shaka.log.debug('PatchedMediaKeysCert.setServerCertificate');
  44. return Promise.resolve(false);
  45. }
  46. };
  47. shaka.polyfill.register(shaka.polyfill.PatchedMediaKeysCert.install);