Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / node_modules / video.js / es5 / media-error.js
1 'use strict';
2
3 exports.__esModule = true;
4
5 var _obj = require('./utils/obj');
6
7 /**
8  * A Custom `MediaError` class which mimics the standard HTML5 `MediaError` class.
9  *
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.
18  *
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}
21  *
22  * @class MediaError
23  */
24 function MediaError(value) {
25
26   // Allow redundant calls to this constructor to avoid having `instanceof`
27   // checks peppered around the code.
28   if (value instanceof MediaError) {
29     return value;
30   }
31
32   if (typeof value === 'number') {
33     this.code = value;
34   } else if (typeof value === 'string') {
35     // default code is zero, so this is a custom error
36     this.message = value;
37   } else if ((0, _obj.isObject)(value)) {
38
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;
43     }
44
45     (0, _obj.assign)(this, value);
46   }
47
48   if (!this.message) {
49     this.message = MediaError.defaultMessages[this.code] || '';
50   }
51 }
52
53 /**
54  * The error code that refers two one of the defined `MediaError` types
55  *
56  * @type {Number}
57  */
58 /**
59  * @file media-error.js
60  */
61 MediaError.prototype.code = 0;
62
63 /**
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.
66  *
67  * @type {String}
68  */
69 MediaError.prototype.message = '';
70
71 /**
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.
77  *
78  * @type {Array}
79  */
80 MediaError.prototype.status = null;
81
82 /**
83  * Errors indexed by the W3C standard. The order **CANNOT CHANGE**! See the
84  * specification listed under {@link MediaError} for more information.
85  *
86  * @enum {array}
87  * @readonly
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
94  */
95 MediaError.errorTypes = ['MEDIA_ERR_CUSTOM', 'MEDIA_ERR_ABORTED', 'MEDIA_ERR_NETWORK', 'MEDIA_ERR_DECODE', 'MEDIA_ERR_SRC_NOT_SUPPORTED', 'MEDIA_ERR_ENCRYPTED'];
96
97 /**
98  * The default `MediaError` messages based on the {@link MediaError.errorTypes}.
99  *
100  * @type {Array}
101  * @constant
102  */
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.'
109 };
110
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;
117 }
118
119 // jsdocs for instance/static members added above
120 // instance methods use `#` and static methods use `.`
121 /**
122  * W3C error code for any custom error.
123  *
124  * @member MediaError#MEDIA_ERR_CUSTOM
125  * @constant {number}
126  * @default 0
127  */
128 /**
129  * W3C error code for any custom error.
130  *
131  * @member MediaError.MEDIA_ERR_CUSTOM
132  * @constant {number}
133  * @default 0
134  */
135
136 /**
137  * W3C error code for media error aborted.
138  *
139  * @member MediaError#MEDIA_ERR_ABORTED
140  * @constant {number}
141  * @default 1
142  */
143 /**
144  * W3C error code for media error aborted.
145  *
146  * @member MediaError.MEDIA_ERR_ABORTED
147  * @constant {number}
148  * @default 1
149  */
150
151 /**
152  * W3C error code for any network error.
153  *
154  * @member MediaError#MEDIA_ERR_NETWORK
155  * @constant {number}
156  * @default 2
157  */
158 /**
159  * W3C error code for any network error.
160  *
161  * @member MediaError.MEDIA_ERR_NETWORK
162  * @constant {number}
163  * @default 2
164  */
165
166 /**
167  * W3C error code for any decoding error.
168  *
169  * @member MediaError#MEDIA_ERR_DECODE
170  * @constant {number}
171  * @default 3
172  */
173 /**
174  * W3C error code for any decoding error.
175  *
176  * @member MediaError.MEDIA_ERR_DECODE
177  * @constant {number}
178  * @default 3
179  */
180
181 /**
182  * W3C error code for any time that a source is not supported.
183  *
184  * @member MediaError#MEDIA_ERR_SRC_NOT_SUPPORTED
185  * @constant {number}
186  * @default 4
187  */
188 /**
189  * W3C error code for any time that a source is not supported.
190  *
191  * @member MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED
192  * @constant {number}
193  * @default 4
194  */
195
196 /**
197  * W3C error code for any time that a source is encrypted.
198  *
199  * @member MediaError#MEDIA_ERR_ENCRYPTED
200  * @constant {number}
201  * @default 5
202  */
203 /**
204  * W3C error code for any time that a source is encrypted.
205  *
206  * @member MediaError.MEDIA_ERR_ENCRYPTED
207  * @constant {number}
208  * @default 5
209  */
210
211 exports['default'] = MediaError;