11import React , { Component , PropTypes } from 'react' ;
2+ import cloudinary from 'cloudinary-core' ;
3+ import CloudinaryComponent from '../CloudinaryComponent' ;
4+ const Util = cloudinary . Util ;
5+ const Cloudinary = cloudinary . Cloudinary ;
6+ const DEFAULT_POSTER_OPTIONS = {
7+ format : 'jpg' ,
8+ resource_type : 'video'
9+ } ;
210
3- export default class Video extends React . Component {
11+ export default class Video extends CloudinaryComponent {
412 constructor ( props ) {
513 super ( props ) ;
614 this . state = { } ;
@@ -29,11 +37,42 @@ export default class Video extends React.Component {
2937 }
3038
3139 render ( ) {
40+ let { publicId, poster, sourceTypes, fallback, sourceTransformation, ...options } = Object . assign ( { } , this . context , this . props ) ;
41+ sourceTransformation = sourceTransformation || { } ;
42+ sourceTypes = sourceTypes || Cloudinary . DEFAULT_VIDEO_PARAMS . source_types ;
43+ options = this . getOptions ( options , { } ) ;
44+ let cld = Cloudinary . new ( options ) ;
45+ let sources = [ ] ;
46+ let tagAttributes = cloudinary . Transformation . new ( options ) . toHtmlAttributes ( ) ;
47+ if ( Util . isPlainObject ( poster ) ) {
48+ let defaults = poster . publicId != null ? Cloudinary . DEFAULT_IMAGE_PARAMS : DEFAULT_POSTER_OPTIONS ;
49+ poster = cld . url ( poster . publicId || publicId , Util . defaults ( { } , poster , defaults ) ) ;
50+ }
51+ if ( ! Util . isEmpty ( poster ) ) {
52+ tagAttributes [ "poster" ] = poster ;
53+ }
54+
55+ if ( Util . isArray ( sourceTypes ) ) {
56+ sources = sourceTypes . map ( srcType => {
57+ let transformation = sourceTransformation [ srcType ] || { } ;
58+ let src = cld . url ( publicId , Util . defaults ( { } , transformation , { resource_type : 'video' , format : srcType } ) ) ;
59+ let mimeType = 'video/' + ( srcType == 'ogv' ? 'ogg' : srcType ) ;
60+ return < source key = { mimeType } src = { src } type = { mimeType } /> ;
61+ }
62+ ) ;
63+ } else {
64+ tagAttributes [ "src" ] = cld . url ( publicId , { resource_type : 'video' , format : sourceTypes } ) ;
65+ }
66+ console . log ( "Ready to return tag" , tagAttributes ) ;
3267 return (
33- < div > Video Not Implemented yet.< video > </ video > </ div >
68+ < video { ...tagAttributes } >
69+ { sources }
70+ { fallback }
71+ { this . props . children }
72+ </ video >
3473 ) ;
3574 }
3675}
37- Video . propTypes = { initialCount : React . PropTypes . number } ;
38- Video . defaultProps = { initialCount : 0 } ;
39- Video . contextTypes = { } ;
76+ Video . propTypes = { publicId : PropTypes . string } ;
77+ // Video.defaultProps = {initialCount: 0};
78+ Video . contextTypes = CloudinaryComponent . contextTypes ;
0 commit comments