@@ -21,6 +21,14 @@ export default function App() {
21
21
const outVidRef = useRef < HTMLVideoElement | null > ( null ) ;
22
22
const incVidRef = useRef < HTMLVideoElement | null > ( null ) ;
23
23
24
+ const disableVideoCompletelyRef = useRef < boolean | null > ( null ) ;
25
+ if ( disableVideoCompletelyRef . current == null ) {
26
+ disableVideoCompletelyRef . current = location . search . includes (
27
+ "disableVideoCompletely" ,
28
+ ) ;
29
+ }
30
+ const disableVideoCompletely = disableVideoCompletelyRef . current ;
31
+
24
32
const enableVideoInitiallyRef = useRef < boolean | null > ( null ) ;
25
33
if ( enableVideoInitiallyRef . current == null ) {
26
34
enableVideoInitiallyRef . current = ! location . search . includes (
@@ -30,8 +38,9 @@ export default function App() {
30
38
const enableVideoInitially = enableVideoInitiallyRef . current ;
31
39
32
40
const [ isOutAudioEnabled , setIsOutAudioEnabled ] = useState ( true ) ;
33
- const [ isOutVideoEnabled , setIsOutVideoEnabled ] =
41
+ const [ isOutVideoEnabled_ , setIsOutVideoEnabled ] =
34
42
useState ( enableVideoInitially ) ;
43
+ const isOutVideoEnabled = disableVideoCompletely ? false : isOutVideoEnabled_ ;
35
44
const isOutAudioEnabledRef = useRef ( isOutAudioEnabled ) ;
36
45
isOutAudioEnabledRef . current = isOutAudioEnabled ;
37
46
const isOutVideoEnabledRef = useRef ( isOutVideoEnabled ) ;
@@ -41,7 +50,7 @@ export default function App() {
41
50
let stream : MediaStream ;
42
51
try {
43
52
stream = await navigator . mediaDevices . getUserMedia ( {
44
- video : true ,
53
+ video : ! disableVideoCompletely ,
45
54
audio : true ,
46
55
} ) ;
47
56
} catch ( error ) {
@@ -62,7 +71,7 @@ export default function App() {
62
71
. forEach ( ( t ) => ( t . enabled = isOutVideoEnabledRef . current ) ) ;
63
72
64
73
return stream ;
65
- } , [ ] ) ;
74
+ } , [ disableVideoCompletely ] ) ;
66
75
const [ outStream , setOutStream ] = useState < MediaStream | null > ( null ) ;
67
76
useEffect ( ( ) => {
68
77
let outdated = false ;
@@ -89,6 +98,16 @@ export default function App() {
89
98
90
99
const manager = useMemo ( ( ) => {
91
100
const onIncStream = ( incStream : MediaStream ) => {
101
+ if ( disableVideoCompletely ) {
102
+ incStream . getVideoTracks ( ) . forEach ( ( t ) => incStream . removeTrack ( t ) ) ;
103
+ incStream . addEventListener ( "addtrack" , ( e ) => {
104
+ if ( e . track . kind !== "video" ) {
105
+ return ;
106
+ }
107
+ incStream . removeTrack ( e . track ) ;
108
+ } ) ;
109
+ }
110
+
92
111
const vid = incVidRef . current ! ;
93
112
vid . srcObject = incStream ;
94
113
@@ -108,7 +127,7 @@ export default function App() {
108
127
playIfPaused ( ) ;
109
128
} ;
110
129
return new CallsManager ( outStreamPromise , onIncStream , setState ) ;
111
- } , [ outStreamPromise ] ) ;
130
+ } , [ outStreamPromise , disableVideoCompletely ] ) ;
112
131
113
132
useEffect ( ( ) => {
114
133
if ( outStream == undefined ) {
@@ -134,7 +153,8 @@ export default function App() {
134
153
} , [ outStream , isOutAudioEnabled , isOutVideoEnabled ] ) ;
135
154
136
155
const outStreamHasVideoTrack =
137
- outStream == undefined || outStream . getVideoTracks ( ) . length >= 1 ;
156
+ ! disableVideoCompletely &&
157
+ ( outStream == undefined || outStream . getVideoTracks ( ) . length >= 1 ) ;
138
158
139
159
const acceptCall : null | ( ( ) => void ) =
140
160
state === "promptingUserToAcceptCall" ? ( ) => manager . acceptCall ( ) : null ;
0 commit comments