@@ -3,7 +3,8 @@ import VideoCall from '../helpers/simple-peer';
3
3
import '../styles/video.css' ;
4
4
import io from 'socket.io-client' ;
5
5
import { getDisplayStream } from '../helpers/media-access' ;
6
- import ShareScreenIcon from './ShareScreenIcon' ;
6
+ import { ShareScreenIcon , MicOnIcon , MicOffIcon , CamOnIcon , CamOffIcon } from './Icons' ;
7
+
7
8
class Video extends React . Component {
8
9
constructor ( ) {
9
10
super ( ) ;
@@ -15,10 +16,13 @@ class Video extends React.Component {
15
16
peer : { } ,
16
17
full : false ,
17
18
connecting : false ,
18
- waiting : true
19
+ waiting : true ,
20
+ micState :true ,
21
+ camState :true ,
19
22
} ;
20
23
}
21
24
videoCall = new VideoCall ( ) ;
25
+
22
26
componentDidMount ( ) {
23
27
const socket = io ( process . env . REACT_APP_SIGNALING_SERVER ) ;
24
28
const component = this ;
@@ -27,6 +31,7 @@ class Video extends React.Component {
27
31
this . getUserMedia ( ) . then ( ( ) => {
28
32
socket . emit ( 'join' , { roomId : roomId } ) ;
29
33
} ) ;
34
+
30
35
socket . on ( 'init' , ( ) => {
31
36
component . setState ( { initiator : true } ) ;
32
37
} ) ;
@@ -45,6 +50,8 @@ class Video extends React.Component {
45
50
component . setState ( { full : true } ) ;
46
51
} ) ;
47
52
}
53
+
54
+
48
55
getUserMedia ( cb ) {
49
56
return new Promise ( ( resolve , reject ) => {
50
57
navigator . getUserMedia = navigator . getUserMedia =
@@ -69,6 +76,29 @@ class Video extends React.Component {
69
76
) ;
70
77
} ) ;
71
78
}
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
+
72
102
getDisplay ( ) {
73
103
getDisplayStream ( ) . then ( stream => {
74
104
stream . oninactive = ( ) => {
@@ -82,6 +112,7 @@ class Video extends React.Component {
82
112
this . state . peer . addStream ( stream ) ;
83
113
} ) ;
84
114
}
115
+
85
116
enter = roomId => {
86
117
this . setState ( { connecting : true } ) ;
87
118
const peer = this . videoCall . init (
@@ -105,6 +136,7 @@ class Video extends React.Component {
105
136
console . log ( err ) ;
106
137
} ) ;
107
138
} ;
139
+
108
140
call = otherId => {
109
141
this . videoCall . connect ( otherId ) ;
110
142
} ;
@@ -132,14 +164,51 @@ class Video extends React.Component {
132
164
id = 'remoteVideo'
133
165
ref = { video => ( this . remoteVideo = video ) }
134
166
/>
167
+
168
+ < div className = 'controls' >
135
169
< button
136
- className = 'share-screen -btn'
170
+ className = 'control -btn'
137
171
onClick = { ( ) => {
138
172
this . getDisplay ( ) ;
139
173
} }
140
174
>
141
175
< ShareScreenIcon />
142
176
</ 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
+
143
212
{ this . state . connecting && (
144
213
< div className = 'status' >
145
214
< p > Establishing connection...</ p >
0 commit comments