Home Reference Source

src/utils/mediakeys-helper.ts

  1. /**
  2. * @see https://developer.mozilla.org/en-US/docs/Web/API/Navigator/requestMediaKeySystemAccess
  3. */
  4. export enum KeySystems {
  5. WIDEVINE = 'com.widevine.alpha',
  6. PLAYREADY = 'com.microsoft.playready',
  7. }
  8.  
  9. export type MediaKeyFunc = (
  10. keySystem: KeySystems,
  11. supportedConfigurations: MediaKeySystemConfiguration[]
  12. ) => Promise<MediaKeySystemAccess>;
  13. const requestMediaKeySystemAccess = (function (): MediaKeyFunc | null {
  14. if (
  15. typeof self !== 'undefined' &&
  16. self.navigator &&
  17. self.navigator.requestMediaKeySystemAccess
  18. ) {
  19. return self.navigator.requestMediaKeySystemAccess.bind(self.navigator);
  20. } else {
  21. return null;
  22. }
  23. })();
  24.  
  25. export { requestMediaKeySystemAccess };