Merge branch 'develop' into screensharing

master
Håvar Aambø Fosstveit 2018-04-10 14:40:58 +02:00
commit b661aa1923
6 changed files with 138 additions and 29 deletions

View File

@ -3,13 +3,85 @@ import { connect } from 'react-redux';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import classnames from 'classnames'; import classnames from 'classnames';
import * as appPropTypes from './appPropTypes'; import * as appPropTypes from './appPropTypes';
import * as stateActions from '../redux/stateActions';
import { Appear } from './transitions'; import { Appear } from './transitions';
import Peer from './Peer'; import Peer from './Peer';
const Peers = ({ peers, activeSpeakerName }) => class Peers extends React.Component
{ {
constructor()
{
super();
this.state = {
ratio : 4 / 3
};
}
updateDimensions()
{
const n = this.props.peers.length;
if (n == 0)
{
return;
}
const width = this.refs.peers.clientWidth;
const height = this.refs.peers.clientHeight;
let x, y, space;
for (let rows = 1; rows < 100; rows = rows + 1)
{
x = width / Math.ceil(n / rows);
y = x / this.state.ratio;
if (height < (y * rows))
{
y = height / rows;
x = this.state.ratio * y;
break;
}
space = height - (y * (rows));
if (space < y)
{
break;
}
}
if (Math.ceil(this.props.peerWidth) !== Math.ceil(0.9 * x))
{
this.props.onComponentResize(0.9 * x, 0.9 * y);
}
}
componentDidMount()
{
window.addEventListener('resize', this.updateDimensions.bind(this));
}
componentWillUnmount()
{
window.removeEventListener('resize', this.updateDimensions.bind(this));
}
render()
{
const {
activeSpeakerName,
peers,
peerWidth,
peerHeight
} = this.props;
const style =
{
'width' : peerWidth,
'height' : peerHeight
};
this.updateDimensions();
return ( return (
<div data-component='Peers'> <div data-component='Peers' ref='peers'>
{ {
peers.map((peer) => peers.map((peer) =>
{ {
@ -18,7 +90,7 @@ const Peers = ({ peers, activeSpeakerName }) =>
<div <div
className={classnames('peer-container', { className={classnames('peer-container', {
'active-speaker' : peer.name === activeSpeakerName 'active-speaker' : peer.name === activeSpeakerName
})} })} style={style}
> >
<Peer name={peer.name} /> <Peer name={peer.name} />
</div> </div>
@ -28,12 +100,26 @@ const Peers = ({ peers, activeSpeakerName }) =>
} }
</div> </div>
); );
}; }
}
Peers.propTypes = Peers.propTypes =
{ {
peers : PropTypes.arrayOf(appPropTypes.Peer).isRequired, peers : PropTypes.arrayOf(appPropTypes.Peer).isRequired,
activeSpeakerName : PropTypes.string activeSpeakerName : PropTypes.string,
peerHeight : PropTypes.number,
peerWidth : PropTypes.number,
onComponentResize : PropTypes.func.isRequired
};
const mapDispatchToProps = (dispatch) =>
{
return {
onComponentResize : (peerWidth, peerHeight) =>
{
dispatch(stateActions.onComponentResize(peerWidth, peerHeight));
}
};
}; };
const mapStateToProps = (state) => const mapStateToProps = (state) =>
@ -44,10 +130,15 @@ const mapStateToProps = (state) =>
return { return {
peers : peersArray, peers : peersArray,
activeSpeakerName : state.room.activeSpeakerName activeSpeakerName : state.room.activeSpeakerName,
peerHeight : state.room.peerHeight,
peerWidth : state.room.peerWidth
}; };
}; };
const PeersContainer = connect(mapStateToProps)(Peers); const PeersContainer = connect(
mapStateToProps,
mapDispatchToProps
)(Peers);
export default PeersContainer; export default PeersContainer;

View File

@ -2,6 +2,8 @@
```js ```js
{ {
peerWidth : 200,
peerHeight : 150,
room : room :
{ {
url : 'https://example.io/?&roomId=d0el8y34', url : 'https://example.io/?&roomId=d0el8y34',

View File

@ -2,7 +2,9 @@ const initialState =
{ {
url : null, url : null,
state : 'new', // new/connecting/connected/disconnected/closed, state : 'new', // new/connecting/connected/disconnected/closed,
activeSpeakerName : null activeSpeakerName : null,
peerHeight : 300,
peerWidth : 400
}; };
const room = (state = initialState, action) => const room = (state = initialState, action) =>
@ -33,6 +35,13 @@ const room = (state = initialState, action) =>
return { ...state, activeSpeakerName: peerName }; return { ...state, activeSpeakerName: peerName };
} }
case 'SET_COMPONENT_SIZE':
{
const { peerWidth, peerHeight } = action.payload;
return { ...state, peerWidth: peerWidth, peerHeight: peerHeight };
}
default: default:
return state; return state;
} }

View File

@ -22,6 +22,14 @@ export const setRoomActiveSpeaker = (peerName) =>
}; };
}; };
export const onComponentResize = (peerWidth, peerHeight) =>
{
return {
type : 'SET_COMPONENT_SIZE',
payload : { peerWidth, peerHeight }
};
};
export const setMe = ({ peerName, displayName, displayNameSet, device }) => export const setMe = ({ peerName, displayName, displayNameSet, device }) =>
{ {
return { return {

View File

@ -1,10 +1,11 @@
[data-component='Peers'] { [data-component='Peers'] {
min-height: 100%; min-height: 100%;
width: 100%; width: 100%;
height: 100%;
+desktop() { +desktop() {
width: 100%; width: 100%;
padding: 40px 0 140px 0; padding: 0px 0 0px 0;
display: flex; display: flex;
flex-direction: row; flex-direction: row;
flex-wrap: wrap; flex-wrap: wrap;
@ -29,8 +30,6 @@
+desktop() { +desktop() {
flex: 0 0 auto; flex: 0 0 auto;
height: 382px;
width: 450px;
margin: 6px; margin: 6px;
border: 1px solid rgba(#fff, 0.15); border: 1px solid rgba(#fff, 0.15);
box-shadow: 0px 5px 12px 2px rgba(#111, 0.5); box-shadow: 0px 5px 12px 2px rgba(#111, 0.5);

View File

@ -48,7 +48,7 @@ body {
#multiparty-meeting-media-query-detector { #multiparty-meeting-media-query-detector {
position: relative; position: relative;
z-index: -1000; z-index: -1000;
bottom: 0; bottom: 1px;
left: 0; left: 0;
height: 1px; height: 1px;
width: 1px; width: 1px;