getdisplaymedia.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * Copyright (c) 2018 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.shimGetDisplayMedia = shimGetDisplayMedia;
  14. function shimGetDisplayMedia(window, preferredMediaSource) {
  15. if (window.navigator.mediaDevices && 'getDisplayMedia' in window.navigator.mediaDevices) {
  16. return;
  17. }
  18. if (!window.navigator.mediaDevices) {
  19. return;
  20. }
  21. window.navigator.mediaDevices.getDisplayMedia = function getDisplayMedia(constraints) {
  22. if (!(constraints && constraints.video)) {
  23. var err = new DOMException('getDisplayMedia without video ' + 'constraints is undefined');
  24. err.name = 'NotFoundError';
  25. // from https://heycam.github.io/webidl/#idl-DOMException-error-names
  26. err.code = 8;
  27. return Promise.reject(err);
  28. }
  29. if (constraints.video === true) {
  30. constraints.video = {
  31. mediaSource: preferredMediaSource
  32. };
  33. } else {
  34. constraints.video.mediaSource = preferredMediaSource;
  35. }
  36. return window.navigator.mediaDevices.getUserMedia(constraints);
  37. };
  38. }