Mirror local video (#57)

* Flip local video horizontally
This commit is contained in:
Ben Ringold 2019-04-08 19:20:55 -07:00 committed by Jerko Steiner
parent 1db22e9b5c
commit c542d71ad0
4 changed files with 28 additions and 8 deletions

View File

@ -75,6 +75,7 @@ export default class App extends React.PureComponent {
stream={streams[constants.ME]} stream={streams[constants.ME]}
userId={constants.ME} userId={constants.ME}
muted muted
mirrored
/> />
{_.map(peers, (_, userId) => ( {_.map(peers, (_, userId) => (

View File

@ -16,10 +16,12 @@ export default class Video extends React.PureComponent {
active: PropTypes.bool.isRequired, active: PropTypes.bool.isRequired,
stream: StreamPropType, stream: StreamPropType,
userId: PropTypes.string.isRequired, userId: PropTypes.string.isRequired,
muted: PropTypes.bool.isRequired muted: PropTypes.bool.isRequired,
mirrored: PropTypes.bool
} }
static defaultProps = { static defaultProps = {
muted: false muted: false,
mirrored: false
} }
handleClick = e => { handleClick = e => {
const { onClick, userId } = this.props const { onClick, userId } = this.props
@ -48,8 +50,8 @@ export default class Video extends React.PureComponent {
videos[socket.id] = video videos[socket.id] = video
} }
render () { render () {
const { active, muted } = this.props const { active, mirrored, muted } = this.props
const className = classnames('video-container', { active }) const className = classnames('video-container', { active, mirrored })
return ( return (
<div className={className}> <div className={className}>
<video <video

View File

@ -1,5 +1,6 @@
jest.mock('../../window.js') jest.mock('../../window.js')
import React from 'react' import React from 'react'
import ReactDOM from 'react-dom'
import TestUtils from 'react-dom/test-utils' import TestUtils from 'react-dom/test-utils'
import Video from '../Video.js' import Video from '../Video.js'
import { MediaStream } from '../../window.js' import { MediaStream } from '../../window.js'
@ -19,30 +20,40 @@ describe('components/Video', () => {
stream={this.state.stream || this.props.stream} stream={this.state.stream || this.props.stream}
onClick={this.props.onClick} onClick={this.props.onClick}
userId="test" userId="test"
muted={this.props.muted}
mirrored={this.props.mirrored}
/> />
} }
} }
let component, videos, video, onClick, mediaStream, url let component, videos, video, onClick, mediaStream, url, wrapper
function render () { function render (flags = {}) {
videos = {} videos = {}
onClick = jest.fn() onClick = jest.fn()
mediaStream = new MediaStream() mediaStream = new MediaStream()
component = TestUtils.renderIntoDocument( component = TestUtils.renderIntoDocument(
<VideoWrapper <VideoWrapper
videos={videos} videos={videos}
active active={flags.active || false}
stream={{ mediaStream, url }} stream={{ mediaStream, url }}
onClick={onClick} onClick={onClick}
userId="test" userId="test"
muted={flags.muted || false}
mirrored={flags.mirrored}
/> />
) )
wrapper = ReactDOM.findDOMNode(component)
video = TestUtils.findRenderedComponentWithType(component, Video) video = TestUtils.findRenderedComponentWithType(component, Video)
} }
describe('render', () => { describe('render', () => {
it('should not fail', () => { it('should not fail', () => {
render() render({})
})
it('Mirrored and active propogate to rendered classes', () => {
render({ active: true, mirrored: true })
expect(wrapper.className).toBe('video-container active mirrored')
}) })
}) })

View File

@ -43,4 +43,10 @@
cursor: inherit; cursor: inherit;
} }
} }
.video-container.mirrored video {
transform: rotateY(180deg);
-webkit-transform:rotateY(180deg);
-moz-transform:rotateY(180deg);
}
} }