Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

JitsiTrackError.js 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. TRACK_ERROR_TO_MESSAGE_MAP[JitsiTrackErrors.NO_DATA_FROM_SOURCE]
  28. = "The track has stopped receiving data from it's source";
  29. // FIXME: Using prototype inheritance because otherwise instanceof is not
  30. // working properly (see https://github.com/babel/babel/issues/3083)
  31. /**
  32. *
  33. * Represents an error that occurred to a JitsiTrack. Can represent various
  34. * types of errors. For error descriptions (@see JitsiTrackErrors).
  35. *
  36. * @extends Error
  37. *
  38. *
  39. * @constructor
  40. * @param {Object|string} error - error object or error name
  41. * @param {Object|string} (options) - getUserMedia constraints object or
  42. * error message
  43. * @param {('audio'|'video'|'desktop'|'screen'|'audiooutput')[]} (devices) -
  44. * list of getUserMedia requested devices
  45. */
  46. function JitsiTrackError(error, options, devices) {
  47. if (typeof error === "object" && typeof error.name !== "undefined") {
  48. /**
  49. * Additional information about original getUserMedia error
  50. * and constraints.
  51. * @type {{
  52. * error: Object,
  53. * constraints: Object,
  54. * devices: Array.<'audio'|'video'|'desktop'|'screen'>
  55. * }}
  56. */
  57. this.gum = {
  58. error,
  59. constraints: options,
  60. devices: devices && Array.isArray(devices)
  61. ? devices.slice(0)
  62. : undefined
  63. };
  64. switch (error.name) {
  65. case "PermissionDeniedError":
  66. case "SecurityError":
  67. this.name = JitsiTrackErrors.PERMISSION_DENIED;
  68. this.message
  69. = TRACK_ERROR_TO_MESSAGE_MAP[this.name]
  70. + (this.gum.devices || []).join(", ");
  71. break;
  72. case "DevicesNotFoundError":
  73. case "NotFoundError":
  74. this.name = JitsiTrackErrors.NOT_FOUND;
  75. this.message
  76. = TRACK_ERROR_TO_MESSAGE_MAP[this.name]
  77. + (this.gum.devices || []).join(", ");
  78. break;
  79. case "ConstraintNotSatisfiedError":
  80. case "OverconstrainedError":
  81. var constraintName = error.constraintName;
  82. if (options
  83. && options.video
  84. && (!devices || devices.indexOf('video') > -1)
  85. && (constraintName === "minWidth"
  86. || constraintName === "maxWidth"
  87. || constraintName === "minHeight"
  88. || constraintName === "maxHeight"
  89. || constraintName === "width"
  90. || constraintName === "height")) {
  91. this.name = JitsiTrackErrors.UNSUPPORTED_RESOLUTION;
  92. this.message
  93. = TRACK_ERROR_TO_MESSAGE_MAP[this.name]
  94. + getResolutionFromFailedConstraint(
  95. constraintName,
  96. options);
  97. } else {
  98. this.name = JitsiTrackErrors.CONSTRAINT_FAILED;
  99. this.message
  100. = TRACK_ERROR_TO_MESSAGE_MAP[this.name]
  101. + error.constraintName;
  102. }
  103. break;
  104. default:
  105. this.name = JitsiTrackErrors.GENERAL;
  106. this.message
  107. = error.message || TRACK_ERROR_TO_MESSAGE_MAP[this.name];
  108. break;
  109. }
  110. } else if (typeof error === "string") {
  111. if (TRACK_ERROR_TO_MESSAGE_MAP[error]) {
  112. this.name = error;
  113. this.message = options || TRACK_ERROR_TO_MESSAGE_MAP[error];
  114. } else {
  115. // this is some generic error that do not fit any of our
  116. // pre-defined errors, so don't give it any specific name, just
  117. // store message
  118. this.message = error;
  119. }
  120. } else {
  121. throw new Error("Invalid arguments");
  122. }
  123. this.stack = error.stack || (new Error()).stack;
  124. }
  125. JitsiTrackError.prototype = Object.create(Error.prototype);
  126. JitsiTrackError.prototype.constructor = JitsiTrackError;
  127. /**
  128. * Gets failed resolution constraint from corresponding object.
  129. * @param {string} failedConstraintName
  130. * @param {Object} constraints
  131. * @returns {string|number}
  132. */
  133. function getResolutionFromFailedConstraint(failedConstraintName, constraints) {
  134. if (constraints && constraints.video && constraints.video.mandatory) {
  135. switch (failedConstraintName) {
  136. case "width":
  137. return constraints.video.mandatory.minWidth;
  138. case "height":
  139. return constraints.video.mandatory.minHeight;
  140. default:
  141. return constraints.video.mandatory[failedConstraintName] || "";
  142. }
  143. }
  144. return "";
  145. }
  146. export default JitsiTrackError;