Skip to content

Commit 238f1ca

Browse files
committed
feat: option to disable video completely
Partially addresses #31. This is for Delta Touch (Ubuntu Touch), where incoming video seems to cause crashes. Note that if one party didn't `disableVideoCompletely`, they will still be able to send outgoing video, but the other party (who has `disableVideoCompletely`) will not see it.
1 parent deddbc7 commit 238f1ca

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

README.md

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

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

3034
### Installing Dependencies

src/App.tsx

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

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

3139
const [isOutAudioEnabled, setIsOutAudioEnabled] = useState(true);
32-
const [isOutVideoEnabled, setIsOutVideoEnabled] =
40+
const [isOutVideoEnabled_, setIsOutVideoEnabled] =
3341
useState(enableVideoInitially);
42+
const isOutVideoEnabled = disableVideoCompletely ? false : isOutVideoEnabled_;
3443
const isOutAudioEnabledRef = useRef(isOutAudioEnabled);
3544
isOutAudioEnabledRef.current = isOutAudioEnabled;
3645
const isOutVideoEnabledRef = useRef(isOutVideoEnabled);
@@ -40,7 +49,7 @@ export default function App() {
4049
let stream: MediaStream;
4150
try {
4251
stream = await navigator.mediaDevices.getUserMedia({
43-
video: true,
52+
video: !disableVideoCompletely,
4453
audio: true,
4554
});
4655
} catch (error) {
@@ -61,7 +70,7 @@ export default function App() {
6170
.forEach((t) => (t.enabled = isOutVideoEnabledRef.current));
6271

6372
return stream;
64-
}, []);
73+
}, [disableVideoCompletely]);
6574
const [outStream, setOutStream] = useState<MediaStream | null>(null);
6675
useEffect(() => {
6776
let outdated = false;
@@ -84,10 +93,13 @@ export default function App() {
8493

8594
const manager = useMemo(() => {
8695
const onIncStream = (incStream: MediaStream) => {
96+
if (disableVideoCompletely) {
97+
incStream.getVideoTracks().forEach((t) => incStream.removeTrack(t));
98+
}
8799
incVidRef.current!.srcObject = incStream;
88100
};
89101
return new CallsManager(outStreamPromise, onIncStream, setState);
90-
}, [outStreamPromise]);
102+
}, [outStreamPromise, disableVideoCompletely]);
91103

92104
useEffect(() => {
93105
if (outStream == undefined) {
@@ -113,7 +125,8 @@ export default function App() {
113125
}, [outStream, isOutAudioEnabled, isOutVideoEnabled]);
114126

115127
const outStreamHasVideoTrack =
116-
outStream == undefined || outStream.getVideoTracks().length >= 1;
128+
!disableVideoCompletely &&
129+
(outStream == undefined || outStream.getVideoTracks().length >= 1);
117130

118131
const endCall = useCallback(() => {
119132
manager.endCall();

0 commit comments

Comments
 (0)