import React from 'react'; import SendMessage from './send-message.jsx'; export default class VideoPreview extends React.PureComponent { constructor(props) { super(props); this.videoRef = React.createRef(); this.handleSendVideo = this.handleSendVideo.bind(this); } handleSendVideo(caption) { this.props.onClose(); const params = { width: this.videoRef.current.videoWidth, height: this.videoRef.current.videoHeight, duration: (this.videoRef.current.duration * 1000) | 0, mime: this.props.content.mime, name: this.props.content.name } // Capture screen from a video. const canvas = document.createElement('canvas'); canvas.width = params.width; canvas.height = params.height; const ctx = canvas.getContext('2d'); ctx.drawImage(this.videoRef.current, 0, 0, canvas.width, canvas.height); ctx.canvas.toBlob( preview => this.props.onSendMessage(caption, this.props.content.blob, preview, params), 'image/jpeg', 0.75 ); } render() { if (!this.props.content) { return null; } return (
{this.props.content.name} {e.preventDefault(); this.props.onClose();}}>close
); } };