|
1 | | -import { sliceAndUnsetProperties } from 'utils/slicing'; |
2 | 1 | import { objectToQuerystring } from 'utils/querystring'; |
3 | 2 | import castArray from 'lodash/castArray'; |
4 | 3 | import { SOURCE_TYPE } from 'utils/consts'; |
| 4 | +import { SOURCE_PARAMS } from 'video-player.const'; |
5 | 5 | import { |
6 | 6 | CONTAINER_MIME_TYPES, |
7 | 7 | ADAPTIVE_SOURCETYPES, |
@@ -37,58 +37,21 @@ class VideoSource extends BaseSource { |
37 | 37 | options.poster = Object.assign({ publicId }, DEFAULT_POSTER_PARAMS); |
38 | 38 | } |
39 | 39 |
|
40 | | - const { |
41 | | - poster, |
42 | | - sourceTypes, |
43 | | - sourceTransformation, |
44 | | - info, |
45 | | - recommendations, |
46 | | - textTracks, |
47 | | - withCredentials, |
48 | | - interactionAreas, |
49 | | - chapters, |
50 | | - visualSearch |
51 | | - } = sliceAndUnsetProperties( |
52 | | - options, |
53 | | - 'poster', |
54 | | - 'sourceTypes', |
55 | | - 'sourceTransformation', |
56 | | - 'info', |
57 | | - 'recommendations', |
58 | | - 'textTracks', |
59 | | - 'withCredentials', |
60 | | - 'interactionAreas', |
61 | | - 'chapters', |
62 | | - 'visualSearch' |
63 | | - ); |
64 | | - |
65 | 40 | super(publicId, options); |
66 | 41 |
|
67 | | - this._sourceTypes = null; |
68 | | - this._recommendations = null; |
69 | | - this._textTracks = null; |
70 | | - this._poster = null; |
71 | | - this._info = null; |
72 | | - this._sourceTransformation = null; |
73 | | - this._interactionAreas = null; |
74 | | - this._chapters = null; |
75 | | - this._visualSearch = null; |
76 | 42 | this._type = SOURCE_TYPE.VIDEO; |
77 | 43 | this.isRawUrl = _isRawUrl; |
78 | 44 | this.isLiveStream = options.type === 'live'; |
79 | | - this._rawTransformation = options.raw_transformation; |
80 | | - this.withCredentials = !!withCredentials; |
| 45 | + this.withCredentials = !!options.withCredentials; |
81 | 46 | this.getInitOptions = () => initOptions; |
82 | 47 |
|
83 | | - this.poster(poster, { type: options.type }); |
84 | | - this.sourceTypes(sourceTypes); |
85 | | - this.sourceTransformation(sourceTransformation); |
86 | | - this.info(info); |
87 | | - this.interactionAreas(interactionAreas); |
88 | | - this.chapters(chapters); |
89 | | - this.visualSearch(visualSearch); |
90 | | - this.recommendations(recommendations); |
91 | | - this.textTracks(textTracks); |
| 48 | + // Set extracted parameters using their respective methods |
| 49 | + SOURCE_PARAMS.forEach(param => { |
| 50 | + if (options[param] !== undefined && this[param]) { |
| 51 | + this[param](options[param]); |
| 52 | + } |
| 53 | + }); |
| 54 | + |
92 | 55 | this.objectId = generateId(); |
93 | 56 | } |
94 | 57 |
|
@@ -171,7 +134,9 @@ class VideoSource extends BaseSource { |
171 | 134 | return this; |
172 | 135 | } |
173 | 136 |
|
174 | | - poster(publicId, options = {}) { |
| 137 | + poster(publicId) { |
| 138 | + let options = { type: this.getInitOptions().type }; |
| 139 | + |
175 | 140 | if (!publicId) { |
176 | 141 | return this._poster; |
177 | 142 | } |
@@ -228,7 +193,7 @@ class VideoSource extends BaseSource { |
228 | 193 | const [type, codecTrans] = formatToMimeTypeAndTransformation(sourceType); |
229 | 194 |
|
230 | 195 | // If user's transformation include video_codec then don't add another video codec to transformation |
231 | | - if (codecTrans && !(hasCodec(opts.transformation) || hasCodec(this._rawTransformation))) { |
| 196 | + if (codecTrans && !(hasCodec(opts.transformation) || hasCodec(this.raw_transformation()))) { |
232 | 197 | opts.transformation = mergeTransformations(opts.transformation, codecTrans); |
233 | 198 | } |
234 | 199 |
|
@@ -284,6 +249,96 @@ class VideoSource extends BaseSource { |
284 | 249 | getInteractionAreas() { |
285 | 250 | return this._interactionAreas; |
286 | 251 | } |
| 252 | + |
| 253 | + // Methods for additional SOURCE_PARAMS |
| 254 | + adaptiveStreaming(value) { |
| 255 | + if (value === undefined) { |
| 256 | + return this._adaptiveStreaming; |
| 257 | + } |
| 258 | + this._adaptiveStreaming = value; |
| 259 | + return this; |
| 260 | + } |
| 261 | + |
| 262 | + allowUsageReport(value) { |
| 263 | + if (value === undefined) { |
| 264 | + return this._allowUsageReport; |
| 265 | + } |
| 266 | + this._allowUsageReport = value; |
| 267 | + return this; |
| 268 | + } |
| 269 | + |
| 270 | + autoShowRecommendations(value) { |
| 271 | + if (value === undefined) { |
| 272 | + return this._autoShowRecommendations; |
| 273 | + } |
| 274 | + this._autoShowRecommendations = value; |
| 275 | + return this; |
| 276 | + } |
| 277 | + |
| 278 | + queryParams(params) { |
| 279 | + if (params === undefined) { |
| 280 | + return this._queryParams; |
| 281 | + } |
| 282 | + this._queryParams = params; |
| 283 | + return this; |
| 284 | + } |
| 285 | + |
| 286 | + raw_transformation(value) { |
| 287 | + if (value === undefined) { |
| 288 | + return this._raw_transformation; |
| 289 | + } |
| 290 | + this._raw_transformation = value; |
| 291 | + return this; |
| 292 | + } |
| 293 | + |
| 294 | + shoppable(value) { |
| 295 | + if (value === undefined) { |
| 296 | + return this._shoppable; |
| 297 | + } |
| 298 | + this._shoppable = value; |
| 299 | + return this; |
| 300 | + } |
| 301 | + |
| 302 | + // Additional setter methods for remaining SOURCE_PARAMS |
| 303 | + source(value) { |
| 304 | + if (value === undefined) { |
| 305 | + return this._source; |
| 306 | + } |
| 307 | + this._source = value; |
| 308 | + return this; |
| 309 | + } |
| 310 | + |
| 311 | + transformation(value) { |
| 312 | + if (value === undefined) { |
| 313 | + return this._transformation; |
| 314 | + } |
| 315 | + this._transformation = value; |
| 316 | + return this; |
| 317 | + } |
| 318 | + |
| 319 | + cloudinaryConfig(value) { |
| 320 | + if (value === undefined) { |
| 321 | + return this._cloudinaryConfig; |
| 322 | + } |
| 323 | + this._cloudinaryConfig = value; |
| 324 | + return this; |
| 325 | + } |
| 326 | + |
| 327 | + type(value) { |
| 328 | + if (value === undefined) { |
| 329 | + return this._typeValue; |
| 330 | + } |
| 331 | + this._typeValue = value; |
| 332 | + return this; |
| 333 | + } |
| 334 | + |
| 335 | + posterOptions(value) { |
| 336 | + if (value === undefined) { |
| 337 | + return this._posterOptions; |
| 338 | + } |
| 339 | + this._posterOptions = value; |
| 340 | + return this; |
| 341 | + } |
287 | 342 | } |
288 | 343 |
|
289 | 344 | export default VideoSource; |
0 commit comments