Skip to content

Commit 27a24c0

Browse files
authored
Merge pull request #11 from kevinjpuscan/master
add audio and video controlls
2 parents afc8a63 + 9e0590c commit 27a24c0

File tree

4 files changed

+99
-10
lines changed

4 files changed

+99
-10
lines changed

src/components/Icons.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from 'react'
2+
export const ShareScreenIcon = () => (
3+
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0V0z"/><path fill="greenyellow" d="M20 18c1.1 0 1.99-.9 1.99-2L22 6c0-1.11-.9-2-2-2H4c-1.11 0-2 .89-2 2v10c0 1.1.89 2 2 2H0v2h24v-2h-4zm-7-3.53v-2.19c-2.78 0-4.61.85-6 2.72.56-2.67 2.11-5.33 6-5.87V7l4 3.73-4 3.74z"/></svg>
4+
);
5+
6+
export const MicOnIcon = () => (
7+
<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24"><path fill="greenyellow" d="M12 14c1.66 0 2.99-1.34 2.99-3L15 5c0-1.66-1.34-3-3-3S9 3.34 9 5v6c0 1.66 1.34 3 3 3zm5.3-3c0 3-2.54 5.1-5.3 5.1S6.7 14 6.7 11H5c0 3.41 2.72 6.23 6 6.72V21h2v-3.28c3.28-.48 6-3.3 6-6.72h-1.7z"/><path d="M0 0h24v24H0z" fill="none"/></svg>
8+
)
9+
10+
export const MicOffIcon = () => (
11+
<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24"><path d="M0 0h24v24H0zm0 0h24v24H0z" fill="none"/><path fill="greenyellow" d="M19 11h-1.7c0 .74-.16 1.43-.43 2.05l1.23 1.23c.56-.98.9-2.09.9-3.28zm-4.02.17c0-.06.02-.11.02-.17V5c0-1.66-1.34-3-3-3S9 3.34 9 5v.18l5.98 5.99zM4.27 3L3 4.27l6.01 6.01V11c0 1.66 1.33 3 2.99 3 .22 0 .44-.03.65-.08l1.66 1.66c-.71.33-1.5.52-2.31.52-2.76 0-5.3-2.1-5.3-5.1H5c0 3.41 2.72 6.23 6 6.72V21h2v-3.28c.91-.13 1.77-.45 2.54-.9L19.73 21 21 19.73 4.27 3z"/></svg>
12+
)
13+
14+
export const CamOnIcon = () => (
15+
<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24"><path d="M0 0h24v24H0z" fill="none"/><path fill="greenyellow" d="M17 10.5V7c0-.55-.45-1-1-1H4c-.55 0-1 .45-1 1v10c0 .55.45 1 1 1h12c.55 0 1-.45 1-1v-3.5l4 4v-11l-4 4z"/></svg>
16+
)
17+
18+
export const CamOffIcon = () => (
19+
<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24"><path d="M0 0h24v24H0zm0 0h24v24H0z" fill="none"/><path fill="greenyellow" d="M21 6.5l-4 4V7c0-.55-.45-1-1-1H9.82L21 17.18V6.5zM3.27 2L2 3.27 4.73 6H4c-.55 0-1 .45-1 1v10c0 .55.45 1 1 1h12c.21 0 .39-.08.54-.18L19.73 21 21 19.73 3.27 2z"/></svg>
20+
)

