Pause synced video if presenter exits the room

This commit is contained in:
Lucas Zawacki 2020-01-10 18:38:52 -03:00
parent 14fd979955
commit 4ade850a5a

View File

@ -74,21 +74,33 @@ class VideoPlayer extends Component {
this.resizeListener = () => { this.resizeListener = () => {
setTimeout(this.handleResize, 0); setTimeout(this.handleResize, 0);
}; };
this.onBeforeUnload = this.onBeforeUnload.bind(this);
} }
componentDidMount() { componentDidMount() {
window.addEventListener('resize', this.resizeListener); window.addEventListener('resize', this.resizeListener);
window.addEventListener('beforeunload', this.onBeforeUnload);
clearInterval(this.syncInterval); clearInterval(this.syncInterval);
this.registerVideoListeners(); this.registerVideoListeners();
} }
onBeforeUnload() {
const { isPresenter } = this.props;
if (isPresenter) {
sendMessage('stop');
}
}
componentWillUnmount() { componentWillUnmount() {
window.removeEventListener('resize', this.resizeListener); window.removeEventListener('resize', this.resizeListener);
window.removeEventListener('beforeunload', this.onBeforeUnload);
this.clearVideoListeners(); this.clearVideoListeners();
clearInterval(this.syncInterval); clearInterval(this.syncInterval);
clearTimeout(this.autoPlayTimeout); clearTimeout(this.autoPlayTimeout);
this.player = null; this.player = null;
} }