@@ -4,6 +4,8 @@ import "./styles.scss";
4
4
import { Button } from "antd" ;
5
5
import {
6
6
ApiOutlined ,
7
+ AudioMutedOutlined ,
8
+ AudioOutlined ,
7
9
PhoneOutlined ,
8
10
VideoCameraOutlined ,
9
11
} from "@ant-design/icons" ;
@@ -23,6 +25,7 @@ const VideoPanel = () => {
23
25
) ;
24
26
const [ userStream , setUserStream ] = useState < MediaStream | null > ( null ) ;
25
27
const [ videoOn , setVideoOn ] = useState < boolean > ( true ) ;
28
+ const [ muteOn , setMuteOn ] = useState < boolean > ( false ) ;
26
29
27
30
const handleCall = ( ) => {
28
31
navigator . mediaDevices
@@ -52,6 +55,17 @@ const VideoPanel = () => {
52
55
if ( sender ) {
53
56
sender . replaceTrack ( videoTrack ) ; // Replace the video track in the call
54
57
}
58
+
59
+ const audioTrack = userStream . getAudioTracks ( ) [ 0 ] ;
60
+
61
+ const sender2 = call . peerConnection . getSenders ( ) . find ( ( s ) => {
62
+ if ( s . track ) {
63
+ return s . track . kind === "audio" ;
64
+ }
65
+ } ) ;
66
+ if ( sender2 ) {
67
+ sender2 . replaceTrack ( audioTrack ) ; // Replace the video track in the call
68
+ }
55
69
}
56
70
}
57
71
}
@@ -104,7 +118,6 @@ const VideoPanel = () => {
104
118
105
119
const toggleVideo = ( ) => {
106
120
if ( userStream ) {
107
- console . log ( userStream . getVideoTracks ( ) ) ;
108
121
const videoTrack = userStream . getVideoTracks ( ) [ 0 ] ;
109
122
110
123
if ( videoTrack ) {
@@ -134,33 +147,102 @@ const VideoPanel = () => {
134
147
}
135
148
} ;
136
149
150
+ const toggleMute = ( ) => {
151
+ if ( userStream ) {
152
+ console . log ( userStream . getAudioTracks ( ) ) ;
153
+ const audioTrack = userStream . getAudioTracks ( ) [ 0 ] ;
154
+
155
+ if ( audioTrack ) {
156
+ if ( muteOn ) {
157
+ // Unmute the audio track
158
+ audioTrack . enabled = true ;
159
+ setMuteOn ( false ) ;
160
+ } else {
161
+ // Mute the audio track
162
+ audioTrack . enabled = false ;
163
+ setMuteOn ( true ) ;
164
+
165
+ if ( callInstance ) {
166
+ const sender = callInstance . peerConnection
167
+ . getSenders ( )
168
+ . find ( ( s ) => {
169
+ if ( s . track ) {
170
+ return s . track . kind === "audio" ;
171
+ }
172
+ } ) ;
173
+ if ( sender ) {
174
+ sender . replaceTrack ( audioTrack ) ; // Replace the video track in the call
175
+ }
176
+ }
177
+ }
178
+ }
179
+ }
180
+ } ;
181
+
137
182
return (
138
183
< div className = "video-panel" >
139
- < p className = "header-tag" > Video Feed for: { currentUsername } </ p >
184
+ { /* <p className="header-tag">Video Feed for: {currentUsername}</p> */ }
140
185
< video
141
186
className = "user-video"
142
187
playsInline
143
188
ref = { currentUserVideoRef }
144
189
autoPlay
145
- muted
146
190
/>
147
- < Button
148
- onClick = { toggleVideo }
149
- icon = { < VideoCameraOutlined /> }
150
- type = { videoOn ? "default" : "primary" }
151
- >
152
- { videoOn ? "Off Webcam" : "On Webcam" }
153
- </ Button >
154
- < Button onClick = { handleCall } icon = { < ApiOutlined /> } type = "primary" >
155
- Initiate Call
156
- </ Button >
157
- < p className = "header-tag" > Video Feed for: { matchedUsername } </ p >
191
+ < div className = "buttons-container" >
192
+ < Button
193
+ onClick = { toggleVideo }
194
+ icon = {
195
+ videoOn ? (
196
+ < div className = "icon-padding" >
197
+ < svg
198
+ xmlns = "http://www.w3.org/2000/svg"
199
+ width = "1.2em"
200
+ height = "1.2em"
201
+ viewBox = "0 0 32 32"
202
+ >
203
+ < path
204
+ fill = "currentColor"
205
+ d = "M21 26H4a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h17a2 2 0 0 1 2 2v4.06l5.42-3.87A1 1 0 0 1 30 9v14a1 1 0 0 1-1.58.81L23 19.94V24a2 2 0 0 1-2 2M4 8v16h17v-6a1 1 0 0 1 1.58-.81L28 21.06V10.94l-5.42 3.87A1 1 0 0 1 21 14V8Z"
206
+ > </ path >
207
+ </ svg >
208
+ </ div >
209
+ ) : (
210
+ < div className = "icon-padding" >
211
+ < svg
212
+ xmlns = "http://www.w3.org/2000/svg"
213
+ width = "1.2em"
214
+ height = "1.2em"
215
+ viewBox = "0 0 32 32"
216
+ >
217
+ < path
218
+ fill = "currentColor"
219
+ d = "M29.46 8.11a1 1 0 0 0-1 .08L23 12.06v-1.62l7-7L28.56 2L2 28.56L3.44 30l4-4H21a2 2 0 0 0 2-2v-4.06l5.42 3.87A1 1 0 0 0 30 23V9a1 1 0 0 0-.54-.89M28 21.06l-5.42-3.87A1 1 0 0 0 21 18v6H9.44L21 12.44V14a1 1 0 0 0 1.58.81L28 10.94zM4 24V8h16V6H4a2 2 0 0 0-2 2v16z"
220
+ > </ path >
221
+ </ svg >
222
+ </ div >
223
+ )
224
+ }
225
+ type = { videoOn ? "default" : "primary" }
226
+ >
227
+ { videoOn ? "Off Cam" : "On Cam" }
228
+ </ Button >
229
+ < Button
230
+ onClick = { toggleMute }
231
+ type = { ! muteOn ? "default" : "primary" }
232
+ icon = { muteOn ? < AudioMutedOutlined /> : < AudioOutlined /> }
233
+ >
234
+ { muteOn ? "On Mic" : "Off Mic" }
235
+ </ Button >
236
+ < Button onClick = { handleCall } icon = { < ApiOutlined /> } type = "primary" >
237
+ Call
238
+ </ Button >
239
+ </ div >
240
+ { /* <p className="header-tag">Video Feed for: {matchedUsername}</p> */ }
158
241
< video
159
242
className = "matched-user-video"
160
243
playsInline
161
244
ref = { remoteVideoRef }
162
245
autoPlay
163
- muted
164
246
/>
165
247
</ div >
166
248
) ;
0 commit comments