Skip to content

Commit 919e222

Browse files
authored
Merge pull request #22 from umonaca/fix-background-audio-video
Fix background audio & video
2 parents ebefb4d + d133de0 commit 919e222

3 files changed

Lines changed: 2 additions & 39 deletions

File tree

app/javascript/mastodon/components/scrollable_list.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,10 @@ export default class ScrollableList extends PureComponent {
212212
}
213213

214214
attachIntersectionObserver () {
215-
let nodeOptions = {
215+
this.intersectionObserverWrapper.connect({
216216
root: this.node,
217217
rootMargin: '300% 0px',
218-
};
219-
220-
this.intersectionObserverWrapper
221-
.connect(this.props.bindToDocument ? {} : nodeOptions);
218+
});
222219
}
223220

224221
detachIntersectionObserver () {

app/javascript/mastodon/features/audio/index.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ class Audio extends React.PureComponent {
6060
if (this.waveform) {
6161
this._updateWaveform();
6262
}
63-
64-
window.addEventListener('scroll', this.handleScroll);
6563
}
6664

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

7371
componentWillUnmount () {
74-
window.removeEventListener('scroll', this.handleScroll);
75-
7672
if (this.wavesurfer) {
7773
this.wavesurfer.destroy();
7874
this.wavesurfer = null;
@@ -178,19 +174,6 @@ class Audio extends React.PureComponent {
178174
}
179175
}, 60);
180176

181-
handleScroll = throttle(() => {
182-
if (!this.waveform || !this.wavesurfer) {
183-
return;
184-
}
185-
186-
const { top, height } = this.waveform.getBoundingClientRect();
187-
const inView = (top <= (window.innerHeight || document.documentElement.clientHeight)) && (top + height >= 0);
188-
189-
if (!this.state.paused && !inView) {
190-
this.setState({ paused: true }, () => this.wavesurfer.pause());
191-
}
192-
}, 150, { trailing: true })
193-
194177
render () {
195178
const { height, intl, alt, editable } = this.props;
196179
const { paused, muted, volume, currentTime } = this.state;

app/javascript/mastodon/features/video/index.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -277,16 +277,12 @@ class Video extends React.PureComponent {
277277
document.addEventListener('mozfullscreenchange', this.handleFullscreenChange, true);
278278
document.addEventListener('MSFullscreenChange', this.handleFullscreenChange, true);
279279

280-
window.addEventListener('scroll', this.handleScroll);
281-
282280
if (this.props.blurhash) {
283281
this._decode();
284282
}
285283
}
286284

287285
componentWillUnmount () {
288-
window.removeEventListener('scroll', this.handleScroll);
289-
290286
document.removeEventListener('fullscreenchange', this.handleFullscreenChange, true);
291287
document.removeEventListener('webkitfullscreenchange', this.handleFullscreenChange, true);
292288
document.removeEventListener('mozfullscreenchange', this.handleFullscreenChange, true);
@@ -323,19 +319,6 @@ class Video extends React.PureComponent {
323319
}
324320
}
325321

326-
handleScroll = throttle(() => {
327-
if (!this.video) {
328-
return;
329-
}
330-
331-
const { top, height } = this.video.getBoundingClientRect();
332-
const inView = (top <= (window.innerHeight || document.documentElement.clientHeight)) && (top + height >= 0);
333-
334-
if (!this.state.paused && !inView) {
335-
this.setState({ paused: true }, () => this.video.pause());
336-
}
337-
}, 150, { trailing: true })
338-
339322
handleFullscreenChange = () => {
340323
this.setState({ fullscreen: isFullscreen() });
341324
}

0 commit comments

Comments
 (0)