@@ -20,6 +20,14 @@ export default function App() {
20
20
const outVidRef = useRef < HTMLVideoElement | null > ( null ) ;
21
21
const incVidRef = useRef < HTMLVideoElement | null > ( null ) ;
22
22
23
+ const disableVideoCompletelyRef = useRef < boolean | null > ( null ) ;
24
+ if ( disableVideoCompletelyRef . current == null ) {
25
+ disableVideoCompletelyRef . current = location . search . includes (
26
+ "disableVideoCompletely" ,
27
+ ) ;
28
+ }
29
+ const disableVideoCompletely = disableVideoCompletelyRef . current ;
30
+
23
31
const enableVideoInitiallyRef = useRef < boolean | null > ( null ) ;
24
32
if ( enableVideoInitiallyRef . current == null ) {
25
33
enableVideoInitiallyRef . current = ! location . search . includes (
@@ -29,8 +37,9 @@ export default function App() {
29
37
const enableVideoInitially = enableVideoInitiallyRef . current ;
30
38
31
39
const [ isOutAudioEnabled , setIsOutAudioEnabled ] = useState ( true ) ;
32
- const [ isOutVideoEnabled , setIsOutVideoEnabled ] =
40
+ const [ isOutVideoEnabled_ , setIsOutVideoEnabled ] =
33
41
useState ( enableVideoInitially ) ;
42
+ const isOutVideoEnabled = disableVideoCompletely ? false : isOutVideoEnabled_ ;
34
43
const isOutAudioEnabledRef = useRef ( isOutAudioEnabled ) ;
35
44
isOutAudioEnabledRef . current = isOutAudioEnabled ;
36
45
const isOutVideoEnabledRef = useRef ( isOutVideoEnabled ) ;
@@ -40,7 +49,7 @@ export default function App() {
40
49
let stream : MediaStream ;
41
50
try {
42
51
stream = await navigator . mediaDevices . getUserMedia ( {
43
- video : true ,
52
+ video : ! disableVideoCompletely ,
44
53
audio : true ,
45
54
} ) ;
46
55
} catch ( error ) {
@@ -61,7 +70,7 @@ export default function App() {
61
70
. forEach ( ( t ) => ( t . enabled = isOutVideoEnabledRef . current ) ) ;
62
71
63
72
return stream ;
64
- } , [ ] ) ;
73
+ } , [ disableVideoCompletely ] ) ;
65
74
const [ outStream , setOutStream ] = useState < MediaStream | null > ( null ) ;
66
75
useEffect ( ( ) => {
67
76
let outdated = false ;
@@ -84,10 +93,13 @@ export default function App() {
84
93
85
94
const manager = useMemo ( ( ) => {
86
95
const onIncStream = ( incStream : MediaStream ) => {
96
+ if ( disableVideoCompletely ) {
97
+ incStream . getVideoTracks ( ) . forEach ( ( t ) => incStream . removeTrack ( t ) ) ;
98
+ }
87
99
incVidRef . current ! . srcObject = incStream ;
88
100
} ;
89
101
return new CallsManager ( outStreamPromise , onIncStream , setState ) ;
90
- } , [ outStreamPromise ] ) ;
102
+ } , [ outStreamPromise , disableVideoCompletely ] ) ;
91
103
92
104
useEffect ( ( ) => {
93
105
if ( outStream == undefined ) {
@@ -113,7 +125,8 @@ export default function App() {
113
125
} , [ outStream , isOutAudioEnabled , isOutVideoEnabled ] ) ;
114
126
115
127
const outStreamHasVideoTrack =
116
- outStream == undefined || outStream . getVideoTracks ( ) . length >= 1 ;
128
+ ! disableVideoCompletely &&
129
+ ( outStream == undefined || outStream . getVideoTracks ( ) . length >= 1 ) ;
117
130
118
131
const endCall = useCallback ( ( ) => {
119
132
manager . endCall ( ) ;
0 commit comments