Merge branch 'feature-lastn' of https://github.com/havfo/multiparty-meeting into feature-lastn

master
Stefan Otto 2018-10-30 08:49:21 +01:00
commit aa0918af28
6 changed files with 75 additions and 10 deletions

View File

@ -673,6 +673,16 @@ export default class RoomClient
stateActions.setWebcamInProgress(false)); stateActions.setWebcamInProgress(false));
} }
setSelectedPeer(peerName)
{
logger.debug('setSelectedPeer() [peerName:"%s"]', peerName);
this._spotlights.setPeerSpotlight(peerName);
this._dispatch(
stateActions.setSelectedPeer(peerName));
}
async mutePeerAudio(peerName) async mutePeerAudio(peerName)
{ {
logger.debug('mutePeerAudio() [peerName:"%s"]', peerName); logger.debug('mutePeerAudio() [peerName:"%s"]', peerName);

View File

@ -12,6 +12,7 @@ export default class Spotlights extends EventEmitter
this._room = room; this._room = room;
this._maxSpotlights = maxSpotlights; this._maxSpotlights = maxSpotlights;
this._peerList = []; this._peerList = [];
this._selectedSpotlights = [];
this._currentSpotlights = []; this._currentSpotlights = [];
this._started = false; this._started = false;
} }
@ -43,6 +44,25 @@ export default class Spotlights extends EventEmitter
} }
} }
setPeerSpotlight(peerName)
{
logger.debug('setPeerSpotlight() [peerName:"%s"]', peerName);
const index = this._selectedSpotlights.indexOf(peerName);
if (index === -1) // We don't have this peer in the list, adding
{
this._selectedSpotlights.push(peerName);
}
else // We have this peer, remove
{
this._selectedSpotlights.splice(index, 1);
}
if (this._started)
this._spotlightsUpdated();
}
_handleRoom() _handleRoom()
{ {
this._room.on('newpeer', (peer) => this._room.on('newpeer', (peer) =>
@ -69,14 +89,21 @@ export default class Spotlights extends EventEmitter
{ {
peer.on('close', () => peer.on('close', () =>
{ {
const index = this._peerList.indexOf(peer.name); let index = this._peerList.indexOf(peer.name);
if (index > -1) // We have this peer in the list, remove if (index !== -1) // We have this peer in the list, remove
{ {
this._peerList.splice(index, 1); this._peerList.splice(index, 1);
}
index = this._selectedSpotlights.indexOf(peer.name);
if (index !== -1) // We have this peer in the list, remove
{
this._selectedSpotlights.splice(index, 1);
}
this._spotlightsUpdated(); this._spotlightsUpdated();
}
}); });
logger.debug('_handlePeer() | adding peer [peerName:"%s"]', peer.name); logger.debug('_handlePeer() | adding peer [peerName:"%s"]', peer.name);
@ -104,15 +131,26 @@ export default class Spotlights extends EventEmitter
_spotlightsUpdated() _spotlightsUpdated()
{ {
let spotlights;
if (this._selectedSpotlights.length > 0)
{
spotlights = [ ...new Set([ ...this._selectedSpotlights, ...this._peerList ]) ];
}
else
{
spotlights = this._peerList;
}
if ( if (
!this._arraysEqual( !this._arraysEqual(
this._currentSpotlights, this._peerList.slice(0, this._maxSpotlights) this._currentSpotlights, spotlights.slice(0, this._maxSpotlights)
) )
) )
{ {
logger.debug('_spotlightsUpdated() | spotlights updated, emitting'); logger.debug('_spotlightsUpdated() | spotlights updated, emitting');
this._currentSpotlights = this._peerList.slice(0, this._maxSpotlights); this._currentSpotlights = spotlights.slice(0, this._maxSpotlights);
this.emit('spotlights-updated', this._currentSpotlights); this.emit('spotlights-updated', this._currentSpotlights);
} }
else else

View File

@ -4,7 +4,7 @@ import ResizeObserver from 'resize-observer-polyfill';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import debounce from 'lodash/debounce'; import debounce from 'lodash/debounce';
import classnames from 'classnames'; import classnames from 'classnames';
import * as stateActions from '../redux/stateActions'; import * as requestActions from '../redux/requestActions';
import Peer from './Peer'; import Peer from './Peer';
import HiddenPeers from './HiddenPeers'; import HiddenPeers from './HiddenPeers';
@ -206,7 +206,7 @@ const mapStateToProps = (state) =>
}; };
const mapDispatchToProps = { const mapDispatchToProps = {
setSelectedPeer : stateActions.setSelectedPeer setSelectedPeer : requestActions.setSelectedPeer
}; };
export default connect( export default connect(

View File

@ -2,7 +2,7 @@ import React from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
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 * as requestActions from '../../redux/requestActions';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import ListPeer from './ListPeer'; import ListPeer from './ListPeer';
import ListMe from './ListMe'; import ListMe from './ListMe';
@ -46,7 +46,7 @@ const mapStateToProps = (state) =>
}; };
const mapDispatchToProps = { const mapDispatchToProps = {
setSelectedPeer : stateActions.setSelectedPeer setSelectedPeer : requestActions.setSelectedPeer
}; };
const ParticipantListContainer = connect( const ParticipantListContainer = connect(

View File

@ -221,6 +221,14 @@ export const sendFile = (file, name, picture) =>
}; };
}; };
export const setSelectedPeer = (selectedPeerName) =>
{
return {
type : 'REQUEST_SELECTED_PEER',
payload : { selectedPeerName }
};
};
// This returns a redux-thunk action (a function). // This returns a redux-thunk action (a function).
export const notify = ({ type = 'info', text, timeout }) => export const notify = ({ type = 'info', text, timeout }) =>
{ {

View File

@ -237,6 +237,15 @@ export default ({ dispatch, getState }) => (next) =>
client.sendFile(action.payload); client.sendFile(action.payload);
break; break;
} }
case 'REQUEST_SELECTED_PEER':
{
const { selectedPeerName } = action.payload;
client.setSelectedPeer(selectedPeerName);
break;
}
} }
return next(action); return next(action);