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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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[JitsiTrackErrors.CHROME_EXTENSION_USER_CANCELED]
  10. = "User canceled Chrome's screen sharing prompt";
  11. TRACK_ERROR_TO_MESSAGE_MAP[JitsiTrackErrors.CHROME_EXTENSION_GENERIC_ERROR]
  12. = "Unknown error from Chrome extension";
  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.TRACK_IS_DISPOSED]
  22. = "Track has been already disposed";
  23. TRACK_ERROR_TO_MESSAGE_MAP[JitsiTrackErrors.TRACK_NO_STREAM_FOUND]
  24. = "Track does not have an associated Media Stream";
  25. TRACK_ERROR_TO_MESSAGE_MAP[JitsiTrackErrors.TRACK_MUTE_UNMUTE_IN_PROGRESS]
  26. = "Track mute/unmute process is currently in progress";
  27. /**
  28. * Represents an error that occurred to a JitsiTrack. Can represent various
  29. * types of errors. For error descriptions (@see JitsiTrackErrors).
  30. *
  31. * @extends Error
  32. */
  33. export default class JitsiTrackError extends Error {
  34. /**
  35. * Initializes a new JitsiTrackError instance.
  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. constructor(error, options, devices) {
  45. super();
  46. if (typeof error === "object" && typeof error.name !== "undefined") {
  47. /**
  48. * Additional information about original getUserMedia error
  49. * and constraints.
  50. * @type {{
  51. * error: Object,
  52. * constraints: Object,
  53. * devices: Array.<'audio'|'video'|'desktop'|'screen'>
  54. * }}
  55. */
  56. this.gum = {
  57. error,
  58. constraints: options,
  59. devices: devices && Array.isArray(devices)
  60. ? devices.slice(0)
  61. : undefined
  62. };
  63. switch (error.name) {
  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. var constraintName = error.constraintName;
  81. if (options
  82. && options.video
  83. && (!devices || devices.indexOf('video') > -1)
  84. && (constraintName === "minWidth"
  85. || constraintName === "maxWidth"
  86. || constraintName === "minHeight"
  87. || constraintName === "maxHeight"
  88. || constraintName === "width"
  89. || constraintName === "height")) {
  90. this.name = JitsiTrackErrors.UNSUPPORTED_RESOLUTION;
  91. this.message
  92. = TRACK_ERROR_TO_MESSAGE_MAP[this.name]
  93. + getResolutionFromFailedConstraint(
  94. constraintName,
  95. options);
  96. } else {
  97. this.name = JitsiTrackErrors.CONSTRAINT_FAILED;
  98. this.message
  99. = TRACK_ERROR_TO_MESSAGE_MAP[this.name]
  100. + error.constraintName;
  101. }
  102. break;
  103. default:
  104. this.name = JitsiTrackErrors.GENERAL;
  105. this.message
  106. = error.message || TRACK_ERROR_TO_MESSAGE_MAP[this.name];
  107. break;
  108. }
  109. } else if (typeof error === "string") {
  110. if (TRACK_ERROR_TO_MESSAGE_MAP[error]) {
  111. this.name = error;
  112. this.message = options || TRACK_ERROR_TO_MESSAGE_MAP[error];
  113. } else {
  114. // this is some generic error that do not fit any of our
  115. // pre-defined errors, so don't give it any specific name, just
  116. // store message
  117. this.message = error;
  118. }
  119. } else {
  120. throw new Error("Invalid arguments");
  121. }
  122. this.stack = error.stack || (new Error()).stack;
  123. }
  124. }
  125. /**
  126. * Gets failed resolution constraint from corresponding object.
  127. * @param {string} failedConstraintName
  128. * @param {Object} constraints
  129. * @returns {string|number}
  130. */
  131. function getResolutionFromFailedConstraint(failedConstraintName, constraints) {
  132. if (constraints && constraints.video && constraints.video.mandatory) {
  133. switch (failedConstraintName) {
  134. case "width":
  135. return constraints.video.mandatory.minWidth;
  136. case "height":
  137. return constraints.video.mandatory.minHeight;
  138. default:
  139. return constraints.video.mandatory[failedConstraintName] || "";
  140. }
  141. }
  142. return "";
  143. }