Force Filmstrip video to take as much space as possible
parent
e49cdcf88e
commit
e4f29b298b
|
|
@ -1,15 +1,92 @@
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
import ResizeObserver from 'resize-observer-polyfill';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import classnames from 'classnames';
|
import classnames from 'classnames';
|
||||||
import Peer from './Peer';
|
import Peer from './Peer';
|
||||||
|
|
||||||
class Filmstrip extends Component
|
class Filmstrip extends Component
|
||||||
{
|
{
|
||||||
|
constructor(props)
|
||||||
|
{
|
||||||
|
super(props);
|
||||||
|
|
||||||
|
this.activePeerContainer = React.createRef();
|
||||||
|
}
|
||||||
|
|
||||||
state = {
|
state = {
|
||||||
selectedPeerName : null
|
selectedPeerName : null,
|
||||||
|
width : 400
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Find the name of the peer which is currently speaking. This is either
|
||||||
|
// the latest active speaker, or the manually selected peer.
|
||||||
|
getActivePeerName = () =>
|
||||||
|
this.state.selectedPeerName || this.props.activeSpeakerName;
|
||||||
|
|
||||||
|
isSharingCamera = (peerName) => this.props.peers[peerName] &&
|
||||||
|
this.props.peers[peerName].consumers.some((consumer) =>
|
||||||
|
this.props.consumers[consumer].source === 'screen');
|
||||||
|
|
||||||
|
getRatio = () =>
|
||||||
|
{
|
||||||
|
let ratio = 4 / 3;
|
||||||
|
|
||||||
|
if (this.isSharingCamera(this.getActivePeerName()))
|
||||||
|
{
|
||||||
|
ratio *= 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ratio;
|
||||||
|
};
|
||||||
|
|
||||||
|
updateDimensions = () =>
|
||||||
|
{
|
||||||
|
const container = this.activePeerContainer.current;
|
||||||
|
|
||||||
|
if (container)
|
||||||
|
{
|
||||||
|
const ratio = this.getRatio();
|
||||||
|
|
||||||
|
let width = container.clientWidth;
|
||||||
|
|
||||||
|
if (width / ratio > container.clientHeight)
|
||||||
|
{
|
||||||
|
width = container.clientHeight * ratio;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
width
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
componentDidMount()
|
||||||
|
{
|
||||||
|
this.updateDimensions();
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidMount()
|
||||||
|
{
|
||||||
|
window.addEventListener('resize', this.updateDimensions);
|
||||||
|
const observer = new ResizeObserver(this.updateDimensions);
|
||||||
|
|
||||||
|
observer.observe(this.activePeerContainer.current);
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount()
|
||||||
|
{
|
||||||
|
window.removeEventListener('resize', this.updateDimensions);
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidUpdate(prevProps)
|
||||||
|
{
|
||||||
|
if (prevProps !== this.props)
|
||||||
|
{
|
||||||
|
this.updateDimensions();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
handleSelectPeer = (selectedPeerName) =>
|
handleSelectPeer = (selectedPeerName) =>
|
||||||
{
|
{
|
||||||
this.setState((oldState) => ({
|
this.setState((oldState) => ({
|
||||||
|
|
@ -22,22 +99,26 @@ class Filmstrip extends Component
|
||||||
{
|
{
|
||||||
const { activeSpeakerName, peers, advancedMode } = this.props;
|
const { activeSpeakerName, peers, advancedMode } = this.props;
|
||||||
|
|
||||||
// Find the name of the peer which is currently speaking. This is either
|
const activePeerName = this.getActivePeerName();
|
||||||
// the latest active speaker, or the manually selected peer.
|
|
||||||
const activePeerName = this.state.selectedPeerName || activeSpeakerName;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div data-component='Filmstrip'>
|
<div data-component='Filmstrip'>
|
||||||
|
<div className='active-peer-container' ref={this.activePeerContainer}>
|
||||||
{peers[activePeerName] && (
|
{peers[activePeerName] && (
|
||||||
<div className='active-peer'>
|
<div
|
||||||
|
className='active-peer'
|
||||||
|
style={{ width: this.state.width, height: this.state.width / this.getRatio() }}
|
||||||
|
>
|
||||||
<Peer
|
<Peer
|
||||||
advancedMode={advancedMode}
|
advancedMode={advancedMode}
|
||||||
name={activePeerName}
|
name={activePeerName}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className='filmstrip'>
|
<div className='filmstrip'>
|
||||||
|
<div className='filmstrip-content'>
|
||||||
{Object.keys(peers).map((peerName) => (
|
{Object.keys(peers).map((peerName) => (
|
||||||
<div
|
<div
|
||||||
key={peerName}
|
key={peerName}
|
||||||
|
|
@ -57,6 +138,7 @@ class Filmstrip extends Component
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -64,13 +146,15 @@ class Filmstrip extends Component
|
||||||
Filmstrip.propTypes = {
|
Filmstrip.propTypes = {
|
||||||
activeSpeakerName : PropTypes.string,
|
activeSpeakerName : PropTypes.string,
|
||||||
advancedMode : PropTypes.bool,
|
advancedMode : PropTypes.bool,
|
||||||
peers : PropTypes.object.isRequired
|
peers : PropTypes.object.isRequired,
|
||||||
|
consumers : PropTypes.object.isRequired
|
||||||
};
|
};
|
||||||
|
|
||||||
const mapStateToProps = (state) =>
|
const mapStateToProps = (state) =>
|
||||||
({
|
({
|
||||||
activeSpeakerName : state.room.activeSpeakerName,
|
activeSpeakerName : state.room.activeSpeakerName,
|
||||||
peers : state.peers
|
peers : state.peers,
|
||||||
|
consumers : state.consumers
|
||||||
});
|
});
|
||||||
|
|
||||||
export default connect(
|
export default connect(
|
||||||
|
|
|
||||||
|
|
@ -4,31 +4,38 @@
|
||||||
align-items: center;
|
align-items: center;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
|
||||||
|
> .active-peer-container {
|
||||||
|
width: 100%;
|
||||||
|
height: 80vh;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
|
||||||
> .active-peer {
|
> .active-peer {
|
||||||
width: 95vmin;
|
width: 100%;
|
||||||
padding: 10vmin 1vmin 1vmin 1vmin;
|
padding: 5vmin 1vmin 1vmin 1vmin;
|
||||||
|
|
||||||
> [data-component='Peer'] {
|
> [data-component='Peer'] {
|
||||||
border: 5px solid rgba(255, 255, 255, 0.15);
|
border: 5px solid rgba(255, 255, 255, 0.15);
|
||||||
box-shadow: 0px 5px 12px 2px rgba(17, 17, 17, 0.5);
|
box-shadow: 0px 5px 12px 2px rgba(17, 17, 17, 0.5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
> .filmstrip {
|
> .filmstrip {
|
||||||
display: flex;
|
display: flex;
|
||||||
background: rgba(0, 0, 0 , 0.5);
|
background: rgba(0, 0, 0 , 0.5);
|
||||||
width: 100%;
|
width: 100%;
|
||||||
overflow-x: auto;
|
overflow-x: auto;
|
||||||
padding: 1vmin 0;
|
height: 20vh;
|
||||||
margin-top: auto;
|
align-items: center;
|
||||||
|
|
||||||
> .film {
|
> .film {
|
||||||
height: 15vmin;
|
height: 18vh;
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
padding-left: 1vmin;
|
padding-left: 1vh;
|
||||||
|
|
||||||
&:last-child {
|
&:last-child {
|
||||||
padding-right: 1vmin;
|
padding-right: 1vh;
|
||||||
}
|
}
|
||||||
|
|
||||||
> .film-content {
|
> .film-content {
|
||||||
|
|
@ -37,11 +44,11 @@
|
||||||
border: 1px solid rgba(255,255,255,0.15);
|
border: 1px solid rgba(255,255,255,0.15);
|
||||||
|
|
||||||
> [data-component='Peer'] {
|
> [data-component='Peer'] {
|
||||||
max-width: 15vmin * (4 / 3);
|
max-width: 17vh * (4 / 3);
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
|
||||||
&.screen {
|
&.screen {
|
||||||
max-width: 15vmin * (2 * 4 / 3);
|
max-width: 17vh * (2 * 4 / 3);
|
||||||
border: 0;
|
border: 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue