Source: lib/polyfill/mediakeys.js

  1. /**
  2. * @license
  3. * 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 at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * 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 and
  15. * limitations under the License.
  16. */
  17. goog.provide('shaka.polyfill.MediaKeys');
  18. goog.require('shaka.log');
  19. goog.require('shaka.polyfill.PatchedMediaKeysMs');
  20. goog.require('shaka.polyfill.PatchedMediaKeysNop');
  21. goog.require('shaka.polyfill.PatchedMediaKeysWebkit');
  22. goog.require('shaka.polyfill.register');
  23. /**
  24. * @namespace shaka.polyfill.MediaKeys
  25. *
  26. * @summary A polyfill to unify EME APIs across browser versions.
  27. *
  28. * The {@link https://w3c.github.io/encrypted-media/ EME spec} is still a
  29. * work-in-progress. As such, we need to provide a consistent API to the Shaka
  30. * Player. Until the spec is completely stable, the API provided by this
  31. * polyfill may lag behind the latest spec developments.
  32. */
  33. /**
  34. * Install the polyfill if needed.
  35. */
  36. shaka.polyfill.MediaKeys.install = function() {
  37. shaka.log.debug('MediaKeys.install');
  38. if (!window.HTMLVideoElement) {
  39. // Avoid errors on very old browsers.
  40. return;
  41. }
  42. if (navigator.requestMediaKeySystemAccess &&
  43. MediaKeySystemAccess.prototype.getConfiguration) {
  44. shaka.log.info('Using native EME as-is.');
  45. } else if (HTMLMediaElement.prototype.webkitGenerateKeyRequest) {
  46. shaka.log.info('Using webkit-prefixed EME v0.1b');
  47. shaka.polyfill.PatchedMediaKeysWebkit.install('webkit');
  48. } else if (HTMLMediaElement.prototype.generateKeyRequest) {
  49. shaka.log.info('Using nonprefixed EME v0.1b');
  50. shaka.polyfill.PatchedMediaKeysWebkit.install('');
  51. } else if (window.MSMediaKeys) {
  52. shaka.log.info('Using ms-prefixed EME v20140218');
  53. shaka.polyfill.PatchedMediaKeysMs.install();
  54. } else {
  55. shaka.log.info('EME not available.');
  56. shaka.polyfill.PatchedMediaKeysNop.install();
  57. }
  58. };
  59. shaka.polyfill.register(shaka.polyfill.MediaKeys.install);