Add useAudioOutputDevice()
Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
parent
c09380644b
commit
0e34f9a464
3 changed files with 48 additions and 20 deletions
|
|
@ -22,6 +22,7 @@ import {
|
|||
} from "matrix-js-sdk/src/webrtc/audioContext";
|
||||
|
||||
import { useSpatialAudio } from "../settings/useSetting";
|
||||
import { useAudioOutputDevice } from "./useAudioOutputDevice";
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
|
|
@ -38,6 +39,8 @@ export const useMediaStream = (
|
|||
): RefObject<MediaElement> => {
|
||||
const mediaRef = useRef<MediaElement>();
|
||||
|
||||
useAudioOutputDevice(mediaRef, audioOutputDevice);
|
||||
|
||||
useEffect(() => {
|
||||
console.log(
|
||||
`useMediaStream update stream mediaRef.current ${!!mediaRef.current} stream ${
|
||||
|
|
@ -67,24 +70,6 @@ export const useMediaStream = (
|
|||
}
|
||||
}, [stream, mute]);
|
||||
|
||||
useEffect(() => {
|
||||
if (
|
||||
mediaRef.current &&
|
||||
audioOutputDevice &&
|
||||
mediaRef.current !== undefined
|
||||
) {
|
||||
if (mediaRef.current.setSinkId) {
|
||||
console.log(
|
||||
`useMediaStream setting output setSinkId ${audioOutputDevice}`
|
||||
);
|
||||
// Chrome for Android doesn't support this
|
||||
mediaRef.current.setSinkId(audioOutputDevice);
|
||||
} else {
|
||||
console.log("Can't set output - no setsinkid");
|
||||
}
|
||||
}
|
||||
}, [audioOutputDevice]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!mediaRef.current) return;
|
||||
if (localVolume === null || localVolume === undefined) return;
|
||||
|
|
@ -156,11 +141,11 @@ const createLoopback = async (stream: MediaStream): Promise<MediaStream> => {
|
|||
export const useAudioContext = (): [
|
||||
AudioContext,
|
||||
AudioNode,
|
||||
RefObject<HTMLAudioElement>
|
||||
RefObject<MediaElement>
|
||||
] => {
|
||||
const context = useRef<AudioContext>();
|
||||
const destination = useRef<AudioNode>();
|
||||
const audioRef = useRef<HTMLAudioElement>();
|
||||
const audioRef = useRef<MediaElement>();
|
||||
|
||||
useEffect(() => {
|
||||
if (audioRef.current && !context.current) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue