Skip to content

Commit

Permalink
Merge pull request #22 from umonaca/fix-background-audio-video
Browse files Browse the repository at this point in the history
Fix background audio & video
  • Loading branch information
doubanius authored May 14, 2020
2 parents ebefb4d + d133de0 commit 919e222
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 39 deletions.
7 changes: 2 additions & 5 deletions app/javascript/mastodon/components/scrollable_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,10 @@ export default class ScrollableList extends PureComponent {
}

attachIntersectionObserver () {
let nodeOptions = {
this.intersectionObserverWrapper.connect({
root: this.node,
rootMargin: '300% 0px',
};

this.intersectionObserverWrapper
.connect(this.props.bindToDocument ? {} : nodeOptions);
});
}

detachIntersectionObserver () {
Expand Down
17 changes: 0 additions & 17 deletions app/javascript/mastodon/features/audio/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ class Audio extends React.PureComponent {
if (this.waveform) {
this._updateWaveform();
}

window.addEventListener('scroll', this.handleScroll);
}

componentDidUpdate (prevProps) {
Expand All @@ -71,8 +69,6 @@ class Audio extends React.PureComponent {
}

componentWillUnmount () {
window.removeEventListener('scroll', this.handleScroll);

if (this.wavesurfer) {
this.wavesurfer.destroy();
this.wavesurfer = null;
Expand Down Expand Up @@ -178,19 +174,6 @@ class Audio extends React.PureComponent {
}
}, 60);

handleScroll = throttle(() => {
if (!this.waveform || !this.wavesurfer) {
return;
}

const { top, height } = this.waveform.getBoundingClientRect();
const inView = (top <= (window.innerHeight || document.documentElement.clientHeight)) && (top + height >= 0);

if (!this.state.paused && !inView) {
this.setState({ paused: true }, () => this.wavesurfer.pause());
}
}, 150, { trailing: true })

render () {
const { height, intl, alt, editable } = this.props;
const { paused, muted, volume, currentTime } = this.state;
Expand Down
17 changes: 0 additions & 17 deletions app/javascript/mastodon/features/video/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,16 +277,12 @@ class Video extends React.PureComponent {
document.addEventListener('mozfullscreenchange', this.handleFullscreenChange, true);
document.addEventListener('MSFullscreenChange', this.handleFullscreenChange, true);

window.addEventListener('scroll', this.handleScroll);

if (this.props.blurhash) {
this._decode();
}
}

componentWillUnmount () {
window.removeEventListener('scroll', this.handleScroll);

document.removeEventListener('fullscreenchange', this.handleFullscreenChange, true);
document.removeEventListener('webkitfullscreenchange', this.handleFullscreenChange, true);
document.removeEventListener('mozfullscreenchange', this.handleFullscreenChange, true);
Expand Down Expand Up @@ -323,19 +319,6 @@ class Video extends React.PureComponent {
}
}

handleScroll = throttle(() => {
if (!this.video) {
return;
}

const { top, height } = this.video.getBoundingClientRect();
const inView = (top <= (window.innerHeight || document.documentElement.clientHeight)) && (top + height >= 0);

if (!this.state.paused && !inView) {
this.setState({ paused: true }, () => this.video.pause());
}
}, 150, { trailing: true })

handleFullscreenChange = () => {
this.setState({ fullscreen: isFullscreen() });
}
Expand Down

0 comments on commit 919e222

Please sign in to comment.