소스 검색

Merge pull request #309 from jitsi/fix_jitsi_track_error

Fixes instanceof JitsiTrackError
dev1
Paweł Domas 9 년 전
부모
커밋
4b4e2261a7
1개의 변경된 파일89개의 추가작업 그리고 85개의 파일을 삭제
  1. 89
    85
      JitsiTrackError.js

+ 89
- 85
JitsiTrackError.js 파일 보기

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

Loading…
취소
저장