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.4KB

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