Skip to content

Commit 19b2b54

Browse files
authored
Merge pull request #35 from deltachat/wofwca/disable-video-completely-option
feat: option to disable video completely
2 parents e7f1a11 + a531ddf commit 19b2b54

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ In order to start the app in audio-only mode initially,
2626
provide `noOutgoingVideoInitially` in the query (search) string
2727
of the initial URL, e.g. `/index.html?noOutgoingVideoInitially#startCall`.
2828

29+
In order to completely disable incoming and outgoing video,
30+
provide `disableVideoCompletely` in the query string of the URL.
31+
See <https://github.com/deltachat/calls-webapp/issues/31>.
32+
2933
## Contributing
3034

3135
### Installing Dependencies

src/App.tsx

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ export default function App() {
2121
const outVidRef = useRef<HTMLVideoElement | null>(null);
2222
const incVidRef = useRef<HTMLVideoElement | null>(null);
2323

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+
2432
const enableVideoInitiallyRef = useRef<boolean | null>(null);
2533
if (enableVideoInitiallyRef.current == null) {
2634
enableVideoInitiallyRef.current = !location.search.includes(
@@ -30,8 +38,9 @@ export default function App() {
3038
const enableVideoInitially = enableVideoInitiallyRef.current;
3139

3240
const [isOutAudioEnabled, setIsOutAudioEnabled] = useState(true);
33-
const [isOutVideoEnabled, setIsOutVideoEnabled] =
41+
const [isOutVideoEnabled_, setIsOutVideoEnabled] =
3442
useState(enableVideoInitially);
43+
const isOutVideoEnabled = disableVideoCompletely ? false : isOutVideoEnabled_;
3544
const isOutAudioEnabledRef = useRef(isOutAudioEnabled);
3645
isOutAudioEnabledRef.current = isOutAudioEnabled;
3746
const isOutVideoEnabledRef = useRef(isOutVideoEnabled);
@@ -41,7 +50,7 @@ export default function App() {
4150
let stream: MediaStream;
4251
try {
4352
stream = await navigator.mediaDevices.getUserMedia({
44-
video: true,
53+
video: !disableVideoCompletely,
4554
audio: true,
4655
});
4756
} catch (error) {
@@ -62,7 +71,7 @@ export default function App() {
6271
.forEach((t) => (t.enabled = isOutVideoEnabledRef.current));
6372

6473
return stream;
65-
}, []);
74+
}, [disableVideoCompletely]);
6675
const [outStream, setOutStream] = useState<MediaStream | null>(null);
6776
useEffect(() => {
6877
let outdated = false;
@@ -89,6 +98,16 @@ export default function App() {
8998

9099
const manager = useMemo(() => {
91100
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+
92111
const vid = incVidRef.current!;
93112
vid.srcObject = incStream;
94113

@@ -108,7 +127,7 @@ export default function App() {
108127
playIfPaused();
109128
};
110129
return new CallsManager(outStreamPromise, onIncStream, setState);
111-
}, [outStreamPromise]);
130+
}, [outStreamPromise, disableVideoCompletely]);
112131

113132
useEffect(() => {
114133
if (outStream == undefined) {
@@ -134,7 +153,8 @@ export default function App() {
134153
}, [outStream, isOutAudioEnabled, isOutVideoEnabled]);
135154

136155
const outStreamHasVideoTrack =
137-
outStream == undefined || outStream.getVideoTracks().length >= 1;
156+
!disableVideoCompletely &&
157+
(outStream == undefined || outStream.getVideoTracks().length >= 1);
138158

139159
const acceptCall: null | (() => void) =
140160
state === "promptingUserToAcceptCall" ? () => manager.acceptCall() : null;

0 commit comments

Comments
 (0)