From 67832f5e732112b300b0ea47c074fe4e6c8875f4 Mon Sep 17 00:00:00 2001 From: mgabdev <> Date: Wed, 10 Jun 2020 23:29:33 -0400 Subject: [PATCH] Updated Video component x3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Updated: - Video component x3 for buffering • Added: - SensitiveMediaItem for Video if sensitive is true --- app/javascript/gabsocial/components/video.js | 126 ++++++++----------- 1 file changed, 54 insertions(+), 72 deletions(-) diff --git a/app/javascript/gabsocial/components/video.js b/app/javascript/gabsocial/components/video.js index 7cff006e..b251b2b6 100644 --- a/app/javascript/gabsocial/components/video.js +++ b/app/javascript/gabsocial/components/video.js @@ -18,6 +18,7 @@ import { import Responsive from '../features/ui/util/responsive_component' import Button from './button' import Icon from './icon' +import SensitiveMediaItem from './sensitive_media_item' import Text from './text' // check every 50 ms for buffer @@ -35,6 +36,7 @@ const messages = defineMessages({ sensitive: { id: 'status.sensitive_warning', defaultMessage: 'Sensitive content' }, hidden: { id: 'status.media_hidden', defaultMessage: 'Media hidden' }, video_stats: { id: 'video.stats_label', defaultMessage: 'Video meta stats' }, + toggle_visible: { id: 'media_gallery.toggle_visible', defaultMessage: 'Hide media' }, }) const formatTime = (secondsNum) => { @@ -168,10 +170,6 @@ class Video extends ImmutablePureComponent { document.addEventListener('mozfullscreenchange', this.handleFullscreenChange, true) document.addEventListener('MSFullscreenChange', this.handleFullscreenChange, true) - if (blurhash) { - this._decode() - } - if (meta) { this.setState({ duration: parseInt(meta.get('duration')) }) } @@ -200,28 +198,25 @@ class Video extends ImmutablePureComponent { if (prevState.revealed && !this.state.revealed && this.video) { this.video.pause() } - if (prevProps.blurhash !== this.props.blurhash && this.props.blurhash) { - this._decode() - } } checkBuffering = () => { - const { isBuffering, paused, currentTime } = this.state + const { isBuffering, paused } = this.state + if (!this.video) { + this.handlePause() + return + } + const { currentTime } = this.video - // checking offset should be at most the check interval - // but allow for some margin + // Checking offset should be at most the check interval but allow for some margin let offset = checkInterval / 1000 - // if no buffering is currently detected, - // and the position does not seem to increase - // and the player isn't manually paused... if (!isBuffering && currentTime < (this.lastPlayPos + offset) && !paused) { + // If no buffering is currently detected, and the position does not seem to increase + // and the player isn't manually paused... this.setState({ isBuffering: true }) - } - - // if we were buffering but the player has advanced, - // then there is no buffering - if (isBuffering && currentTime > (this.lastPlayPos + offset) && !paused) { + } else if (isBuffering && currentTime > (this.lastPlayPos + offset) && !paused) { + // If we were buffering but the player has advanced, then there is no buffering this.setState({ isBuffering: false }) } @@ -264,10 +259,6 @@ class Video extends ImmutablePureComponent { this.volume = n } - setCanvasRef = (n) => { - this.canvas = n - } - setSettingsBtnRef = (n) => { this.settingsBtn = n } @@ -405,18 +396,6 @@ class Video extends ImmutablePureComponent { } } - _decode() { - const hash = this.props.blurhash - const pixels = decode(hash, 32, 32) - - if (pixels && this.canvas) { - const ctx = this.canvas.getContext('2d') - const imageData = new ImageData(pixels, 32, 32) - - ctx.putImageData(imageData, 0, 0) - } - } - handleFullscreenChange = () => { this.setState({ fullscreen: isFullscreen() }) } @@ -500,7 +479,7 @@ class Video extends ImmutablePureComponent { alt, detailed, sensitive, - aspectRatio + aspectRatio, } = this.props const { @@ -637,6 +616,10 @@ class Video extends ImmutablePureComponent { displayNone: !paused, }) + if (!revealed && sensitive) { + return + } + return (
- { - !revealed && - - } -
{ paused && !isBuffering && @@ -676,32 +649,29 @@ class Video extends ImmutablePureComponent { }
- { - revealed && -
+ + { + revealed && sensitive && +
+
+ } ) } - }