From 1250396ba74358c377744cce725c2def930c2a5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5var=20Aamb=C3=B8=20Fosstveit?= Date: Fri, 13 Apr 2018 09:54:59 +0200 Subject: [PATCH 1/4] Fixed bug in screen sharing, and added support for showing cam video at the same time as screen sharing --- app/lib/components/Peer.jsx | 77 +++++------ app/lib/components/PeerScreenView.jsx | 160 ---------------------- app/lib/components/PeerView.jsx | 124 +++++++++++++---- app/stylus/components/PeerScreenView.styl | 146 -------------------- app/stylus/components/PeerView.styl | 38 ++++- app/stylus/index.styl | 1 - 6 files changed, 159 insertions(+), 387 deletions(-) delete mode 100644 app/lib/components/PeerScreenView.jsx delete mode 100644 app/stylus/components/PeerScreenView.styl diff --git a/app/lib/components/Peer.jsx b/app/lib/components/Peer.jsx index 66536eb..09c4fa2 100644 --- a/app/lib/components/Peer.jsx +++ b/app/lib/components/Peer.jsx @@ -2,7 +2,6 @@ import React from 'react'; import { connect } from 'react-redux'; import * as appPropTypes from './appPropTypes'; import PeerView from './PeerView'; -import PeerScreenView from './PeerScreenView'; const Peer = (props) => { @@ -41,53 +40,41 @@ const Peer = (props) => if (screenConsumer) screenProfile = screenConsumer.profile; - if (screenVisible && screenConsumer.supported) - { - return ( -
- -
- ); - } - else - { - return ( -
-
- {!micEnabled ? -
- :null - } - {!videoVisible ? -
- :null - } -
- - {videoVisible && !webcamConsumer.supported ? -
-

incompatible video

-
+ return ( +
+
+ {!micEnabled ? +
+ :null + } + {!videoVisible ? +
:null } - -
- ); - } + + {videoVisible && !webcamConsumer.supported ? +
+

incompatible video

+
+ :null + } + + +
+ ); }; Peer.propTypes = diff --git a/app/lib/components/PeerScreenView.jsx b/app/lib/components/PeerScreenView.jsx deleted file mode 100644 index 62672aa..0000000 --- a/app/lib/components/PeerScreenView.jsx +++ /dev/null @@ -1,160 +0,0 @@ -import React from 'react'; -import PropTypes from 'prop-types'; -import classnames from 'classnames'; -import Spinner from 'react-spinner'; - -export default class PeerScreenView extends React.Component -{ - constructor(props) - { - super(props); - - this.state = - { - videoWidth : null, - videoHeight : null - }; - - // Latest received video track. - // @type {MediaStreamTrack} - this._videoTrack = null; - - // Periodic timer for showing video resolution. - this._videoResolutionTimer = null; - } - - render() - { - const { - isMe, - videoVisible, - videoProfile, - videoCodec - } = this.props; - - const { - videoWidth, - videoHeight - } = this.state; - - return ( -
-
-
-
- {videoCodec ? -

{videoCodec} {videoProfile}

- :null - } - - {(videoVisible && videoWidth !== null) ? -

{videoWidth}x{videoHeight}

- :null - } -
-
-
- -
- ); - } - - componentDidMount() - { - const { videoTrack } = this.props; - - this._setTracks(videoTrack); - } - - componentWillUnmount() - { - clearInterval(this._videoResolutionTimer); - } - - componentWillReceiveProps(nextProps) - { - const { videoTrack } = nextProps; - - this._setTracks(videoTrack); - } - - _setTracks(videoTrack) - { - if (this._videoTrack === videoTrack) - return; - - this._videoTrack = videoTrack; - - clearInterval(this._videoResolutionTimer); - this._hideVideoResolution(); - - const { video } = this.refs; - - if (videoTrack) - { - const stream = new MediaStream; - - if (videoTrack) - stream.addTrack(videoTrack); - - video.srcObject = stream; - - if (videoTrack) - this._showVideoResolution(); - } - else - { - video.srcObject = null; - } - } - - _showVideoResolution() - { - this._videoResolutionTimer = setInterval(() => - { - const { videoWidth, videoHeight } = this.state; - const { video } = this.refs; - - // Don't re-render if nothing changed. - if (video.videoWidth === videoWidth && video.videoHeight === videoHeight) - return; - - this.setState( - { - videoWidth : video.videoWidth, - videoHeight : video.videoHeight - }); - }, 1000); - } - - _hideVideoResolution() - { - this.setState({ videoWidth: null, videoHeight: null }); - } -} - -PeerScreenView.propTypes = -{ - isMe : PropTypes.bool, - videoTrack : PropTypes.any, - videoVisible : PropTypes.bool.isRequired, - videoProfile : PropTypes.string, - videoCodec : PropTypes.string -}; diff --git a/app/lib/components/PeerView.jsx b/app/lib/components/PeerView.jsx index 840badd..e4f4572 100644 --- a/app/lib/components/PeerView.jsx +++ b/app/lib/components/PeerView.jsx @@ -14,9 +14,11 @@ export default class PeerView extends React.Component this.state = { - volume : 0, // Integer from 0 to 10., - videoWidth : null, - videoHeight : null + volume : 0, // Integer from 0 to 10., + videoWidth : null, + videoHeight : null, + screenWidth : null, + screenHeight : null }; // Latest received video track. @@ -27,6 +29,10 @@ export default class PeerView extends React.Component // @type {MediaStreamTrack} this._videoTrack = null; + // Latest received screen track. + // @type {MediaStreamTrack} + this._screenTrack = null; + // Hark instance. // @type {Object} this._hark = null; @@ -42,37 +48,60 @@ export default class PeerView extends React.Component peer, videoVisible, videoProfile, + screenVisible, + screenProfile, audioCodec, videoCodec, + screenCodec, onChangeDisplayName } = this.props; const { volume, videoWidth, - videoHeight + videoHeight, + screenWidth, + screenHeight } = this.state; return (
-
- {audioCodec ? -

{audioCodec}

- :null - } + {screenVisible ? +
+ {audioCodec ? +

{audioCodec}

+ :null + } - {videoCodec ? -

{videoCodec} {videoProfile}

- :null - } + {screenCodec ? +

{screenCodec} {screenProfile}

+ :null + } - {(videoVisible && videoWidth !== null) ? -

{videoWidth}x{videoHeight}

- :null - } -
+ {(screenVisible && screenWidth !== null) ? +

{screenWidth}x{screenHeight}

+ :null + } +
+ :
+ {audioCodec ? +

{audioCodec}

+ :null + } + + {videoCodec ? +

{videoCodec} {videoProfile}

+ :null + } + + {(videoVisible && videoWidth !== null) ? +

{videoWidth}x{videoHeight}

+ :null + } +
+ }
@@ -111,19 +140,35 @@ export default class PeerView extends React.Component