Skip to content

Commit 0ce6446

Browse files
committed
Updates for video view
1 parent 23a2255 commit 0ce6446

File tree

3 files changed

+41
-36
lines changed

3 files changed

+41
-36
lines changed

src/components/Chat/VideoView.js

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,43 +9,25 @@ export class VideoView extends React.Component {
99
static propTypes = {
1010
ready: T.bool,
1111
remote: T.bool,
12+
stream: T.object,
1213
peer: T.object
1314
}
1415

1516
componentDidMount() {
16-
if (this.props.ready) {
17-
this.attachVideo();
17+
if (this.props.ready && this.props.stream) {
18+
this.attachVideo(this.props.stream);
1819
}
1920
}
2021

2122
componentWillReceiveProps(nextProps) {
22-
if (nextProps.ready !== this.props.ready || nextProps.peer !== this.props.peer) {
23-
this.attachVideo();
23+
if (nextProps.ready && nextProps.stream) {
24+
this.attachVideo(nextProps.stream);
2425
}
2526
}
2627

27-
attachVideo() {
28-
console.log('attachVideo ->', this.props);
29-
this.props.remote ? this.attachRemoteVideo() : this.attachLocalVideo()
30-
}
31-
32-
attachRemoteVideo() {
33-
const {peer} = this.props;
34-
let node = ReactDOM.findDOMNode(this.refs.videoView);
35-
attachMediaStream(peer.stream, node);
36-
}
37-
38-
attachLocalVideo() {
39-
const {rtc} = this.props;
40-
28+
attachVideo(stream) {
4129
let node = ReactDOM.findDOMNode(this.refs.videoView);
42-
rtc.webrtc.startLocalMedia(rtc.config.media, function (err, stream) {
43-
if (err) {
44-
rtc.emit('localMediaError', err);
45-
} else {
46-
attachMediaStream(stream, node, rtc.config.localVideo);
47-
}
48-
});
30+
attachMediaStream(stream, node);
4931
}
5032

5133
render() {

src/views/main/indexPage/Page.js

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ export class Index extends React.Component {
1212
this.state = {
1313
ready: false,
1414
id: null,
15-
peers: [],
15+
localVideo: {
16+
stream: null,
17+
config: null
18+
},
1619
messages: []
1720
}
1821
}
@@ -23,11 +26,26 @@ export class Index extends React.Component {
2326
}
2427

2528
componentWillReceiveProps(nextProps) {
26-
if (nextProps.ready !== this.props.ready) {
27-
this.props.actions.webrtc.joinRoom('fullstackio')
29+
if (nextProps.ready && !this.props.ready) {
30+
this.startLocalMedia();
2831
}
2932
}
3033

34+
startLocalMedia() {
35+
const {webrtc, actions} = this.props;
36+
actions.webrtc.joinRoom('fullstackio');
37+
webrtc.webrtc
38+
.startLocalMedia(webrtc.webrtc.config.media, (err, stream) => {
39+
if (err) {
40+
webrtc.emit('localMediaError', err);
41+
} else {
42+
this.setState({
43+
localStream: stream
44+
});
45+
}
46+
});
47+
}
48+
3149
goToAbout(evt) {
3250
const {router} = this.context;
3351
const {actions} = this.props;
@@ -36,7 +54,9 @@ export class Index extends React.Component {
3654
}
3755

3856
render() {
39-
const {ready, peers, rtc} = this.props;
57+
const {ready, peers, webrtc} = this.props;
58+
const {localStream} = this.state;
59+
4060
return (
4161
<div className={styles.container}>
4262
<div className={styles.header}>
@@ -48,8 +68,9 @@ export class Index extends React.Component {
4868
<div className={styles.videoContainer}>
4969

5070
<div className={styles.main}>
51-
<VideoView remote={false}
52-
ready={ready} rtc={rtc} />
71+
<VideoView key={'mine'}
72+
ready={ready}
73+
stream={localStream} />
5374
</div>
5475

5576
<div className={styles.peers}>
@@ -59,10 +80,12 @@ export class Index extends React.Component {
5980
</div>
6081
<div className={styles.people}>
6182
{peers.map(peer => {
83+
console.log('peer id ', peer.id, this.props.id);
6284
return (
6385
<div className={styles.person}>
6486
<VideoView key={peer.id}
65-
remote={true} peer={peer} ready={ready} rtc={rtc}></VideoView>
87+
ready={ready}
88+
stream={peer.stream} />
6689
</div>
6790
)
6891
})}
@@ -91,8 +114,8 @@ Index.contextTypes = {
91114
}
92115

93116
export default connect(state => ({
94-
webrtc: state.webrtc,
117+
webrtc: state.webrtc.webrtc,
118+
id: state.webrtc.id,
95119
ready: state.webrtc.ready,
96120
peers: state.webrtc.peers,
97-
rtc: state.webrtc.webrtc
98121
}))(Index);

src/views/main/styles.module.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020

2121
.content {
2222
position: relative;
23-
/*top: var(--topbar-height);*/
23+
top: var(--topbar-height);
2424
left: 0;
2525

2626
flex: 1;
2727
order: 1;
2828

2929
.padding {
30-
/*padding: var(--padding);*/
30+
padding: var(--padding);
3131
}
3232

3333
@media (--screen-phone-lg) {

0 commit comments

Comments
 (0)