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