selectaudiooutput.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * Copyright (c) 2022 The adapter.js project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree.
  7. */
  8. /* eslint-env node */
  9. 'use strict';
  10. Object.defineProperty(exports, "__esModule", {
  11. value: true
  12. });
  13. exports.shimSelectAudioOutput = shimSelectAudioOutput;
  14. function shimSelectAudioOutput(window) {
  15. // Polyfillying only makes sense when setSinkId is available
  16. // and the function is not already there.
  17. if (!('HTMLMediaElement' in window)) {
  18. return;
  19. }
  20. if (!('setSinkId' in window.HTMLMediaElement.prototype)) {
  21. return;
  22. }
  23. if (!(window.navigator && window.navigator.mediaDevices)) {
  24. return;
  25. }
  26. if (!window.navigator.mediaDevices.enumerateDevices) {
  27. return;
  28. }
  29. if (window.navigator.mediaDevices.selectAudioOutput) {
  30. return;
  31. }
  32. window.navigator.mediaDevices.selectAudioOutput = function () {
  33. return window.navigator.mediaDevices.enumerateDevices().then(function (devices) {
  34. return devices.filter(function (d) {
  35. return d.kind === 'audiooutput';
  36. });
  37. });
  38. };
  39. }