bae731e59e
Works around the fact that Chrome doesnt have AEC on streams that dont go through PCs
42 lines
1.2 KiB
JavaScript
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,
|
|
};
|