bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/audio/local-echo/service.js
prlanzarin bae731e59e fix(audio): PC loopback workaround for local echo in Chrome
Works around the fact that Chrome doesnt have AEC on streams that dont go through PCs
2022-04-13 14:37:39 +00:00

42 lines
1.2 KiB
JavaScript

import LocalPCLoopback from '/imports/ui/services/webrtc-base/local-pc-loopback';
import browserInfo from '/imports/utils/browserInfo';
const MEDIA_TAG = Meteor.settings.public.media.mediaTag;
const USE_RTC_LOOPBACK_CHR = Meteor.settings.public.media.localEchoTest.useRtcLoopbackInChromium;
const useRTCLoopback = () => (browserInfo.isChrome || browserInfo.isEdge) && USE_RTC_LOOPBACK_CHR;
const createAudioRTCLoopback = () => new LocalPCLoopback({ audio: true });
const deattachEchoStream = () => {
const audioElement = document.querySelector(MEDIA_TAG);
audioElement.pause();
audioElement.srcObject = null;
};
const playEchoStream = async (stream, loopbackAgent = null) => {
if (stream) {
const audioElement = document.querySelector(MEDIA_TAG);
deattachEchoStream();
let streamToPlay = stream;
if (loopbackAgent) {
try {
await loopbackAgent.start(stream);
streamToPlay = loopbackAgent.loopbackStream;
} catch (error) {
loopbackAgent.stop();
}
}
audioElement.srcObject = streamToPlay;
audioElement.play();
}
};
export default {
useRTCLoopback,
createAudioRTCLoopback,
deattachEchoStream,
playEchoStream,
};