Check for audio track count

Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
Šimon Brandner 2022-08-14 09:01:16 +02:00
parent fd8ade1bf1
commit 897f127fbd
No known key found for this signature in database
GPG key ID: D1D45825D60C24D2

View file

@ -18,6 +18,7 @@ import React, { useEffect, useRef } from "react";
import { Participant } from "../room/InCallView";
import { useCallFeed } from "./useCallFeed";
import { useMediaStreamTrackCount } from "./useMediaStream";
// XXX: These in fact do not render anything but to my knowledge this is the
// only way to a hook on an array
@ -34,12 +35,13 @@ export function AudioForParticipant({
audioDestination,
}: AudioForParticipantProps): JSX.Element {
const { stream, localVolume, audioMuted } = useCallFeed(item.callFeed);
const [audioTrackCount] = useMediaStreamTrackCount(stream);
const gainNodeRef = useRef<GainNode>();
const sourceRef = useRef<MediaStreamAudioSourceNode>();
useEffect(() => {
if (!item.isLocal && audioContext && !audioMuted) {
if (!item.isLocal && audioContext && !audioMuted && audioTrackCount > 0) {
if (!gainNodeRef.current) {
gainNodeRef.current = new GainNode(audioContext, {
gain: localVolume,