mirror of
https://github.com/vector-im/element-call.git
synced 2026-09-07 21:45:18 +00:00
Also add a check for controlled audio devices in useAudioContext
This commit is contained in:
@@ -17,6 +17,7 @@ import {
|
|||||||
useMediaDevices,
|
useMediaDevices,
|
||||||
} from "./livekit/MediaDevicesContext";
|
} from "./livekit/MediaDevicesContext";
|
||||||
import { type PrefetchedSounds } from "./soundUtils";
|
import { type PrefetchedSounds } from "./soundUtils";
|
||||||
|
import { useUrlParams } from "./UrlParams";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Play a sound though a given AudioContext. Will take
|
* Play a sound though a given AudioContext. Will take
|
||||||
@@ -71,7 +72,7 @@ export function useAudioContext<S extends string>(
|
|||||||
): UseAudioContext<S> | null {
|
): UseAudioContext<S> | null {
|
||||||
const [soundEffectVolume] = useSetting(soundEffectVolumeSetting);
|
const [soundEffectVolume] = useSetting(soundEffectVolumeSetting);
|
||||||
const { audioOutput } = useMediaDevices();
|
const { audioOutput } = useMediaDevices();
|
||||||
|
const { controlledAudioDevices } = useUrlParams();
|
||||||
const [audioContext, setAudioContext] = useState<AudioContext>();
|
const [audioContext, setAudioContext] = useState<AudioContext>();
|
||||||
const [audioBuffers, setAudioBuffers] = useState<Record<S, AudioBuffer>>();
|
const [audioBuffers, setAudioBuffers] = useState<Record<S, AudioBuffer>>();
|
||||||
|
|
||||||
@@ -110,14 +111,18 @@ export function useAudioContext<S extends string>(
|
|||||||
|
|
||||||
// Update the sink ID whenever we change devices.
|
// Update the sink ID whenever we change devices.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (audioContext && "setSinkId" in audioContext) {
|
if (
|
||||||
|
audioContext &&
|
||||||
|
"setSinkId" in audioContext &&
|
||||||
|
!controlledAudioDevices
|
||||||
|
) {
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/setSinkId
|
// https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/setSinkId
|
||||||
// @ts-expect-error - setSinkId doesn't exist yet in types, maybe because it's not supported everywhere.
|
// @ts-expect-error - setSinkId doesn't exist yet in types, maybe because it's not supported everywhere.
|
||||||
audioContext.setSinkId(audioOutput.selectedId).catch((ex) => {
|
audioContext.setSinkId(audioOutput.selectedId).catch((ex) => {
|
||||||
logger.warn("Unable to change sink for audio context", ex);
|
logger.warn("Unable to change sink for audio context", ex);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [audioContext, audioOutput.selectedId]);
|
}, [audioContext, audioOutput.selectedId, controlledAudioDevices]);
|
||||||
const { pan: earpiecePan, volume: earpieceVolume } = useEarpieceAudioConfig();
|
const { pan: earpiecePan, volume: earpieceVolume } = useEarpieceAudioConfig();
|
||||||
|
|
||||||
// Don't return a function until we're ready.
|
// Don't return a function until we're ready.
|
||||||
|
|||||||
Reference in New Issue
Block a user