modified lib-jitsi-meet dev repo
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

JitsiTrackError.js 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. import * as JitsiTrackErrors from './JitsiTrackErrors';
  2. const TRACK_ERROR_TO_MESSAGE_MAP = {};
  3. TRACK_ERROR_TO_MESSAGE_MAP[JitsiTrackErrors.UNSUPPORTED_RESOLUTION]
  4. = 'Video resolution is not supported: ';
  5. TRACK_ERROR_TO_MESSAGE_MAP[JitsiTrackErrors.SCREENSHARING_USER_CANCELED]
  6. = 'User canceled screen sharing prompt';
  7. TRACK_ERROR_TO_MESSAGE_MAP[JitsiTrackErrors.SCREENSHARING_GENERIC_ERROR]
  8. = 'Unknown error from screensharing';
  9. TRACK_ERROR_TO_MESSAGE_MAP[JitsiTrackErrors.ELECTRON_DESKTOP_PICKER_ERROR]
  10. = 'Unkown error from desktop picker';
  11. TRACK_ERROR_TO_MESSAGE_MAP[JitsiTrackErrors.ELECTRON_DESKTOP_PICKER_NOT_FOUND]
  12. = 'Failed to detect desktop picker';
  13. TRACK_ERROR_TO_MESSAGE_MAP[JitsiTrackErrors.GENERAL]
  14. = 'Generic getUserMedia error';
  15. TRACK_ERROR_TO_MESSAGE_MAP[JitsiTrackErrors.PERMISSION_DENIED]
  16. = 'User denied permission to use device(s): ';
  17. TRACK_ERROR_TO_MESSAGE_MAP[JitsiTrackErrors.NOT_FOUND]
  18. = 'Requested device(s) was/were not found: ';
  19. TRACK_ERROR_TO_MESSAGE_MAP[JitsiTrackErrors.CONSTRAINT_FAILED]
  20. = 'Constraint could not be satisfied: ';
  21. TRACK_ERROR_TO_MESSAGE_MAP[JitsiTrackErrors.TIMEOUT]
  22. = 'Could not start media source. Timeout occured!';
  23. TRACK_ERROR_TO_MESSAGE_MAP[JitsiTrackErrors.TRACK_IS_DISPOSED]
  24. = 'Track has been already disposed';
  25. TRACK_ERROR_TO_MESSAGE_MAP[JitsiTrackErrors.TRACK_NO_STREAM_FOUND]
  26. = 'Track does not have an associated Media Stream';
  27. // FIXME: Using prototype inheritance because otherwise instanceof is not
  28. // working properly (see https://github.com/babel/babel/issues/3083)
  29. /**
  30. *
  31. * Represents an error that occurred to a JitsiTrack. Can represent various
  32. * types of errors. For error descriptions (@see JitsiTrackErrors).
  33. *
  34. * @extends Error
  35. *
  36. *
  37. * @constructor
  38. * @param {Object|string} error - error object or error name
  39. * @param {Object|string} (options) - getUserMedia constraints object or
  40. * error message
  41. * @param {('audio'|'video'|'desktop'|'screen'|'audiooutput')[]} (devices) -
  42. * list of getUserMedia requested devices
  43. */
  44. function JitsiTrackError(error, options, devices) {
  45. if (typeof error === 'object' && typeof error.name !== 'undefined') {
  46. /**
  47. * Additional information about original getUserMedia error
  48. * and constraints.
  49. * @type {{
  50. * error: Object,
  51. * constraints: Object,
  52. * devices: Array.<'audio'|'video'|'desktop'|'screen'>
  53. * }}
  54. */
  55. this.gum = {
  56. error,
  57. constraints: options,
  58. devices: devices && Array.isArray(devices)
  59. ? devices.slice(0)
  60. : undefined
  61. };
  62. switch (error.name) {
  63. case 'NotAllowedError':
  64. case 'PermissionDeniedError':
  65. case 'SecurityError':
  66. this.name = JitsiTrackErrors.PERMISSION_DENIED;
  67. this.message
  68. = TRACK_ERROR_TO_MESSAGE_MAP[this.name]
  69. + (this.gum.devices || []).join(', ');
  70. break;
  71. case 'DevicesNotFoundError':
  72. case 'NotFoundError':
  73. this.name = JitsiTrackErrors.NOT_FOUND;
  74. this.message
  75. = TRACK_ERROR_TO_MESSAGE_MAP[this.name]
  76. + (this.gum.devices || []).join(', ');
  77. break;
  78. case 'ConstraintNotSatisfiedError':
  79. case 'OverconstrainedError': {
  80. const constraintName = error.constraintName || error.constraint;
  81. // we treat deviceId as unsupported resolution, as we want to
  82. // retry and finally if everything fails to remove deviceId from
  83. // mandatory constraints
  84. if (options
  85. && options.video
  86. && (!devices || devices.indexOf('video') > -1)
  87. && (constraintName === 'minWidth'
  88. || constraintName === 'maxWidth'
  89. || constraintName === 'minHeight'
  90. || constraintName === 'maxHeight'
  91. || constraintName === 'width'
  92. || constraintName === 'height'
  93. || constraintName === 'deviceId')) {
  94. this.name = JitsiTrackErrors.UNSUPPORTED_RESOLUTION;
  95. this.message
  96. = TRACK_ERROR_TO_MESSAGE_MAP[this.name]
  97. + getResolutionFromFailedConstraint(
  98. constraintName,
  99. options);
  100. } else {
  101. this.name = JitsiTrackErrors.CONSTRAINT_FAILED;
  102. this.message
  103. = TRACK_ERROR_TO_MESSAGE_MAP[this.name]
  104. + error.constraintName;
  105. }
  106. break;
  107. }
  108. default:
  109. this.name = JitsiTrackErrors.GENERAL;
  110. this.message
  111. = error.message || TRACK_ERROR_TO_MESSAGE_MAP[this.name];
  112. break;
  113. }
  114. } else if (typeof error === 'string') {
  115. if (TRACK_ERROR_TO_MESSAGE_MAP[error]) {
  116. this.name = error;
  117. this.message = options || TRACK_ERROR_TO_MESSAGE_MAP[error];
  118. } else {
  119. // this is some generic error that do not fit any of our
  120. // pre-defined errors, so don't give it any specific name, just
  121. // store message
  122. this.message = error;
  123. }
  124. } else {
  125. throw new Error('Invalid arguments');
  126. }
  127. this.stack = error.stack || new Error().stack;
  128. }
  129. JitsiTrackError.prototype = Object.create(Error.prototype);
  130. JitsiTrackError.prototype.constructor = JitsiTrackError;
  131. /**
  132. * Gets failed resolution constraint from corresponding object.
  133. * @param {string} failedConstraintName
  134. * @param {Object} constraints
  135. * @returns {string|number}
  136. */
  137. function getResolutionFromFailedConstraint(failedConstraintName, constraints) {
  138. if (constraints && constraints.video && constraints.video.mandatory) {
  139. switch (failedConstraintName) {
  140. case 'width':
  141. return constraints.video.mandatory.minWidth;
  142. case 'height':
  143. return constraints.video.mandatory.minHeight;
  144. default:
  145. return constraints.video.mandatory[failedConstraintName] || '';
  146. }
  147. }
  148. return '';
  149. }
  150. export default JitsiTrackError;