3 exports.__esModule = true;
5 var _obj = require('./utils/obj');
8 * A Custom `MediaError` class which mimics the standard HTML5 `MediaError` class.
10 * @param {number|string|Object|MediaError} value
11 * This can be of multiple types:
12 * - number: should be a standard error code
13 * - string: an error message (the code will be 0)
14 * - Object: arbitrary properties
15 * - `MediaError` (native): used to populate a video.js `MediaError` object
16 * - `MediaError` (video.js): will return itself if it's already a
17 * video.js `MediaError` object.
19 * @see [MediaError Spec]{@link https://dev.w3.org/html5/spec-author-view/video.html#mediaerror}
20 * @see [Encrypted MediaError Spec]{@link https://www.w3.org/TR/2013/WD-encrypted-media-20130510/#error-codes}
24 function MediaError(value) {
26 // Allow redundant calls to this constructor to avoid having `instanceof`
27 // checks peppered around the code.
28 if (value instanceof MediaError) {
32 if (typeof value === 'number') {
34 } else if (typeof value === 'string') {
35 // default code is zero, so this is a custom error
37 } else if ((0, _obj.isObject)(value)) {
39 // We assign the `code` property manually because native `MediaError` objects
40 // do not expose it as an own/enumerable property of the object.
41 if (typeof value.code === 'number') {
42 this.code = value.code;
45 (0, _obj.assign)(this, value);
49 this.message = MediaError.defaultMessages[this.code] || '';
54 * The error code that refers two one of the defined `MediaError` types
59 * @file media-error.js
61 MediaError.prototype.code = 0;
64 * An optional message that to show with the error. Message is not part of the HTML5
65 * video spec but allows for more informative custom errors.
69 MediaError.prototype.message = '';
72 * An optional status code that can be set by plugins to allow even more detail about
73 * the error. For example a plugin might provide a specific HTTP status code and an
74 * error message for that code. Then when the plugin gets that error this class will
75 * know how to display an error message for it. This allows a custom message to show
76 * up on the `Player` error overlay.
80 MediaError.prototype.status = null;
83 * Errors indexed by the W3C standard. The order **CANNOT CHANGE**! See the
84 * specification listed under {@link MediaError} for more information.
88 * @property {string} 0 - MEDIA_ERR_CUSTOM
89 * @property {string} 1 - MEDIA_ERR_CUSTOM
90 * @property {string} 2 - MEDIA_ERR_ABORTED
91 * @property {string} 3 - MEDIA_ERR_NETWORK
92 * @property {string} 4 - MEDIA_ERR_SRC_NOT_SUPPORTED
93 * @property {string} 5 - MEDIA_ERR_ENCRYPTED
95 MediaError.errorTypes = ['MEDIA_ERR_CUSTOM', 'MEDIA_ERR_ABORTED', 'MEDIA_ERR_NETWORK', 'MEDIA_ERR_DECODE', 'MEDIA_ERR_SRC_NOT_SUPPORTED', 'MEDIA_ERR_ENCRYPTED'];
98 * The default `MediaError` messages based on the {@link MediaError.errorTypes}.
103 MediaError.defaultMessages = {
104 1: 'You aborted the media playback',
105 2: 'A network error caused the media download to fail part-way.',
106 3: 'The media playback was aborted due to a corruption problem or because the media used features your browser did not support.',
107 4: 'The media could not be loaded, either because the server or network failed or because the format is not supported.',
108 5: 'The media is encrypted and we do not have the keys to decrypt it.'
111 // Add types as properties on MediaError
112 // e.g. MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED = 4;
113 for (var errNum = 0; errNum < MediaError.errorTypes.length; errNum++) {
114 MediaError[MediaError.errorTypes[errNum]] = errNum;
115 // values should be accessible on both the class and instance
116 MediaError.prototype[MediaError.errorTypes[errNum]] = errNum;
119 // jsdocs for instance/static members added above
120 // instance methods use `#` and static methods use `.`
122 * W3C error code for any custom error.
124 * @member MediaError#MEDIA_ERR_CUSTOM
129 * W3C error code for any custom error.
131 * @member MediaError.MEDIA_ERR_CUSTOM
137 * W3C error code for media error aborted.
139 * @member MediaError#MEDIA_ERR_ABORTED
144 * W3C error code for media error aborted.
146 * @member MediaError.MEDIA_ERR_ABORTED
152 * W3C error code for any network error.
154 * @member MediaError#MEDIA_ERR_NETWORK
159 * W3C error code for any network error.
161 * @member MediaError.MEDIA_ERR_NETWORK
167 * W3C error code for any decoding error.
169 * @member MediaError#MEDIA_ERR_DECODE
174 * W3C error code for any decoding error.
176 * @member MediaError.MEDIA_ERR_DECODE
182 * W3C error code for any time that a source is not supported.
184 * @member MediaError#MEDIA_ERR_SRC_NOT_SUPPORTED
189 * W3C error code for any time that a source is not supported.
191 * @member MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED
197 * W3C error code for any time that a source is encrypted.
199 * @member MediaError#MEDIA_ERR_ENCRYPTED
204 * W3C error code for any time that a source is encrypted.
206 * @member MediaError.MEDIA_ERR_ENCRYPTED
211 exports['default'] = MediaError;