src/components/ShareScreenIcon.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/components/video.js

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import VideoCall from '../helpers/simple-peer';
33
import '../styles/video.css';
44
import io from 'socket.io-client';
55
import { getDisplayStream } from '../helpers/media-access';
6-
import ShareScreenIcon from './ShareScreenIcon';
6+
import {ShareScreenIcon,MicOnIcon,MicOffIcon,CamOnIcon,CamOffIcon} from './Icons';
7+
78
class Video extends React.Component {
89
constructor() {
910
super();
@@ -15,10 +16,13 @@ class Video extends React.Component {
1516
peer: {},
1617
full: false,
1718
connecting: false,
18-
waiting: true
19+
waiting: true,
20+
micState:true,
21+
camState:true,
1922
};
2023
}
2124
videoCall = new VideoCall();
25+
2226
componentDidMount() {
2327
const socket = io(process.env.REACT_APP_SIGNALING_SERVER);
2428
const component = this;
@@ -27,6 +31,7 @@ class Video extends React.Component {
2731
this.getUserMedia().then(() => {
2832
socket.emit('join', { roomId: roomId });
2933
});
34+
3035
socket.on('init', () => {
3136
component.setState({ initiator: true });
3237
});
@@ -45,6 +50,8 @@ class Video extends React.Component {
4550
component.setState({ full: true });
4651
});
4752
}
53+
54+
4855
getUserMedia(cb) {
4956
return new Promise((resolve, reject) => {
5057
navigator.getUserMedia = navigator.getUserMedia =
@@ -69,6 +76,29 @@ class Video extends React.Component {
6976
);
7077
});
7178
}
79+
80+
setAudioLocal(){
81+
if(this.state.localStream.getAudioTracks().length>0){
82+
this.state.localStream.getAudioTracks().forEach(track => {
83+
track.enabled=!track.enabled;
84+
});
85+
}
86+
this.setState({
87+
micState:!this.state.micState
88+
})
89+
}
90+
91+
setVideoLocal(){
92+
if(this.state.localStream.getVideoTracks().length>0){
93+
this.state.localStream.getVideoTracks().forEach(track => {
94+
track.enabled=!track.enabled;
95+
});
96+
}
97+
this.setState({
98+
camState:!this.state.camState
99+
})
100+
}
101+
72102
getDisplay() {
73103
getDisplayStream().then(stream => {
74104
stream.oninactive = () => {
@@ -82,6 +112,7 @@ class Video extends React.Component {
82112
this.state.peer.addStream(stream);
83113
});
84114
}
115+
85116
enter = roomId => {
86117
this.setState({ connecting: true });
87118
const peer = this.videoCall.init(
@@ -105,6 +136,7 @@ class Video extends React.Component {
105136
console.log(err);
106137
});
107138
};
139+
108140
call = otherId => {
109141
this.videoCall.connect(otherId);
110142
};
@@ -132,14 +164,51 @@ class Video extends React.Component {
132164
id='remoteVideo'
133165
ref={video => (this.remoteVideo = video)}
134166
/>
167+
168+
<div className='controls'>
135169
<button
136-
className='share-screen-btn'
170+
className='control-btn'
137171
onClick={() => {
138172
this.getDisplay();
139173
}}
140174
>
141175
<ShareScreenIcon />
142176
</button>
177+
178+
179+
<button
180+
className='control-btn'
181+
onClick={() => {
182+
this.setAudioLocal();
183+
}}
184+
>
185+
{
186+
this.state.micState?(
187+
<MicOnIcon></MicOnIcon>
188+
):(
189+
<MicOffIcon></MicOffIcon>
190+
)
191+
}
192+
</button>
193+
194+
<button
195+
className='control-btn'
196+
onClick={() => {
197+
this.setVideoLocal();
198+
}}
199+
>
200+
{
201+
this.state.camState?(
202+
<CamOnIcon></CamOnIcon>
203+
):(
204+
<CamOffIcon></CamOffIcon>
205+
)
206+
}
207+
</button>
208+
</div>
209+
210+
211+
143212
{this.state.connecting && (
144213
<div className='status'>
145214
<p>Establishing connection...</p>

src/styles/video.css

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,15 @@
3030
color: greenyellow;
3131
height: 100vh;
3232
}
33-
.share-screen-btn{
33+
34+
.controls{
3435
position: absolute;
3536
bottom: 24px;
3637
left: 24px;
38+
}
39+
.control-btn{
40+
position: relative;
41+
margin-right: 24px;
3742
background: transparent;
3843
outline: none;
3944
border: none;
@@ -43,6 +48,7 @@
4348
height: 64px;
4449
width: 64px;
4550
}
51+
4652
@media screen and (max-width: 480px) {
4753
.video-wrapper {
4854
position: relative;

0 commit comments

Comments
 (0)