|
| 1 | +import React, { Component } from 'react'; |
| 2 | + |
| 3 | +import './VideoMessage.css'; |
| 4 | + |
| 5 | +import FaCloudDownload from 'react-icons/lib/fa/cloud-download'; |
| 6 | +import FaError from 'react-icons/lib/fa/exclamation-triangle'; |
| 7 | + |
| 8 | +import classNames from 'classnames'; |
| 9 | + |
| 10 | +const ProgressBar = require('react-progress-bar.js'); |
| 11 | +const Circle = ProgressBar.Circle; |
| 12 | + |
| 13 | +export class VideoMessage extends Component { |
| 14 | + render() { |
| 15 | + var progressOptions = { |
| 16 | + strokeWidth: 2.3, |
| 17 | + color: '#efe', |
| 18 | + trailColor: '#aaa', |
| 19 | + trailWidth: 1, |
| 20 | + step: (state, circle) => { |
| 21 | + circle.path.setAttribute('trail', state.color); |
| 22 | + circle.path.setAttribute('trailwidth-width', state.width); |
| 23 | + |
| 24 | + var value = Math.round(circle.value() * 100); |
| 25 | + if (value === 0) |
| 26 | + circle.setText(''); |
| 27 | + else |
| 28 | + circle.setText(value); |
| 29 | + } |
| 30 | + }; |
| 31 | + |
| 32 | + const error = this.props.data.status && this.props.data.status.error === true; |
| 33 | + const downloaded = this.props.data.status && this.props.data.status.download; |
| 34 | + |
| 35 | + return ( |
| 36 | + <div |
| 37 | + className={classNames('rce-mbox-video', { |
| 38 | + 'padding-time': !this.props.text, |
| 39 | + })}> |
| 40 | + <div |
| 41 | + className='rce-mbox-video--video' |
| 42 | + style={this.props.data.width && this.props.data.height && { |
| 43 | + width: this.props.data.width, |
| 44 | + height: this.props.data.height, |
| 45 | + }}> |
| 46 | + |
| 47 | + { |
| 48 | + !downloaded && |
| 49 | + <img |
| 50 | + src={this.props.data.uri} |
| 51 | + alt={this.props.data.alt} |
| 52 | + onClick={this.props.onOpen} |
| 53 | + onLoad={this.props.onLoad} |
| 54 | + onError={this.props.onPhotoError}/> |
| 55 | + } |
| 56 | + |
| 57 | + { |
| 58 | + downloaded && |
| 59 | + <video controls> |
| 60 | + <source src={this.props.data.videoURL} type='video/mp4'/> |
| 61 | + Your browser does not support HTML video. |
| 62 | + </video> |
| 63 | + } |
| 64 | + |
| 65 | + { |
| 66 | + error && |
| 67 | + <div className='rce-mbox-video--video__block'> |
| 68 | + <span |
| 69 | + className='rce-mbox-video--video__block-item rce-mbox-video--error'> |
| 70 | + <FaError/> |
| 71 | + </span> |
| 72 | + </div> |
| 73 | + } |
| 74 | + { |
| 75 | + !error && |
| 76 | + this.props.data.status && |
| 77 | + !downloaded && |
| 78 | + <div className='rce-mbox-video--video__block'> |
| 79 | + { |
| 80 | + !this.props.data.status.click && |
| 81 | + <button |
| 82 | + onClick={this.props.onDownload} |
| 83 | + className='rce-mbox-video--video__block-item rce-mbox-video--download'> |
| 84 | + <FaCloudDownload/> |
| 85 | + </button> |
| 86 | + } |
| 87 | + { |
| 88 | + typeof this.props.data.status.loading === 'number' && |
| 89 | + this.props.data.status.loading !== 0 && |
| 90 | + <Circle |
| 91 | + progress={this.props.data.status.loading} |
| 92 | + options={progressOptions} |
| 93 | + initialAnimate={true} |
| 94 | + containerClassName={'rce-mbox-video--video__block-item'} /> |
| 95 | + } |
| 96 | + </div> |
| 97 | + } |
| 98 | + </div> |
| 99 | + { |
| 100 | + this.props.text && |
| 101 | + <div className='rce-mbox-text'> |
| 102 | + {this.props.text} |
| 103 | + </div> |
| 104 | + } |
| 105 | + </div> |
| 106 | + ); |
| 107 | + } |
| 108 | +} |
| 109 | + |
| 110 | +VideoMessage.defaultProps = { |
| 111 | + text: '', |
| 112 | + data: {}, |
| 113 | + onDownload: null, |
| 114 | + onOpen: null, |
| 115 | + onLoad: null, |
| 116 | + onPhotoError: null, |
| 117 | +}; |
| 118 | + |
| 119 | + |
| 120 | +export default VideoMessage; |
0 commit comments